File: triggers.eye

package info (click to toggle)
ruby-eye 0.7-5.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 672 kB
  • sloc: ruby: 5,003; makefile: 3
file content (64 lines) | stat: -rw-r--r-- 1,629 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# Triggers example:
#
# to execute commands inside trigger need to use 2 methods:
# process.execute_async(cmd, opts), and
# process.execute_sync(cmd, opts)

Eye.config do
  logger "/tmp/eye.log"
end

Eye.app :triggers do

  # Execute shell command before process start
  process :a do
    pid_file "/tmp/a.pid"
    start_command "sleep 100"
    daemonize true

    # send message async which sendxmpp, before process start
    trigger :transition, to: :starting, do: -> {
      process.execute_async "sendxmpp -s 'hhahahaa' someone@jabber.org"
    }
  end

  # Touch some file before process start, remove file after process die
  process :b do
    pid_file "/tmp/b.pid"
    start_command "sleep 100"
    daemonize true

    # before process starting, touch some file
    trigger :transition1, to: :starting, do: -> {
      process.execute_sync "touch /tmp/bla.file"
    }

    # after process, crashed, or stopped, remove that file
    trigger :transition2, to: :down, do: -> {
      process.execute_sync "rm /tmp/bla.file"
    }
  end

  # With restart :c process, send restart to process :a
  process :c do
    pid_file "/tmp/c.pid"
    start_command "sleep 100"
    daemonize true

    app_name = app.name
    trigger :transition, :event => :restarting, :do => ->{
      info "send restarting to :a"
      Eye::Control.command('restart', "#{app_name}:a")
    }
  end

  # process d cant start, until file /tmp/bla contains string 'bla'
  process :d do
    pid_file "/tmp/d.pid"
    start_command "sleep 100"
    daemonize true

    trigger :starting_guard, every: 5.seconds, should: -> { `cat /tmp/bla` =~ /bla/ }
  end

end