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/bin/god CHANGED
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- STDOUT.sync = true
3
+ $stdout.sync = true
4
4
 
5
- $:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
5
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
6
6
 
7
7
  require 'optparse'
8
8
  require 'drb'
@@ -12,10 +12,10 @@ begin
12
12
  # Save ARGV in case someone wants to use it later
13
13
  ORIGINAL_ARGV = ARGV.dup
14
14
 
15
- options = {:daemonize => true, :port => 17165, :syslog => true, :events => true}
15
+ options = { daemonize: true, port: 17165, syslog: true, events: true }
16
16
 
17
- opts = OptionParser.new do |opts|
18
- opts.banner = <<-EOF
17
+ opts = OptionParser.new do |o|
18
+ o.banner = <<-BANNER
19
19
  Usage:
20
20
  Starting:
21
21
  god [-c <config file>] [-p <port> | -b] [-P <file>] [-l <file>] [-D]
@@ -42,57 +42,57 @@ begin
42
42
  check run self diagnostic
43
43
 
44
44
  Options:
45
- EOF
45
+ BANNER
46
46
 
47
- opts.on("-cCONFIG", "--config-file CONFIG", "Configuration file") do |x|
47
+ o.on('-cCONFIG', '--config-file CONFIG', 'Configuration file') do |x|
48
48
  options[:config] = x
49
49
  end
50
50
 
51
- opts.on("-pPORT", "--port PORT", "Communications port (default 17165)") do |x|
51
+ o.on('-pPORT', '--port PORT', 'Communications port (default 17165)') do |x|
52
52
  options[:port] = x
53
53
  end
54
54
 
55
- opts.on("-b", "--auto-bind", "Auto-bind to an unused port number") do
56
- options[:port] = "0"
55
+ o.on('-b', '--auto-bind', 'Auto-bind to an unused port number') do
56
+ options[:port] = '0'
57
57
  end
58
58
 
59
- opts.on("-PFILE", "--pid FILE", "Where to write the PID file") do |x|
59
+ o.on('-PFILE', '--pid FILE', 'Where to write the PID file') do |x|
60
60
  options[:pid] = x
61
61
  end
62
62
 
63
- opts.on("-lFILE", "--log FILE", "Where to write the log file") do |x|
63
+ o.on('-lFILE', '--log FILE', 'Where to write the log file') do |x|
64
64
  options[:log] = x
65
65
  end
66
66
 
67
- opts.on("-D", "--no-daemonize", "Don't daemonize") do
67
+ o.on('-D', '--no-daemonize', "Don't daemonize") do
68
68
  options[:daemonize] = false
69
69
  end
70
70
 
71
- opts.on("-v", "--version", "Print the version number and exit") do
71
+ o.on('-v', '--version', 'Print the version number and exit') do
72
72
  options[:version] = true
73
73
  end
74
74
 
75
- opts.on("-V", "Print extended version and build information") do
75
+ o.on('-V', 'Print extended version and build information') do
76
76
  options[:info] = true
77
77
  end
78
78
 
79
- opts.on("--log-level LEVEL", "Log level [debug|info|warn|error|fatal]") do |x|
79
+ o.on('--log-level LEVEL', 'Log level [debug|info|warn|error|fatal]') do |x|
80
80
  options[:log_level] = x.to_sym
81
81
  end
82
82
 
83
- opts.on("--no-syslog", "Disable output to syslog") do
83
+ o.on('--no-syslog', 'Disable output to syslog') do
84
84
  options[:syslog] = false
85
85
  end
86
86
 
87
- opts.on("--attach PID", "Quit god when the attached process dies") do |x|
87
+ o.on('--attach PID', 'Quit god when the attached process dies') do |x|
88
88
  options[:attach] = x
89
89
  end
90
90
 
91
- opts.on("--no-events", "Disable the event system") do
91
+ o.on('--no-events', 'Disable the event system') do
92
92
  options[:events] = false
