5 def initialize(command, options, args)
15 # connect to drb unix socket
17 @server = DRbObject.new(nil, God::Socket.socket(@options[:port]))
19 # ping server to ensure that it is responsive
22 rescue DRb::DRbConnError
23 puts "The server is not available (or you do not have permissions to access it)"
29 if %w{load status log quit terminate}.include?(@command)
30 send("#{@command}_command")
31 elsif %w{start stop restart monitor unmonitor}.include?(@command)
34 puts "Command '#{@command}' is not valid. Run 'god --help' for usage"
42 puts "Sending '#{@command}' command"
45 unless File.exist?(file)
46 abort "File not found: #{file}"
49 names, errors = *@server.running_load(File.read(file), File.expand_path(file))
53 puts 'The following tasks were affected:'
66 watches = @server.status
67 watches.keys.sort.each do |name|
68 state = watches[name][:state]
69 puts "#{name}: #{state}"
75 Signal.trap('INT') { exit }
79 print @server.running_log(name, t)
83 rescue God::NoSuchWatchError
85 rescue DRb::DRbConnError
86 puts "The server went away"
93 abort 'Could not stop god'
94 rescue DRb::DRbConnError
100 t = Thread.new { loop { STDOUT.print('.'); STDOUT.flush; sleep(1) } }
103 puts 'Stopped all watches'
106 puts 'Could not stop all watches within 10 seconds'
111 abort 'Could not stop god'
112 rescue DRb::DRbConnError
117 def lifecycle_command
118 # get the name of the watch/group
121 puts "Sending '#{@command}' command"
123 t = Thread.new { loop { sleep(1); STDOUT.print('.'); STDOUT.flush; sleep(1) } }
126 watches = @server.control(name, @command)
130 unless watches.empty?
131 puts 'The following watches were affected:'
136 puts 'No matching task or group'