resurrected_god 0.14.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (138) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +559 -0
  3. data/README.md +9 -4
  4. data/bin/god +26 -28
  5. data/ext/god/extconf.rb +9 -9
  6. data/lib/god/behavior.rb +3 -5
  7. data/lib/god/behaviors/clean_pid_file.rb +4 -6
  8. data/lib/god/behaviors/clean_unix_socket.rb +4 -6
  9. data/lib/god/behaviors/notify_when_flapping.rb +13 -15
  10. data/lib/god/cli/command.rb +109 -89
  11. data/lib/god/cli/run.rb +51 -75
  12. data/lib/god/cli/version.rb +2 -4
  13. data/lib/god/condition.rb +12 -14
  14. data/lib/god/conditions/always.rb +3 -2
  15. data/lib/god/conditions/complex.rb +23 -24
  16. data/lib/god/conditions/cpu_usage.rb +12 -16
  17. data/lib/god/conditions/degrading_lambda.rb +15 -19
  18. data/lib/god/conditions/disk_usage.rb +7 -8
  19. data/lib/god/conditions/file_mtime.rb +3 -7
  20. data/lib/god/conditions/file_touched.rb +4 -5
  21. data/lib/god/conditions/flapping.rb +57 -62
  22. data/lib/god/conditions/http_response_code.rb +27 -32
  23. data/lib/god/conditions/lambda.rb +3 -5
  24. data/lib/god/conditions/memory_usage.rb +12 -16
  25. data/lib/god/conditions/process_exits.rb +12 -12
  26. data/lib/god/conditions/process_running.rb +8 -10
  27. data/lib/god/conditions/socket_responding.rb +23 -28
  28. data/lib/god/conditions/tries.rb +12 -14
  29. data/lib/god/configurable.rb +7 -10
  30. data/lib/god/contact.rb +41 -52
  31. data/lib/god/contacts/airbrake.rb +10 -12
  32. data/lib/god/contacts/campfire.rb +18 -20
  33. data/lib/god/contacts/email.rb +27 -28
  34. data/lib/god/contacts/prowl.rb +16 -17
  35. data/lib/god/contacts/scout.rb +2 -5
  36. data/lib/god/contacts/sensu.rb +15 -11
  37. data/lib/god/contacts/slack.rb +23 -33
  38. data/lib/god/contacts/statsd.rb +8 -8
  39. data/lib/god/contacts/twitter.rb +2 -2
  40. data/lib/god/contacts/webhook.rb +21 -24
  41. data/lib/god/driver.rb +12 -18
  42. data/lib/god/errors.rb +0 -2
  43. data/lib/god/event_handler.rb +40 -49
  44. data/lib/god/event_handlers/dummy_handler.rb +1 -1
  45. data/lib/god/event_handlers/kqueue_handler.rb +2 -2
  46. data/lib/god/event_handlers/netlink_handler.rb +1 -1
  47. data/lib/god/logger.rb +5 -13
  48. data/lib/god/metric.rb +13 -15
  49. data/lib/god/process.rb +93 -98
  50. data/lib/god/simple_logger.rb +13 -15
  51. data/lib/god/socket.rb +21 -23
  52. data/lib/god/sugar.rb +8 -8
  53. data/lib/god/sys_logger.rb +6 -8
  54. data/lib/god/system/portable_poller.rb +1 -9
  55. data/lib/god/system/process.rb +4 -6
  56. data/lib/god/system/slash_proc_poller.rb +17 -19
  57. data/lib/god/task.rb +110 -136
  58. data/lib/god/timeline.rb +2 -4
  59. data/lib/god/trigger.rb +7 -11
  60. data/lib/god/version.rb +1 -1
  61. data/lib/god/watch.rb +51 -57
  62. data/lib/god.rb +122 -148
  63. metadata +17 -370
  64. data/Announce.txt +0 -135
  65. data/Gemfile +0 -5
  66. data/Rakefile +0 -129
  67. data/doc/god.asciidoc +0 -1592
  68. data/doc/intro.asciidoc +0 -20
  69. data/ext/god/.gitignore +0 -5
  70. data/lib/god/compat19.rb +0 -33
  71. data/lib/god/contacts/hipchat.rb +0 -117
  72. data/lib/god/contacts/jabber.rb +0 -75
  73. data/test/configs/child_events/child_events.god +0 -44
  74. data/test/configs/child_events/simple_server.rb +0 -3
  75. data/test/configs/child_polls/child_polls.god +0 -37
  76. data/test/configs/child_polls/simple_server.rb +0 -12
  77. data/test/configs/complex/complex.god +0 -59
  78. data/test/configs/complex/simple_server.rb +0 -3
  79. data/test/configs/contact/contact.god +0 -118
  80. data/test/configs/contact/simple_server.rb +0 -3
  81. data/test/configs/daemon_events/daemon_events.god +0 -37
  82. data/test/configs/daemon_events/simple_server.rb +0 -8
  83. data/test/configs/daemon_events/simple_server_stop.rb +0 -11
  84. data/test/configs/daemon_polls/daemon_polls.god +0 -17
  85. data/test/configs/daemon_polls/simple_server.rb +0 -6
  86. data/test/configs/degrading_lambda/degrading_lambda.god +0 -31
  87. data/test/configs/degrading_lambda/tcp_server.rb +0 -15
  88. data/test/configs/keepalive/keepalive.god +0 -9
  89. data/test/configs/keepalive/keepalive.rb +0 -12
  90. data/test/configs/lifecycle/lifecycle.god +0 -25
  91. data/test/configs/matias/matias.god +0 -50
  92. data/test/configs/real.rb +0 -59
  93. data/test/configs/running_load/running_load.god +0 -16
  94. data/test/configs/stop_options/simple_server.rb +0 -12
  95. data/test/configs/stop_options/stop_options.god +0 -39
  96. data/test/configs/stress/simple_server.rb +0 -3
  97. data/test/configs/stress/stress.god +0 -15
  98. data/test/configs/task/logs/.placeholder +0 -0
  99. data/test/configs/task/task.god +0 -26
  100. data/test/configs/test.rb +0 -61
  101. data/test/configs/usr1_trapper.rb +0 -10
  102. data/test/helper.rb +0 -172
  103. data/test/suite.rb +0 -6
  104. data/test/test_airbrake.rb +0 -14
  105. data/test/test_behavior.rb +0 -18
  106. data/test/test_campfire.rb +0 -22
  107. data/test/test_condition.rb +0 -52
  108. data/test/test_conditions_disk_usage.rb +0 -50
  109. data/test/test_conditions_http_response_code.rb +0 -109
  110. data/test/test_conditions_process_running.rb +0 -40
  111. data/test/test_conditions_socket_responding.rb +0 -176
  112. data/test/test_conditions_tries.rb +0 -67
  113. data/test/test_contact.rb +0 -109
  114. data/test/test_driver.rb +0 -26
  115. data/test/test_email.rb +0 -34
  116. data/test/test_event_handler.rb +0 -82
  117. data/test/test_god.rb +0 -710
  118. data/test/test_god_system.rb +0 -201
  119. data/test/test_handlers_kqueue_handler.rb +0 -16
  120. data/test/test_hipchat.rb +0 -23
  121. data/test/test_jabber.rb +0 -29
  122. data/test/test_logger.rb +0 -55
  123. data/test/test_metric.rb +0 -74
  124. data/test/test_process.rb +0 -263
  125. data/test/test_prowl.rb +0 -15
  126. data/test/test_registry.rb +0 -15
  127. data/test/test_sensu.rb +0 -11
  128. data/test/test_slack.rb +0 -57
  129. data/test/test_socket.rb +0 -34
  130. data/test/test_statsd.rb +0 -22
  131. data/test/test_sugar.rb +0 -42
  132. data/test/test_system_portable_poller.rb +0 -17
  133. data/test/test_system_process.rb +0 -30
  134. data/test/test_task.rb +0 -246
  135. data/test/test_timeline.rb +0 -37
  136. data/test/test_trigger.rb +0 -63
  137. data/test/test_watch.rb +0 -286
  138. data/test/test_webhook.rb +0 -22