93
93
  end
94
94
 
95
- opts.on("--bleakhouse", "Enable bleakhouse profiling") do
95
+ o.on('--bleakhouse', 'Enable bleakhouse profiling') do
96
96
  options[:bleakhouse] = true
97
97
  end
98
98
  end
@@ -115,7 +115,7 @@ begin
115
115
  require 'god'
116
116
  God::EventHandler.load
117
117
  God::CLI::Version.version_extended
118
- elsif !options[:config] && command = ARGV[0]
118
+ elsif !options[:config] && (command = ARGV[0])
119
119
  require 'god'
120
120
  God::EventHandler.load
121
121
  God::CLI::Command.new(command, options, ARGV)
@@ -124,11 +124,9 @@ begin
124
124
  God::CLI::Run.new(options)
125
125
  end
126
126
  rescue Exception => e
127
- if e.instance_of?(SystemExit)
128
- raise
129
- else
130
- puts 'Uncaught exception'
131
- puts e.message
132
- puts e.backtrace.join("\n")
133
- end
127
+ raise if e.instance_of?(SystemExit)
128
+
129
+ puts 'Uncaught exception'
130
+ puts e.message
131
+ puts e.backtrace.join("\n")
134
132
  end
data/ext/god/extconf.rb CHANGED
@@ -3,9 +3,9 @@ require 'mkmf'
3
3
  fail = false
4
4
 
5
5
  def create_dummy_makefile
6
- File.open("Makefile", 'w') do |f|
7
- f.puts "all:"
8
- f.puts "install:"
6
+ File.open('Makefile', 'w') do |f|
7
+ f.puts 'all:'
8
+ f.puts 'install:'
9
9
  end
10
10
  end
11
11
 
@@ -20,7 +20,7 @@ when /bsd/i, /darwin/i
20
20
 
21
21
  if fail
22
22
  puts
23
- puts "Events handler could not be compiled (see above error). Your god installation will not support event conditions."
23
+ puts 'Events handler could not be compiled (see above error). Your god installation will not support event conditions.'
24
24
  create_dummy_makefile
25
25
  else
26
26
  create_makefile 'kqueue_handler_ext'
@@ -29,21 +29,21 @@ when /linux/i
29
29
  unless have_header('linux/netlink.h')
30
30
  puts
31
31
  puts "Missing 'linux/netlink.h' header(s)"
32
- puts "You may need to install a header package for your system"
32
+ puts 'You may need to install a header package for your system'
33
33
  fail = true
34
34
  end
35
35
 
36
36
  unless have_header('linux/connector.h') && have_header('linux/cn_proc.h')
37
37
  puts
38
38
  puts "Missing 'linux/connector.h', or 'linux/cn_proc.h' header(s)"
39
- puts "These are only available in Linux kernel 2.6.15 and later (run `uname -a` to find yours)"
40
- puts "You may need to install a header package for your system"
39
+ puts 'These are only available in Linux kernel 2.6.15 and later (run `uname -a` to find yours)'
40
+ puts 'You may need to install a header package for your system'
41
41
  fail = true
42
42
  end
43
43
 
44
44
  if fail
45
45
  puts
46
- puts "Events handler could not be compiled (see above error). Your god installation will not support event conditions."
46
+ puts 'Events handler could not be compiled (see above error). Your god installation will not support event conditions.'
47
47
  create_dummy_makefile
48
48
  else
49
49
  create_makefile 'netlink_handler_ext'
@@ -51,6 +51,6 @@ when /linux/i
51
51
  else
52
52
  puts
53
53
  puts "Unsupported platform '#{RUBY_PLATFORM}'. Supported platforms are BSD, DARWIN, and LINUX."
54
- puts "Your god installation will not support event conditions."
54
+ puts 'Your god installation will not support event conditions.'
55
55
  create_dummy_makefile
56
56
  end
data/lib/god/behavior.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  module God
2
-
3
2
  class Behavior
