3 $
:.unshift File
.join(File
.dirname(__FILE__
), *%w
[.. lib
])
12 unless God
::EventHandler.loaded
?
14 puts
"***********************************************************************"
16 puts
"* Event conditions are not available for your installation of god."
17 puts
"* You may still use and write custom conditions using the poll system"
19 puts
"***********************************************************************"
23 options
= {:daemonize => true, :port => 17165}
25 OptionParser
.new
do |opts
|
27 Usage: god [command] [options]
30 start <watch or group name>
31 stop <watch or group name>
32 monitor <watch or group name>
33 unmonitor <watch or group name>
38 opts
.on("-cCONFIG", "--config-file CONFIG", "Configuration file") do |x
|
42 opts
.on("-pPORT", "--port PORT", "Communications port") do |x
|
46 opts
.on("-D", "--no-daemonize", "Don't daemonize") do
47 options
[:daemonize] = false
50 opts
.on("-v", "--version", "Print the version number and exit") do
51 options
[:version] = true
56 puts
"Version #{God::VERSION}"
58 elsif command
= ARGV[0]
59 # a command was specified
61 # get the name of the watch/group
64 # connect to remote drb
66 server
= DRbObject
.new
nil, "druby://localhost:#{options[:port]}"
68 # get the list of watches
69 watches
= Array(server
.meddle
.watches
[name
] || server
.meddle
.groups
[name
])
73 when "start", "monitor"
74 watches
.each
{ |w
| w
.monitor
}
76 watches
.each
{ |w
| w
.move(:restart) }
78 watches
.each
{ |w
| w
.unmonitor
.action(:stop) }
80 watches
.each
{ |w
| w
.unmonitor
}
82 abort
"Command '#{command}' is not valid. Run 'god --help' for usage"
87 options
[:config] = File
.expand_path(options
[:config]) if options
[:config]
89 Daemons
.daemonize
if options
[:daemonize]