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.
- checksums.yaml +4 -4
- data/History.md +559 -0
- data/README.md +9 -4
- data/bin/god +26 -28
- data/ext/god/extconf.rb +9 -9
- data/lib/god/behavior.rb +3 -5
- data/lib/god/behaviors/clean_pid_file.rb +4 -6
- data/lib/god/behaviors/clean_unix_socket.rb +4 -6
- data/lib/god/behaviors/notify_when_flapping.rb +13 -15
- data/lib/god/cli/command.rb +109 -89
- data/lib/god/cli/run.rb +51 -75
- data/lib/god/cli/version.rb +2 -4
- data/lib/god/condition.rb +12 -14
- data/lib/god/conditions/always.rb +3 -2
- data/lib/god/conditions/complex.rb +23 -24
- data/lib/god/conditions/cpu_usage.rb +12 -16
- data/lib/god/conditions/degrading_lambda.rb +15 -19
- data/lib/god/conditions/disk_usage.rb +7 -8
- data/lib/god/conditions/file_mtime.rb +3 -7
- data/lib/god/conditions/file_touched.rb +4 -5
- data/lib/god/conditions/flapping.rb +57 -62
- data/lib/god/conditions/http_response_code.rb +27 -32
- data/lib/god/conditions/lambda.rb +3 -5
- data/lib/god/conditions/memory_usage.rb +12 -16
- data/lib/god/conditions/process_exits.rb +12 -12
- data/lib/god/conditions/process_running.rb +8 -10
- data/lib/god/conditions/socket_responding.rb +23 -28
- data/lib/god/conditions/tries.rb +12 -14
- data/lib/god/configurable.rb +7 -10
- data/lib/god/contact.rb +41 -52
- data/lib/god/contacts/airbrake.rb +10 -12
- data/lib/god/contacts/campfire.rb +18 -20
- data/lib/god/contacts/email.rb +27 -28
- data/lib/god/contacts/prowl.rb +16 -17
- data/lib/god/contacts/scout.rb +2 -5
- data/lib/god/contacts/sensu.rb +15 -11
- data/lib/god/contacts/slack.rb +23 -33
- data/lib/god/contacts/statsd.rb +8 -8
- data/lib/god/contacts/twitter.rb +2 -2
- data/lib/god/contacts/webhook.rb +21 -24
- data/lib/god/driver.rb +12 -18
- data/lib/god/errors.rb +0 -2
- data/lib/god/event_handler.rb +40 -49
- data/lib/god/event_handlers/dummy_handler.rb +1 -1
- data/lib/god/event_handlers/kqueue_handler.rb +2 -2
- data/lib/god/event_handlers/netlink_handler.rb +1 -1
- data/lib/god/logger.rb +5 -13
- data/lib/god/metric.rb +13 -15
- data/lib/god/process.rb +93 -98
- data/lib/god/simple_logger.rb +13 -15
- data/lib/god/socket.rb +21 -23
- data/lib/god/sugar.rb +8 -8
- data/lib/god/sys_logger.rb +6 -8
- data/lib/god/system/portable_poller.rb +1 -9
- data/lib/god/system/process.rb +4 -6
- data/lib/god/system/slash_proc_poller.rb +17 -19
- data/lib/god/task.rb +110 -136
- data/lib/god/timeline.rb +2 -4
- data/lib/god/trigger.rb +7 -11
- data/lib/god/version.rb +1 -1
- data/lib/god/watch.rb +51 -57
- data/lib/god.rb +122 -148
- metadata +17 -370
- data/Announce.txt +0 -135
- data/Gemfile +0 -5
- data/Rakefile +0 -129
- data/doc/god.asciidoc +0 -1592
- data/doc/intro.asciidoc +0 -20
- data/ext/god/.gitignore +0 -5
- data/lib/god/compat19.rb +0 -33
- data/lib/god/contacts/hipchat.rb +0 -117
- data/lib/god/contacts/jabber.rb +0 -75
- data/test/configs/child_events/child_events.god +0 -44
- data/test/configs/child_events/simple_server.rb +0 -3
- data/test/configs/child_polls/child_polls.god +0 -37
- data/test/configs/child_polls/simple_server.rb +0 -12
- data/test/configs/complex/complex.god +0 -59
- data/test/configs/complex/simple_server.rb +0 -3
- data/test/configs/contact/contact.god +0 -118
- data/test/configs/contact/simple_server.rb +0 -3
- data/test/configs/daemon_events/daemon_events.god +0 -37
- data/test/configs/daemon_events/simple_server.rb +0 -8
- data/test/configs/daemon_events/simple_server_stop.rb +0 -11
- data/test/configs/daemon_polls/daemon_polls.god +0 -17
- data/test/configs/daemon_polls/simple_server.rb +0 -6
- data/test/configs/degrading_lambda/degrading_lambda.god +0 -31
- data/test/configs/degrading_lambda/tcp_server.rb +0 -15
- data/test/configs/keepalive/keepalive.god +0 -9
- data/test/configs/keepalive/keepalive.rb +0 -12
- data/test/configs/lifecycle/lifecycle.god +0 -25
- data/test/configs/matias/matias.god +0 -50
- data/test/configs/real.rb +0 -59
- data/test/configs/running_load/running_load.god +0 -16
- data/test/configs/stop_options/simple_server.rb +0 -12
- data/test/configs/stop_options/stop_options.god +0 -39
- data/test/configs/stress/simple_server.rb +0 -3
- data/test/configs/stress/stress.god +0 -15
- data/test/configs/task/logs/.placeholder +0 -0
- data/test/configs/task/task.god +0 -26
- data/test/configs/test.rb +0 -61
- data/test/configs/usr1_trapper.rb +0 -10
- data/test/helper.rb +0 -172
- data/test/suite.rb +0 -6
- data/test/test_airbrake.rb +0 -14
- data/test/test_behavior.rb +0 -18
- data/test/test_campfire.rb +0 -22
- data/test/test_condition.rb +0 -52
- data/test/test_conditions_disk_usage.rb +0 -50
- data/test/test_conditions_http_response_code.rb +0 -109
- data/test/test_conditions_process_running.rb +0 -40
- data/test/test_conditions_socket_responding.rb +0 -176
- data/test/test_conditions_tries.rb +0 -67
- data/test/test_contact.rb +0 -109
- data/test/test_driver.rb +0 -26
- data/test/test_email.rb +0 -34
- data/test/test_event_handler.rb +0 -82
- data/test/test_god.rb +0 -710
- data/test/test_god_system.rb +0 -201
- data/test/test_handlers_kqueue_handler.rb +0 -16
- data/test/test_hipchat.rb +0 -23
- data/test/test_jabber.rb +0 -29
- data/test/test_logger.rb +0 -55
- data/test/test_metric.rb +0 -74
- data/test/test_process.rb +0 -263
- data/test/test_prowl.rb +0 -15
- data/test/test_registry.rb +0 -15
- data/test/test_sensu.rb +0 -11
- data/test/test_slack.rb +0 -57
- data/test/test_socket.rb +0 -34
- data/test/test_statsd.rb +0 -22
- data/test/test_sugar.rb +0 -42
- data/test/test_system_portable_poller.rb +0 -17
- data/test/test_system_process.rb +0 -30
- data/test/test_task.rb +0 -246
- data/test/test_timeline.rb +0 -37
- data/test/test_trigger.rb +0 -63
- data/test/test_watch.rb +0 -286
- data/test/test_webhook.rb +0 -22
data/bin/god
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
3
|
+
$stdout.sync = true
|
4
4
|
|
5
|
-
|
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 = {:
|
15
|
+
options = { daemonize: true, port: 17165, syslog: true, events: true }
|
16
16
|
|
17
|
-
opts = OptionParser.new do |
|
18
|
-
|
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
|
-
|
45
|
+
BANNER
|
46
46
|
|
47
|
-
|
47
|
+
o.on('-cCONFIG', '--config-file CONFIG', 'Configuration file') do |x|
|
48
48
|
options[:config] = x
|
49
49
|
end
|
50
50
|
|
51
|
-
|
51
|
+
o.on('-pPORT', '--port PORT', 'Communications port (default 17165)') do |x|
|
52
52
|
options[:port] = x
|
53
53
|
end
|
54
54
|
|
55
|
-
|
56
|
-
options[:port] =
|
55
|
+
o.on('-b', '--auto-bind', 'Auto-bind to an unused port number') do
|
56
|
+
options[:port] = '0'
|
57
57
|
end
|
58
58
|
|
59
|
-
|
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
|
-
|
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
|
-
|
67
|
+
o.on('-D', '--no-daemonize', "Don't daemonize") do
|
68
68
|
options[:daemonize] = false
|
69
69
|
end
|
70
70
|
|
71
|
-
|
71
|
+
o.on('-v', '--version', 'Print the version number and exit') do
|
72
72
|
options[:version] = true
|
73
73
|
end
|
74
74
|
|
75
|
-
|
75
|
+
o.on('-V', 'Print extended version and build information') do
|
76
76
|
options[:info] = true
|
77
77
|
end
|
78
78
|
|
79
|
-
|
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
|
-
|
83
|
+
o.on('--no-syslog', 'Disable output to syslog') do
|
84
84
|
options[:syslog] = false
|
85
85
|
end
|
86
86
|
|
87
|
-
|
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
|
-
|
91
|
+
o.on('--no-events', 'Disable the event system') do
|
92
92
|
options[:events] = false
|
93
93
|
end
|
94
94
|
|
95
|
-
|
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
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
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(
|
7
|
-
f.puts
|
8
|
-
f.puts
|
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
|
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
|
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
|
40
|
-
puts
|
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
|
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
|
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(/_(.)/){
|
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
|
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
|
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
|
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(
|
11
|
+
File.delete(watch.pid_file)
|
13
12
|
|
14
|
-
|
13
|
+
'deleted pid file'
|
15
14
|
rescue
|
16
|
-
|
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
|
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(
|
11
|
+
File.delete(watch.unix_socket)
|
13
12
|
|
14
|
-
|
13
|
+
'deleted unix socket'
|
15
14
|
rescue
|
16
|
-
|
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
|
-
|
7
|
-
|
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
|
17
|
-
valid &= complain("Attribute 'seconds' must be specified", self) unless
|
18
|
-
valid &= complain("Attribute 'notifier' must be specified", self) unless
|
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
|
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
|
-
|
43
|
-
|
44
|
-
|
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
|
data/lib/god/cli/command.rb
CHANGED
@@ -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
|
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
|
26
|
+
if %w[load status signal log quit terminate].include?(@command)
|
28
27
|
setup
|
29
28
|
send("#{@command}_command")
|
30
|
-
elsif %w
|
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
|
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
|
67
|
+
puts " #{w}"
|
71
68
|
end
|
72
69
|
end
|
73
70
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
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 =
|
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
|
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
|
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
|
137
|
-
|
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
|
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
|
-
|
149
|
-
|
150
|
-
name = @args[1]
|
160
|
+
Signal.trap('INT') { exit }
|
161
|
+
name = @args[1]
|
151
162
|
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
163
|
+
unless name
|
164
|
+
puts 'You must specify a Task or Group name'
|
165
|
+
exit!
|
166
|
+
end
|
156
167
|
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
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
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
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
|
182
|
-
|
183
|
-
|
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
|
-
|
201
|
-
|
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
|
-
|
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
|
-
|
215
|
-
loop { sleep(1) }
|
216
|
-
end
|
226
|
+
puts 'forking off new process'
|
217
227
|
|
218
|
-
|
228
|
+
pid = fork do
|
229
|
+
loop { sleep(1) }
|
230
|
+
end
|
219
231
|
|
220
|
-
|
221
|
-
puts "[ok] process exit event received"
|
222
|
-
exit!(0)
|
223
|
-
end
|
232
|
+
puts "forked process with pid = #{pid}"
|
224
233
|
|
225
|
-
|
234
|
+
God::EventHandler.register(pid, :proc_exit) do
|
235
|
+
puts '[ok] process exit event received'
|
236
|
+
exit!(0)
|
237
|
+
end
|
226
238
|
|
227
|
-
|
239
|
+
sleep(1)
|
228
240
|
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
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
|
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
|
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
|
256
|
-
|
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
|
282
|
+
puts " #{w}"
|
260
283
|
end
|
261
|
-
else
|
262
|
-
puts 'No matching task or group'
|
263
284
|
end
|
264
285
|
end
|
265
|
-
end
|
266
|
-
|
286
|
+
end
|
267
287
|
end
|
268
288
|
end
|