4
3
  include Configurable
5
4
 
@@ -9,12 +8,12 @@ module God
9
8
  # kind (which is given as an underscored symbol).
10
9
  # +kind+ is the underscored symbol representing the class (e.g. foo_bar for God::Behaviors::FooBar)
11
10
  def self.generate(kind, watch)
12
- sym = kind.to_s.capitalize.gsub(/_(.)/){$1.upcase}.intern
11
+ sym = kind.to_s.capitalize.gsub(/_(.)/) { Regexp.last_match(1).upcase }.intern
13
12
  b = God::Behaviors.const_get(sym).new
14
13
  b.watch = watch
15
14
  b
16
15
  rescue NameError
17
- raise NoSuchBehaviorError.new("No Behavior found with the class name God::Behaviors::#{sym}")
16
+ raise NoSuchBehaviorError, "No Behavior found with the class name God::Behaviors::#{sym}"
18
17
  end
19
18
 
20
19
  def valid?
@@ -45,8 +44,7 @@ module God
45
44
  #
46
45
  # Behavior FooBar on Watch 'baz'
47
46
  def friendly_name
48
- "Behavior " + super + " on Watch '#{self.watch.name}'"
47
+ "Behavior #{super} on Watch '#{watch.name}'"
49
48
  end
50
49
  end
51
-
52
50
  end
@@ -1,21 +1,19 @@
1
1
  module God
2
2
  module Behaviors
3
-
4
3
  class CleanPidFile < Behavior
5
4
  def valid?
6
5
  valid = true
7
- valid &= complain("Attribute 'pid_file' must be specified", self) if self.watch.pid_file.nil?
6
+ valid &= complain("Attribute 'pid_file' must be specified", self) if watch.pid_file.nil?
8
7
  valid
9
8
  end
10
9
 
11
10
  def before_start
12
- File.delete(self.watch.pid_file)
11
+ File.delete(watch.pid_file)
13
12
 
14
- "deleted pid file"
13
+ 'deleted pid file'
15
14
  rescue
16
- "no pid file to delete"
15
+ 'no pid file to delete'
17
16
  end
18
17
  end
19
-
20
18
  end
21
19
  end
@@ -1,21 +1,19 @@
1
1
  module God
2
2
  module Behaviors
3
-
4
3
  class CleanUnixSocket < Behavior
5
4
  def valid?
6
5
  valid = true
7
- valid &= complain("Attribute 'unix_socket' must be specified", self) if self.watch.unix_socket.nil?
6
+ valid &= complain("Attribute 'unix_socket' must be specified", self) if watch.unix_socket.nil?
8
7
  valid
9
8
  end
10
9
 
11
10
  def before_start
12
- File.delete(self.watch.unix_socket)
11
+ File.delete(watch.unix_socket)
13
12
 
14
- "deleted unix socket"
13
+ 'deleted unix socket'
15
14
  rescue
16
- "no unix socket to delete"
15
+ 'no unix socket to delete'
17
16
  end
18
17
  end
19
-
20
18
  end
21
19
  end
@@ -1,10 +1,9 @@
1
1
  module God
2
2
  module Behaviors
3
-
4
3
  class NotifyWhenFlapping < Behavior
5
- attr_accessor :failures # number of failures
6
- attr_accessor :seconds # number of seconds
7
- attr_accessor :notifier # class to notify with
4
+ attr_accessor :failures, # number of failures
5
+ :seconds, # number of seconds
6
+ :notifier # class to notify with
8
7
 
9
8
  def initialize
10
9
  super
@@ -13,12 +12,12 @@ module God
13
12
 
14
13
  def valid?
15
14
  valid = true
16
- valid &= complain("Attribute 'failures' must be specified", self) unless self.failures
17
- valid &= complain("Attribute 'seconds' must be specified", self) unless self.seconds
18
- valid &= complain("Attribute 'notifier' must be specified", self) unless self.notifier
15
+ valid &= complain("Attribute 'failures' must be specified", self) unless failures
16
+ valid &= complain("Attribute 'seconds' must be specified", self) unless seconds
17
+ valid &= complain("Attribute 'notifier' must be specified", self) unless notifier
19
18
 