data/doc/intro.asciidoc DELETED
@@ -1,20 +0,0 @@
1
- God: The Ruby Framework for Process Management
2
- ==============================================
3
- Tom Preston-Werner <tom@mojombo.com>
4
-
5
- God is an easy to configure, easy to extend monitoring framework written in
6
- Ruby.
7
-
8
- Keeping your server processes and tasks running should be a simple part of
9
- your deployment process. God aims to be the simplest, most powerful monitoring
10
- application available.
11
-
12
- Features
13
- --------
14
-
15
- * Config file is written in Ruby
16
- * Easily write your own custom conditions in Ruby
17
- * Supports both poll and event based conditions
18
- * Different poll conditions can have different intervals
19
- * Integrated notification system (write your own too!)
20
- * Easily control non-daemonizing scripts
data/ext/god/.gitignore DELETED
@@ -1,5 +0,0 @@
1
- Makefile
2
- kqueue_handler_ext.bundle
3
- kqueue_handler.o
4
- netlink_handler_ext.bundle
5
- netlink_handler.o
data/lib/god/compat19.rb DELETED
@@ -1,33 +0,0 @@
1
- require 'monitor'
2
-
3
- # Taken from http://redmine.ruby-lang.org/repositories/entry/ruby-19/lib/monitor.rb
4
-
5
- module MonitorMixin
6
- class ConditionVariable
7
- def wait(timeout = nil)
8
- @monitor.__send__(:mon_check_owner)
9
- count = @monitor.__send__(:mon_exit_for_cond)
10
- begin
11
- @cond.wait(@monitor.instance_variable_get("@mon_mutex"), timeout)
12
- return true
13
- ensure
14
- @monitor.__send__(:mon_enter_for_cond, count)
15
- end
16
- end
17
- end
18
- end
19
-
20
- # Taken from http://redmine.ruby-lang.org/repositories/entry/ruby-19/lib/thread.rb
21
-
22
- class ConditionVariable
23
- def wait(mutex, timeout=nil)
24
- begin
25
- # TODO: mutex should not be used
26
- @waiters_mutex.synchronize do
27
- @waiters.push(Thread.current)
28
- end
29
- mutex.sleep timeout
30
- end
31
- self
32
- end
33
- end
@@ -1,117 +0,0 @@
1
- # Send a notice to a Hipchat room (http://hipchat.com).
2
- #
3
- # token - The String token used for authentication.
4
- # room - The String room name to which the message should be sent.
5
- # ssl - A Boolean determining whether or not to use SSL
6
- # (default: false).
7
- # from - The String representing who the message should be sent as.
8
-
9
- require 'net/http'
10
- require 'net/https'
11
-
12
- CONTACT_DEPS[:hipchat] = ['json']
13
- CONTACT_DEPS[:hipchat].each do |d|
14
- require d
15
- end
16
-
17
- module Marshmallow
18
- class Connection
19
- def initialize(options)
20
- raise "Required option :token not set." unless options[:token]
21
- @options = options
22
- end
23
-
24
- def base_url
25
- scheme = @options[:ssl] ? 'https' : 'http'
26
- "#{scheme}://api.hipchat.com/v1/rooms"
27
- end
28
-
29
- def find_room_id_by_name(room_name)
30
- url = URI.parse("#{base_url}/list?format=json&auth_token=#{@options[:token]}")
31
- http = Net::HTTP.new(url.host, url.port)
32
- http.use_ssl = true if @options[:ssl]
33
-
34
- req = Net::HTTP::Get.new(url.request_uri)
35
- req.set_content_type('application/json')
36
-
37
- res = http.request(req)
38
- case res
39
- when Net::HTTPSuccess
40
- rooms = JSON.parse(res.body)
41
- room = rooms['rooms'].select { |x| x['name'] == room_name }
42
- rooms.empty? ? nil : room.first['room_id'].to_i
43
- else
44
- raise res.error!
45
- end
46
- end
47
-
48
- def speak(room, message)
49
- room_id = find_room_id_by_name(room)
50
- puts "in spark: room_id = #{room_id}"
51
- raise "No such room: #{room}." unless room_id
52
-
53
- escaped_message = URI.escape(message)
54
-
55
- url = URI.parse("#{base_url}/message?message_format=text&format=json&auth_token=#{@options[:token]}&from=#{@options[:from]}&room_id=#{room}&message=#{escaped_message}")
56
-
57
- http = Net::HTTP.new(url.host, url.port)
58
- http.use_ssl = true if @options[:ssl]
59
-
60
- req = Net::HTTP::Post.new(url.request_uri)
61
- req.set_content_type('application/json')
62
- res = http.request(req)
63
- case res
64
- when Net::HTTPSuccess
65
- true
66
- else
67
- raise res.error!
68
- end
69
- end
70
- end
71
- end
72
-
73
- module God
74
- module Contacts
75
-
76
- class Hipchat < Contact
77
- class << self
78
- attr_accessor :token, :room, :ssl, :from
79
- attr_accessor :format
80
- end
81
-
82
- self.ssl = false
83
-
84
- self.format = lambda do |message, time, priority, category, host|
85
- "[#{time.strftime('%H:%M:%S')}] #{host} - #{message}"
86
- end
87
-
88
- attr_accessor :token, :room, :ssl, :from
89
-
90
- def valid?
91
- valid = true
92
- valid &= complain("Attribute 'token' must be specified", self) unless arg(:token)
93
- valid &= complain("Attribute 'room' must be specified", self) unless arg(:room)
94
- valid &= complain("Attribute 'from' must be specified", self) unless arg(:from)
95
- valid
96
- end
97
-
98
- def notify(message, time, priority, category, host)
99
- body = Hipchat.format.call(message, time, priority, category, host)
100
-
101
- conn = Marshmallow::Connection.new(
102
- :token => arg(:token),
103
- :ssl => arg(:ssl),
104
- :from => arg(:from)
105
- )
106
-
107
- conn.speak(arg(:room), body)
108
-
109
- self.info = "notified hipchat: #{arg(:room)}"
110
- rescue Object => e
111
- applog(nil, :info, "failed to notify hipchat: #{e.message}")
112
- applog(nil, :debug, e.backtrace.join("\n"))
113
- end
114
- end
115
-
116
- end
117
- end
@@ -1,75 +0,0 @@
1
- # Send a notice to a Jabber address.
2
- #
3
- # host - The String hostname of the Jabber server.
4
- # port - The Integer port of the Jabber server (default: 5222).
5
- # from_jid - The String Jabber ID of the sender.
6
- # password - The String password of the sender.
7
- # to_jid - The String Jabber ID of the recipient.
8
- # subject - The String subject of the message (default: "God Notification").
9
-
10
- CONTACT_DEPS[:jabber] = ['xmpp4r']
11
- CONTACT_DEPS[:jabber].each do |d|
12
- require d
13
- end
14
-
15
- module God
16
- module Contacts
17
-
18
- class Jabber < Contact
19
- class << self
20
- attr_accessor :host, :port, :from_jid, :password, :to_jid, :subject
21
- attr_accessor :format
22
- end
23
-
24
- self.port = 5222
25
- self.subject = 'God Notification'
26
-
27
- self.format = lambda do |message, time, priority, category, host|
28
- text = "Message: #{message}\n"
29
- text += "Host: #{host}\n" if host
30
- text += "Priority: #{priority}\n" if priority
31
- text += "Category: #{category}\n" if category
32
- text
33
- end
34
-
35
- attr_accessor :host, :port, :from_jid, :password, :to_jid, :subject
36
-
37
- def valid?
38
- valid = true
39
- valid &= complain("Attribute 'host' must be specified", self) unless arg(:host)
40
- valid &= complain("Attribute 'port' must be specified", self) unless arg(:port)
41
- valid &= complain("Attribute 'from_jid' must be specified", self) unless arg(:from_jid)
42
- valid &= complain("Attribute 'to_jid' must be specified", self) unless arg(:to_jid)
43
- valid &= complain("Attribute 'password' must be specified", self) unless arg(:password)
44
- valid
45
- end
46
-
47
- def notify(message, time, priority, category, host)
48
- body = Jabber.format.call(message, time, priority, category, host)
49
-
50
- message = ::Jabber::Message.new(arg(:to_jid), body)
51
- message.set_type(:normal)
52
- message.set_id('1')
53
- message.set_subject(arg(:subject))
54
-
55
- jabber_id = ::Jabber::JID.new("#{arg(:from_jid)}/God")
56
-
57
- client = ::Jabber::Client.new(jabber_id)
58
- client.connect(arg(:host), arg(:port))
59
- client.auth(arg(:password))
60
- client.send(message)
61
- client.close
62
-
63
- self.info = "sent jabber message to #{self.to_jid}"
64
- rescue Object => e
65
- if e.respond_to?(:message)
66
- applog(nil, :info, "failed to send jabber message to #{arg(:to_jid)}: #{e.message}")
67
- else
68
- applog(nil, :info, "failed to send jabber message to #{arg(:to_jid)}: #{e.class}")
69
- end
70
- applog(nil, :debug, e.backtrace.join("\n"))
71
- end
72
-
73
- end
74
- end
75
- end
@@ -1,44 +0,0 @@
1
- God.watch do |w|
2
- w.name = "child-events"
3
- w.interval = 5.seconds
4
- w.start = File.join(GOD_ROOT, *%w[test configs child_events simple_server.rb])
5
- # w.log = File.join(GOD_ROOT, *%w[test configs child_events god.log])
6
-
7
- # determine the state on startup
8
- w.transition(:init, { true => :up, false => :start }) do |on|
9
- on.condition(:process_running) do |c|
10
- c.running = true
11
- end
12
- end
13
-
14
- # determine when process has finished starting
15
- w.transition([:start, :restart], :up) do |on|
16
- on.condition(:process_running) do |c|
17
- c.running = true
18
- end
19
-
20
- # failsafe
21
- on.condition(:tries) do |c|
22
- c.times = 2
23
- c.transition = :start
24
- end
25
- end
26
-
27
- # start if process is not running
28
- w.transition(:up, :start) do |on|
29
- on.condition(:process_exits)
30
- end
31
-
32
- # lifecycle
33
- w.lifecycle do |on|
34
- on.condition(:flapping) do |c|
35
- c.to_state = [:start, :restart]
36
- c.times = 5
37
- c.within = 20.seconds
38
- c.transition = :unmonitored
39
- c.retry_in = 10.seconds
40
- c.retry_times = 2
41
- c.retry_within = 5.minutes
42
- end
43
- end
44
- end
@@ -1,3 +0,0 @@
1
- #! /usr/bin/env ruby
2
-
3
- loop { puts 'server'; sleep 1 }
@@ -1,37 +0,0 @@
1
- God.watch do |w|
2
- w.name = 'child-polls'
3
- w.start = File.join(GOD_ROOT, *%w[test configs child_polls simple_server.rb])
4
- w.interval = 5
5
- w.grace = 2
6
-
7
- w.start_if do |start|
8
- start.condition(:process_running) do |c|
9
- c.running = false
10
- end
11
- end
12
-
13
- w.restart_if do |restart|
14
- restart.condition(:cpu_usage) do |c|
15
- c.above = 30.percent
16
- c.times = [3, 5]
17
- end
18
-
19
- restart.condition(:memory_usage) do |c|
20
- c.above = 10.megabytes
21
- c.times = [3, 5]
22
- end
23
- end
24
-
25
- # lifecycle
26
- w.lifecycle do |on|
27
- on.condition(:flapping) do |c|
28
- c.to_state = [:start, :restart]
29
- c.times = 3
30
- c.within = 60.seconds
31
- c.transition = :unmonitored
32
- c.retry_in = 10.seconds
33
- c.retry_times = 2
34
- c.retry_within = 5.minutes
35
- end
36
- end
37
- end
@@ -1,12 +0,0 @@
1
- #! /usr/bin/env ruby
2
-
3
- data = ''
4
-
5
- loop do
6
- STDOUT.puts('server');
7
- STDOUT.flush;
8
-
9
- 100000.times { data << 'x' }
10
-
11
- sleep 10
12
- end
@@ -1,59 +0,0 @@
1
- God.watch do |w|
2
- w.name = "complex"
3
- w.interval = 5.seconds
4
- w.start = File.join(GOD_ROOT, *%w[test configs complex simple_server.rb])
5
- # w.log = File.join(GOD_ROOT, *%w[test configs child_events god.log])
6
-
7
- # determine the state on startup
8
- w.transition(:init, { true => :up, false => :start }) do |on|
9
- on.condition(:process_running) do |c|
10
- c.running = true
11
- end
12
- end
13
-
14
- # determine when process has finished starting
15
- w.transition([:start, :restart], :up) do |on|
16
- on.condition(:process_running) do |c|
17
- c.running = true
18
- end
19
-
20
- # failsafe
21
- on.condition(:tries) do |c|
22
- c.times = 2
23
- c.transition = :start
24
- end
25
- end
26
-
27
- # start if process is not running
28
- w.transition(:up, :start) do |on|
29
- on.condition(:process_exits)
30
- end
31
-
32
- # restart if process is misbehaving
33
- w.transition(:up, :restart) do |on|
34
- on.condition(:complex) do |cc|
35
- cc.and(:cpu_usage) do |c|
36
- c.above = 0.percent
37
- c.times = 1
38
- end
39
-
40
- cc.and(:memory_usage) do |c|
41
- c.above = 0.megabytes
42
- c.times = 3
43
- end
44
- end
45
- end
46
-
47
- # lifecycle
48
- w.lifecycle do |on|
49
- on.condition(:flapping) do |c|
50
- c.to_state = [:start, :restart]
51
- c.times = 5
52
- c.within = 20.seconds
53
- c.transition = :unmonitored
54
- c.retry_in = 10.seconds
55
- c.retry_times = 2
56
- c.retry_within = 5.minutes
57
- end
58
- end
59
- end
@@ -1,3 +0,0 @@
1
- #! /usr/bin/env ruby
2
-
3
- loop { puts 'server'; sleep 1 }
@@ -1,118 +0,0 @@
1
- # God::Contacts::Campfire.defaults do |d|
2
- # d.subdomain = 'github'
3
- # d.token = '9fb768e421975cc1c6ff3f4f8306f890cb46e24f'
4
- # d.room = 'Notices'
5
- # d.ssl = true
6
- # end
7
- #
8
- # God.contact(:campfire) do |c|
9
- # c.name = 'tom4'
10
- # end
11
-
12
- # God::Contacts::Hipchat.defaults do |d|
13
- # d.token = '9fb768e421975cc1c6ff3f4f8306f890cb46e24f'
14
- # d.room = 'Notices'
15
- # d.ssl = true
16
- # end
17
- #
18
- # God.contact(:hipchat) do |c|
19
- # c.name = 'hip1'
20
- # end
21
-
22
- # God.contact(:email) do |c|
23
- # c.name = 'tom'
24
- # c.group = 'developers'
25
- # c.to_email = 'tom@lepton.local'
26
- # c.from_email = 'god@github.com'
27
- # c.from_name = 'God'
28
- # c.delivery_method = :sendmail
29
- # end
30
-
31
- # God.contact(:email) do |c|
32
- # c.name = 'tom'
33
- # c.group = 'developers'
34
- # c.to_email = 'tom@mojombo.com'
35
- # c.from_email = 'god@github.com'
36
- # c.from_name = 'God'
37
- # c.server_host = 'smtp.rs.github.com'
38
- # end
39
-
40
- # God.contact(:prowl) do |c|
41
- # c.name = 'tom3'
42
- # c.apikey = 'f0fc8e1f3121672686337a631527eac2f1b6031c'
43
- # c.group = 'developers'
44
- # end
45
-
46
- # God.contact(:twitter) do |c|
47
- # c.name = 'tom6'
48
- # c.consumer_token = 'gOhjax6s0L3mLeaTtBWPw'
49
- # c.consumer_secret = 'yz4gpAVXJHKxvsGK85tEyzQJ7o2FEy27H1KEWL75jfA'
50
- # c.access_token = '17376380-qS391nCrgaP4HKXAmZtM38gB56xUXMhx1NYbjT6mQ'
51
- # c.access_secret = 'uMwCDeU4OXlEBWFQBc3KwGyY8OdWCtAV0Jg5KVB0'
52
- # end
53
-
54
- # God.contact(:scout) do |c|
55
- # c.name = 'tom5'
56
- # c.client_key = '583a51b5-acbc-2421-a830-b6f3f8e4b04e'
57
- # c.plugin_id = '230641'
58
- # end
59
-
60
- # God.contact(:webhook) do |c|
61
- # c.name = 'tom'
62
- # c.url = "http://www.postbin.org/wk7guh"
63
- # end
64
-
65
- # God.contact(:jabber) do |c|
66
- # c.name = 'tom'
67
- # c.host = 'talk.google.com'
68
- # c.to_jid = 'mojombo@jabber.org'
69
- # c.from_jid = 'mojombo@gmail.com'
70
- # c.password = 'secret'
71
- # end
72
-
73
- God.watch do |w|
74
- w.name = "contact"
75
- w.interval = 5.seconds
76
- w.start = "ruby " + File.join(File.dirname(__FILE__), *%w[simple_server.rb])
77
- w.log = "/Users/tom/contact.log"
78
-
79
- # determine the state on startup
80
- w.transition(:init, { true => :up, false => :start }) do |on|
81
- on.condition(:process_running) do |c|
82
- c.running = true
83
- end
84
- end
85
-
86
- # determine when process has finished starting
87
- w.transition([:start, :restart], :up) do |on|
88
- on.condition(:process_running) do |c|
89
- c.running = true
90
- end
91
-
92
- # failsafe
93
- on.condition(:tries) do |c|
94
- c.times = 2
95
- c.transition = :start
96
- end
97
- end
98
-
99
- # start if process is not running
100
- w.transition(:up, :start) do |on|
101
- on.condition(:process_exits) do |c|
102
- c.notify = {:contacts => ['tom'], :priority => 1, :category => 'product'}
103
- end
104
- end
105
-
106
- # lifecycle
107
- w.lifecycle do |on|
108
- on.condition(:flapping) do |c|
109
- c.to_state = [:start, :restart]
110
- c.times = 5
111
- c.within = 20.seconds
112
- c.transition = :unmonitored
113
- c.retry_in = 10.seconds
114
- c.retry_times = 2
115
- c.retry_within = 5.minutes
116
- end
117
- end
118
- end
@@ -1,3 +0,0 @@
1
- #! /usr/bin/env ruby
2
-
3
- loop { puts 'server'; sleep 1 }
@@ -1,37 +0,0 @@
1
- God.watch do |w|
2
- w.name = "daemon-events"
3
- w.interval = 5.seconds
4
- w.start = 'ruby ' + File.join(File.dirname(__FILE__), *%w[simple_server.rb]) + ' start'
5
- w.stop = 'ruby ' + File.join(File.dirname(__FILE__), *%w[simple_server_stop.rb])
6
- w.pid_file = '/var/run/daemon-events.pid'
7
- w.log = File.join(File.dirname(__FILE__), 'daemon_events.log')
8
- w.uid = 'tom'
9
- w.gid = 'tom'
10
-
11
- w.behavior(:clean_pid_file)
12
-
13
- # determine the state on startup
14
- w.transition(:init, { true => :up, false => :start }) do |on|
15
- on.condition(:process_running) do |c|
16
- c.running = true
17
- end
18
- end
19
-
20
- # determine when process has finished starting
21
- w.transition([:start, :restart], :up) do |on|
22
- on.condition(:process_running) do |c|
23
- c.running = true
24
- end
25
-
26
- # failsafe
27
- on.condition(:tries) do |c|
28
- c.times = 2
29
- c.transition = :start
30
- end
31
- end
32
-
33
- # start if process is not running
34
- w.transition(:up, :start) do |on|
35
- on.condition(:process_exits)
36
- end
37
- end
@@ -1,8 +0,0 @@
1
- require 'rubygems'
2
- require 'daemons'
3
-
4
- puts 'simple server ahoy!'
5
-
6
- Daemons.run_proc('daemon-events', {:dir_mode => :system}) do
7
- loop { puts 'server'; sleep 1 }
8
- end
@@ -1,11 +0,0 @@
1
- # exit!(2)
2
-
3
- 3.times do
4
- puts 'waiting'
5
- sleep 1
6
- end
7
-
8
- p ENV
9
-
10
- command = '/usr/local/bin/ruby ' + File.join(File.dirname(__FILE__), *%w[simple_server.rb]) + ' stop'
11
- system(command)
@@ -1,17 +0,0 @@
1
- God.watch do |w|
2
- w.name = "daemon-polls"
3
- w.interval = 5.seconds
4
- w.start = 'ruby ' + File.join(File.dirname(__FILE__), *%w[simple_server.rb]) + ' start'
5
- w.stop = 'ruby ' + File.join(File.dirname(__FILE__), *%w[simple_server.rb]) + ' stop'
6
- w.pid_file = '/var/run/daemon-polls.pid'
7
- w.start_grace = 2.seconds
8
- w.log = File.join(File.dirname(__FILE__), *%w[out.log])
9
-
10
- w.behavior(:clean_pid_file)
11
-
12
- w.start_if do |start|
13
- start.condition(:process_running) do |c|
14
- c.running = false
15
- end
16
- end
17
- end
@@ -1,6 +0,0 @@
1
- require 'rubygems'
2
- require 'daemons'
3
-
4
- Daemons.run_proc('daemon-polls', {:dir_mode => :system}) do
5
- loop { STDOUT.puts('server'); STDOUT.flush; sleep 1 }
6
- end
@@ -1,31 +0,0 @@
1
- God.watch do |w|
2
- w.name = 'degrading-lambda'
3
- w.start = 'ruby ' + File.join(File.dirname(__FILE__), *%w[tcp_server.rb])
4
- w.interval = 5
5
- w.grace = 2
6
- w.group = 'test'
7
-
8
- w.start_if do |start|
9
- start.condition(:process_running) do |c|
10
- c.running = false
11
- end
12
- end
13
-
14
- w.restart_if do |restart|
15
- restart.condition(:degrading_lambda) do |c|
16
- require 'socket'
17
- c.lambda = lambda {
18
- begin
19
- sock = TCPSocket.open('127.0.0.1', 9090)
20
- sock.send "2\n", 0
21
- retval = sock.gets
22
- puts "Retval is #{retval}"
23
- sock.close
24
- retval
25
- rescue
26
- false
27
- end
28
- }
29
- end
30
- end
31
- end
@@ -1,15 +0,0 @@
1
- #! /usr/bin/env ruby
2
-
3
- require 'socket'
4
- server = TCPServer.new('127.0.0.1', 9090)
5
- while (session = server.accept)
6
- puts "Found a session"
7
- request = session.gets
8
- puts "Request: #{request}"
9
- time = request.to_i
10
- puts "Sleeping for #{time}"
11
- sleep time
12
- session.print "Slept for #{time} seconds"
13
- session.close
14
- puts "Session closed"
15
- end
@@ -1,9 +0,0 @@
1
- God.watch do |w|
2
- w.name = 'keepalive'
3
- w.start = File.join(GOD_ROOT, *%w[test configs keepalive keepalive.rb])
4
- w.log = File.join(GOD_ROOT, *%w[test configs keepalive keepalive.log])
5
-
6
- w.keepalive(:interval => 5.seconds,
7
- :memory_max => 10.megabytes,
8
- :cpu_max => 30.percent)
9
- end