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
55 puts
"Version #{God::VERSION}"
57 elsif command
= ARGV[0]
60 # a command was specified
63 # module God; def self.at_exit; end; end
65 # get the name of the watch/group
68 # connect to remote drb
70 server
= DRbObject
.new
nil, "druby://localhost:#{options[:port]}"
73 puts
"Sending '#{command}' command"
76 watches
= server
.control(name
, command
)
79 puts
'The following watches were affected:'
83 rescue God
::InvalidCommandError
84 abort
"Command '#{command}' is not valid. Run 'god --help' for usage"
90 if !options
[:daemonize]
92 load File
.expand_path(options
[:config])
100 log_file
= options
[:log] || "/dev/null"
102 STDIN.reopen
"/dev/null"
103 STDOUT.reopen(log_file
, "a")
108 unless God
::EventHandler.loaded
?
110 puts
"***********************************************************************"
112 puts
"* Event conditions are not available for your installation of god."
113 puts
"* You may still use and write custom conditions using the poll system"
115 puts
"***********************************************************************"
119 puts
"Resetting file descriptors"
121 # Daemons.daemonize if options[:daemonize]
123 puts
"Loading config"
125 load File
.expand_path(options
[:config])
127 File
.open('god.log', 'a') { |f
| f
.puts e
.message
+ "\n" + e
.backtrace
}
128 abort
"!!! ERROR !!!"
132 pid_file
= options
[:pid] || "god.pid"
133 File
.open(pid_file
, 'w') { |f
| f
.write pid
}