20
19
  # Must take one arg or variable args
21
- unless self.notifier.respond_to?(:notify) and [1,-1].include?(self.notifier.method(:notify).arity)
20
+ unless notifier.respond_to?(:notify) && [1, -1].include?(notifier.method(:notify).arity)
22
21
  valid &= complain("The 'notifier' must have a method 'notify' which takes 1 or variable args", self)
23
22
  end
24
23
 
@@ -39,13 +38,12 @@ module God
39
38
 
40
39
  private
41
40
 
42
- def check_for_flapping(now)
43
- @startup_times.select! {|time| time >= now - self.seconds }
44
- if @startup_times.length >= self.failures
45
- self.notifier.notify("#{self.watch.name} has called start/restart #{@startup_times.length} times in #{self.seconds} seconds")
46
- end
47
- end
48
- end
41
+ def check_for_flapping(now)
42
+ @startup_times.select! { |time| time >= now - seconds }
43
+ return if @startup_times.length < failures
49
44
 
45
+ notifier.notify("#{watch.name} has called start/restart #{@startup_times.length} times in #{seconds} seconds")
46
+ end
47
+ end
50
48
  end
51
49
  end
@@ -1,6 +1,5 @@
1
1
  module God
2
2
  module CLI
3
-
4
3
  class Command
5
4
  def initialize(command, options, args)
6
5
  @command = command
@@ -18,16 +17,16 @@ module God
18
17
  begin
19
18
  @server.ping
20
19
  rescue DRb::DRbConnError
21
- puts "The server is not available (or you do not have permissions to access it)"
20
+ puts 'The server is not available (or you do not have permissions to access it)'
22
21
  abort
23
22
  end
24
23
  end
25
24
 
26
25
  def dispatch
27
- if %w{load status signal log quit terminate}.include?(@command)
26
+ if %w[load status signal log quit terminate].include?(@command)
28
27
  setup
29
28
  send("#{@command}_command")
30
- elsif %w{start stop restart monitor unmonitor remove}.include?(@command)
29
+ elsif %w[start stop restart monitor unmonitor remove].include?(@command)
31
30
  setup
32
31
  lifecycle_command
33
32
  elsif @command == 'check'
@@ -50,9 +49,7 @@ module God
50
49
  puts "Sending '#{@command}' command with action '#{action}'"
51
50
  puts
52
51
 
53
- unless File.exist?(file)
54
- abort "File not found: #{file}"
55
- end
52
+ abort "File not found: #{file}" unless File.exist?(file)
56
53
 
57
54
  affected, errors, removed = *@server.running_load(File.read(file), File.expand_path(file), action)
58
55
 
@@ -60,21 +57,21 @@ module God
60
57
  unless affected.empty?
61
58
  puts 'The following tasks were affected:'
62
59
  affected.each do |w|
63
- puts ' ' + w
60
+ puts " #{w}"
64
61
  end
65
62
  end
66
63
 
67
64
  unless removed.empty?
68
65
  puts 'The following tasks were removed:'
69
66
  removed.each do |w|
70
- puts ' ' + w
67
+ puts " #{w}"
71
68
  end
72
69
  end
73
70
 
74
- unless errors.empty?
75
- puts errors
76
- exit(1)
77
- end
71
+ return if errors.empty?
72
+
73
+ puts errors
74
+ exit(1)
78
75
  end
79
76
 
80
77
  def status_command
@@ -87,18 +84,25 @@ module God
87
84
  groups[g][name] = status
88
85
  end
89
86
 
90
- if item = @args[1]
91
- if single = statuses[item]
87
+ if (item = @args[1])
88
+ if (single = statuses[item])
92
89
  # specified task (0 -> up, 1 -> unmonitored, 2 -> other)
