3 $
:.unshift File
.join(File
.dirname(__FILE__
), *%w
[.. lib
])
9 options
= {:daemonize => true, :port => 17165}
11 OptionParser
.new
do |opts
|
13 Usage: god [command] [options]
16 start <watch or group name>
17 stop <watch or group name>
18 monitor <watch or group name>
19 unmonitor <watch or group name>
24 opts
.on("-cCONFIG", "--config-file CONFIG", "Configuration file") do |x
|
28 opts
.on("-pPORT", "--port PORT", "Communications port") do |x
|
32 opts
.on("-PFILE", "--pid FILE", "Where to write the PID file") do |x
|
36 opts
.on("-lFILE", "--log FILE", "Where to write the log file") do |x
|
40 opts
.on("-D", "--no-daemonize", "Don't daemonize") do
41 options
[:daemonize] = false
44 opts
.on("-v", "--version", "Print the version number and exit") do
45 options
[:version] = true
48 opts
.on("-V", "Print extended version and build information") do
57 puts
"Version #{God::VERSION}"
62 puts
"Version: #{God::VERSION}"
64 puts
"Events: " + God
::EventHandler.event_system
67 elsif command
= ARGV[0]
70 # a command was specified
73 # module God; def self.at_exit; end; end
75 # get the name of the watch/group
78 # connect to remote drb
80 server
= DRbObject
.new
nil, "druby://localhost:#{options[:port]}"
83 puts
"Sending '#{command}' command"
86 watches
= server
.control(name
, command
)
89 puts
'The following watches were affected:'
93 rescue God
::InvalidCommandError
94 abort
"Command '#{command}' is not valid. Run 'god --help' for usage"
100 if !options
[:daemonize]
102 load File
.expand_path(options
[:config])
108 log_file
= options
[:log] || "/dev/null"
110 STDIN.reopen
"/dev/null"
111 STDOUT.reopen(log_file
, "a")
116 unless God
::EventHandler.loaded
?
118 puts
"***********************************************************************"
120 puts
"* Event conditions are not available for your installation of god."
121 puts
"* You may still use and write custom conditions using the poll system"
123 puts
"***********************************************************************"
127 puts
"Resetting file descriptors"
129 puts
"Loading config"
131 load File
.expand_path(options
[:config])
133 File
.open('god.log', 'a') { |f
| f
.puts e
.message
+ "\n" + e
.backtrace
}
134 abort
"!!! ERROR !!!"
139 File
.open(options
[:pid], 'w') { |f
| f
.write pid
}