add god check to binary
[god.git] / bin / god
blobd9b324668b9a140508b58379104e7c4a8b8c87f0
1 #!/usr/bin/env ruby
3 STDOUT.sync = true
5 $:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
7 require 'rubygems'
8 require 'optparse'
9 require 'drb'
11 begin
12 options = {:daemonize => true, :port => 17165}
14 opts = OptionParser.new do |opts|
15 opts.banner = <<-EOF
16 Usage:
17 Starting:
18 god [-c <config file>] [-p <port> | -b] [-P <file>] [-l <file>] [-D]
20 Querying:
21 god <command> <argument> [-p <port>]
22 god <command> [-p <port>]
23 god -v
24 god -V (must be run as root to be accurate on Linux)
26 Commands:
27 start <task or group name> start task or group
28 restart <task or group name> restart task or group
29 stop <task or group name> stop task or group
30 monitor <task or group name> monitor task or group
31 unmonitor <task or group name> unmonitor task or group
32 load <file> load a config into a running god
33 log <task name> show realtime log for given task
34 status show status of each task
35 quit stop god
36 terminate stop god and all tasks
37 check run self diagnostic
39 Options:
40 EOF
42 opts.on("-cCONFIG", "--config-file CONFIG", "Configuration file") do |x|
43 options[:config] = x
44 end
46 opts.on("-pPORT", "--port PORT", "Communications port (default 17165)") do |x|
47 options[:port] = x
48 end
50 opts.on("-b", "--auto-bind", "Auto-bind to an unused port number") do
51 options[:port] = "0"
52 end
54 opts.on("-PFILE", "--pid FILE", "Where to write the PID file") do |x|
55 options[:pid] = x
56 end
58 opts.on("-lFILE", "--log FILE", "Where to write the log file") do |x|
59 options[:log] = x
60 end
62 opts.on("-D", "--no-daemonize", "Don't daemonize") do
63 options[:daemonize] = false
64 end
66 opts.on("-v", "--version", "Print the version number and exit") do
67 options[:version] = true
68 end
70 opts.on("-V", "Print extended version and build information") do
71 options[:info] = true
72 end
73 end
75 opts.parse!
77 if !options[:config] && options[:version]
78 require 'god'
79 God::CLI::Version.version
80 elsif !options[:config] && options[:info]
81 require 'god'
82 God::CLI::Version.version_extended
83 elsif !options[:config] && command = ARGV[0]
84 require 'god'
85 God::CLI::Command.new(command, options, ARGV)
86 else
87 require 'god/cli/run'
88 God::CLI::Run.new(options)
89 end
90 rescue Exception => e
91 if e.instance_of?(SystemExit)
92 raise
93 else
94 puts 'Uncaught exception'
95 puts e.message
96 puts e.backtrace.join("\n")
97 end
98 end