93
90
  state = single[:state]
94
91
  puts "#{item}: #{state}"
95
- exitcode = state == :up ? 0 : (state == :unmonitored ? 1 : 2)
92
+ exitcode = case state
93
+ when :up
94
+ 0
95
+ when :unmonitored
96
+ 1
97
+ else
98
+ 2
99
+ end
96
100
  elsif groups[item]
97
101
  # specified group (0 -> up, N -> other)
98
102
  puts "#{item}:"
99
103
  groups[item].keys.sort.each do |name|
100
104
  state = groups[item][name][:state]
101
- print " "
105
+ print ' '
102
106
  puts "#{name}: #{state}"
103
107
  exitcode += 1 unless state == :up
104
108
  end
@@ -112,7 +116,7 @@ module God
112
116
  puts "#{group}:" unless group.empty?
113
117
  groups[group].keys.sort.each do |name|
114
118
  state = groups[group][name][:state]
115
- print " " unless group.empty?
119
+ print ' ' unless group.empty?
116
120
  puts "#{name}: #{state}"
117
121
  end
118
122
  end
@@ -128,62 +132,73 @@ module God
128
132
 
129
133
  puts "Sending signal '#{signal}' to '#{name}'"
130
134
 
131
- t = Thread.new { loop { sleep(1); STDOUT.print('.'); STDOUT.flush; sleep(1) } }
135
+ t = Thread.new do
136
+ loop do
137
+ sleep(1)
138
+ $stdout.print('.')
139
+ $stdout.flush
140
+ sleep(1)
141
+ end
142
+ end
132
143
 
133
144
  watches = @server.signal(name, signal)
134
145
 
135
146
  # output response
136
- t.kill; STDOUT.puts
137
- unless watches.empty?
147
+ t.kill
148
+ $stdout.puts
149
+ if watches.empty?
150
+ puts 'No matching task or group'
151
+ else
138
152
  puts 'The following watches were affected:'
139
153
  watches.each do |w|
140
- puts ' ' + w
154
+ puts " #{w}"
141
155
  end
142
- else
143
- puts 'No matching task or group'
144
156
  end
145
157
  end
146
158
 
147
159
  def log_command
148
- begin
149
- Signal.trap('INT') { exit }
150
- name = @args[1]
160
+ Signal.trap('INT') { exit }
161
+ name = @args[1]
151
162
 
152
- unless name
153
- puts "You must specify a Task or Group name"
154
- exit!
155
- end
163
+ unless name
164
+ puts 'You must specify a Task or Group name'
165
+ exit!
166
+ end
156
167
 
157
- puts "Please wait..."
158
- t = Time.at(0)
159
- loop do
160
- print @server.running_log(name, t)
161
- t = Time.now
162
- sleep 0.25
163
- end
164
- rescue God::NoSuchWatchError
165
- puts "No such watch"
166
- rescue DRb::DRbConnError
167
- puts "The server went away"
168
+ puts 'Please wait...'
169
+ t = Time.at(0)
170
+ loop do
171
+ print @server.running_log(name, t)
172
+ t = Time.now
173
+ sleep 0.25
168
174
  end
175
+ rescue God::NoSuchWatchError
176
+ puts 'No such watch'
177
+ rescue DRb::DRbConnError
178
+ puts 'The server went away'
169
179
  end
170
180
 
171
181
  def quit_command
172
- begin
173
- @server.terminate
174
- abort 'Could not stop god'
175
- rescue DRb::DRbConnError
176
- puts 'Stopped god'
177
- end
182
+ @server.terminate
183
+ abort 'Could not stop god'
184
+ rescue DRb::DRbConnError
185
+ puts 'Stopped god'
178
186
  end
179
187
 
180
188
  def terminate_command
