3 $
:.unshift File
.join(File
.dirname(__FILE__
), *%w
[.. lib
])
11 options
= {:daemonize => true, :port => 17165}
13 OptionParser
.new
do |opts
|
15 Usage: god [command] [options]
18 start <watch or group name>
19 stop <watch or group name>
20 monitor <watch or group name>
21 unmonitor <watch or group name>
26 opts
.on("-cCONFIG", "--config-file CONFIG", "Configuration file") do |x
|
30 opts
.on("-pPORT", "--port PORT", "Communications port") do |x
|
34 opts
.on("-PFILE", "--pid FILE", "Where to write the PID file") do |x
|
38 opts
.on("-lFILE", "--log FILE", "Where to write the log file") do |x
|
42 opts
.on("-D", "--no-daemonize", "Don't daemonize") do
43 options
[:daemonize] = false
46 opts
.on("-v", "--version", "Print the version number and exit") do
47 options
[:version] = true
50 opts
.on("-V", "Print extended version and build information") do
59 puts
"Version #{God::VERSION}"
64 puts
"Version: #{God::VERSION}"
66 puts
"Events: " + God
::EventHandler.event_system
69 elsif command
= ARGV[0]
72 # a command was specified
75 # module God; def self.at_exit; end; end
77 # get the name of the watch/group
80 # connect to remote drb
82 server
= DRbObject
.new
nil, "druby://localhost:#{options[:port]}"
85 puts
"Sending '#{command}' command"
88 watches
= server
.control(name
, command
)
91 puts
'The following watches were affected:'
95 rescue God
::InvalidCommandError
96 abort
"Command '#{command}' is not valid. Run 'god --help' for usage"
102 if !options
[:daemonize]
104 load File
.expand_path(options
[:config])
110 log_file
= options
[:log] || "/dev/null"
112 STDIN.reopen
"/dev/null"
113 STDOUT.reopen(log_file
, "a")
118 unless God
::EventHandler.loaded
?
120 puts
"***********************************************************************"
122 puts
"* Event conditions are not available for your installation of god."
123 puts
"* You may still use and write custom conditions using the poll system"
125 puts
"***********************************************************************"
129 puts
"Resetting file descriptors"
131 puts
"Loading config"
133 load File
.expand_path(options
[:config])
135 File
.open('god.log', 'a') { |f
| f
.puts e
.message
+ "\n" + e
.backtrace
}
136 abort
"!!! ERROR !!!"
141 File
.open(options
[:pid], 'w') { |f
| f
.write pid
}