3 $
:.unshift File
.join(File
.dirname(__FILE__
), *%w
[.. lib
])
12 options
= {:daemonize => true, :port => 17165}
14 OptionParser
.new
do |opts
|
16 Usage: god [command] [options]
19 start <watch or group name>
20 stop <watch or group name>
21 monitor <watch or group name>
22 unmonitor <watch or group name>
27 opts
.on("-cCONFIG", "--config-file CONFIG", "Configuration file") do |x
|
31 opts
.on("-pPORT", "--port PORT", "Communications port") do |x
|
35 opts
.on("-D", "--no-daemonize", "Don't daemonize") do
36 options
[:daemonize] = false
39 opts
.on("-v", "--version", "Print the version number and exit") do
40 options
[:version] = true
46 puts
"Version #{God::VERSION}"
48 elsif command
= ARGV[0]
49 # a command was specified
52 # module God; def self.at_exit; end; end
54 # get the name of the watch/group
57 # connect to remote drb
59 server
= DRbObject
.new
nil, "druby://localhost:#{options[:port]}"
62 puts
"Sending '#{command}' command"
65 watches
= server
.control(name
, command
)
68 puts
'The following watches were affected:'
72 rescue God
::InvalidCommandError
73 abort
"Command '#{command}' is not valid. Run 'god --help' for usage"
79 if !options
[:daemonize]
80 load File
.expand_path(options
[:config])
85 STDIN.reopen
"/dev/null"
86 STDOUT.reopen('god.log', "a")
91 unless God
::EventHandler.loaded
?
93 puts
"***********************************************************************"
95 puts
"* Event conditions are not available for your installation of god."
96 puts
"* You may still use and write custom conditions using the poll system"
98 puts
"***********************************************************************"
102 puts
"Resetting file descriptors"
104 # Daemons.daemonize if options[:daemonize]
106 puts
"Loading config"
108 load File
.expand_path(options
[:config])
110 File
.open('god.log', 'a') { |f
| f
.puts e
.message
+ "\n" + e
.backtrace
}
111 abort
"!!! ERROR !!!"
115 File
.open("god.pid", 'w') { |f
| f
.write pid
}
120 module God
; def self.at_exit
; end; end