181
- t = Thread.new { loop { STDOUT.print('.'); STDOUT.flush; sleep(1) } }
182
- if @server.stop_all
183
- t.kill; STDOUT.puts
189
+ t = Thread.new do
190
+ loop do
191
+ $stdout.print('.')
192
+ $stdout.flush
193
+ sleep(1)
194
+ end
195
+ end
196
+ stopped = @server.stop_all
197
+ t.kill
198
+ $stdout.puts
199
+ if stopped
184
200
  puts 'Stopped all watches'
185
201
  else
186
- t.kill; STDOUT.puts
187
202
  puts "Could not stop all watches within #{@server.terminate_timeout} seconds"
188
203
  end
189
204
 
@@ -197,46 +212,44 @@ module God
197
212
 
198
213
  def check_command
199
214
  Thread.new do
200
- begin
201
- event_system = God::EventHandler.event_system
202
- puts "using event system: #{event_system}"
203
-
204
- if God::EventHandler.loaded?
205
- puts "starting event handler"
206
- God::EventHandler.start
207
- else
208
- puts "[fail] event system did not load"
209
- exit(1)
210
- end
215
+ event_system = God::EventHandler.event_system
216
+ puts "using event system: #{event_system}"
211
217
 
212
- puts 'forking off new process'
218
+ if God::EventHandler.loaded?
219
+ puts 'starting event handler'
220
+ God::EventHandler.start
221
+ else
222
+ puts '[fail] event system did not load'
223
+ exit(1)
224
+ end
213
225
 
214
- pid = fork do
215
- loop { sleep(1) }
216
- end
226
+ puts 'forking off new process'
217
227
 
218
- puts "forked process with pid = #{pid}"
228
+ pid = fork do
229
+ loop { sleep(1) }
230
+ end
219
231
 
220
- God::EventHandler.register(pid, :proc_exit) do
221
- puts "[ok] process exit event received"
222
- exit!(0)
223
- end
232
+ puts "forked process with pid = #{pid}"
224
233
 
225
- sleep(1)
234
+ God::EventHandler.register(pid, :proc_exit) do
235
+ puts '[ok] process exit event received'
236
+ exit!(0)
237
+ end
226
238
 
227
- puts "killing process"
239
+ sleep(1)
228
240
 
229
- ::Process.kill('KILL', pid)
230
- ::Process.waitpid(pid)
231
- rescue => e
232
- puts e.message
233
- puts e.backtrace.join("\n")
234
- end
241
+ puts 'killing process'
242
+
243
+ ::Process.kill('KILL', pid)
244
+ ::Process.waitpid(pid)
245
+ rescue => e
246
+ puts e.message
247
+ puts e.backtrace.join("\n")
235
248
  end
236
249
 
237
250
  sleep(2)
238
251
 
239
- puts "[fail] never received process exit event"
252
+ puts '[fail] never received process exit event'
240
253
  exit(1)
241
254
  end
242
255
 
@@ -246,23 +259,30 @@ module God
246
259
 
247
260
  puts "Sending '#{@command}' command"
248
261
 
249
- t = Thread.new { loop { sleep(1); STDOUT.print('.'); STDOUT.flush; sleep(1) } }
262
+ t = Thread.new do
263
+ loop do
264
+ sleep(1)
265
+ $stdout.print('.')
266
+ $stdout.flush
267
+ sleep(1)
268
+ end
269
+ end
250
270
 
251
271
  # send @command
252
272
  watches = @server.control(name, @command)
253
273
 
254
274
  # output response
255
- t.kill; STDOUT.puts
256
- unless watches.empty?
275
+ t.kill
276
+ $stdout.puts
277
+ if watches.empty?
278
+ puts 'No matching task or group'
279
+ else
257
280
  puts 'The following watches were affected:'
258
281
  watches.each do |w|
259
- puts ' ' + w
282
+ puts " #{w}"
260
283
  end
261
- else
262
- puts 'No matching task or group'
263
284
  end
264
285
  end
265
- end # Command
266
-
286
+ end
267
287
  end
268
288
  end