add --log-level to cli tool
[god.git] / bin / god
blob57b86d8dce1109b32ac0ce6151c8f413da69eeb7
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, :log_level => "info"}
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 remove <task or group name> remove task or group from god
33 load <file> load a config into a running god
34 log <task name> show realtime log for given task
35 status show status of each task
36 quit stop god
37 terminate stop god and all tasks
38 check run self diagnostic
40 Options:
41 EOF
43 opts.on("-cCONFIG", "--config-file CONFIG", "Configuration file") do |x|
44 options[:config] = x
45 end
47 opts.on("-pPORT", "--port PORT", "Communications port (default 17165)") do |x|
48 options[:port] = x
49 end
51 opts.on("-b", "--auto-bind", "Auto-bind to an unused port number") do
52 options[:port] = "0"
53 end
55 opts.on("-PFILE", "--pid FILE", "Where to write the PID file") do |x|
56 options[:pid] = x
57 end
59 opts.on("-lFILE", "--log FILE", "Where to write the log file") do |x|
60 options[:log] = x
61 end
63 opts.on("-D", "--no-daemonize", "Don't daemonize") do
64 options[:daemonize] = false
65 end
67 opts.on("-v", "--version", "Print the version number and exit") do
68 options[:version] = true
69 end
71 opts.on("-V", "Print extended version and build information") do
72 options[:info] = true
73 end
75 opts.on("--log-level LEVEL", "Log level [debug|info|fatal]") do |x|
76 options[:log_level] = x.to_sym
77 end
78 end
80 opts.parse!
82 if !options[:config] && options[:version]
83 require 'god'
84 God::CLI::Version.version
85 elsif !options[:config] && options[:info]
86 require 'god'
87 God::CLI::Version.version_extended
88 elsif !options[:config] && command = ARGV[0]
89 require 'god'
90 God::CLI::Command.new(command, options, ARGV)
91 else
92 require 'god/cli/run'
93 God::CLI::Run.new(options)
94 end
95 rescue Exception => e
96 if e.instance_of?(SystemExit)
97 raise
98 else
99 puts 'Uncaught exception'
100 puts e.message
101 puts e.backtrace.join("\n")