diff options
author | Robin Houston <robin@lenny.robin> | 2011-06-29 21:48:41 +0100 |
---|---|---|
committer | Robin Houston <robin@lenny.robin> | 2011-06-29 21:48:41 +0100 |
commit | 2ee00e2716d7db65b909789021fed84f76a06db3 (patch) | |
tree | f3f7e034ab12b3d771b04a8118e110f58520d7a2 /script | |
parent | c923a0213abe3686da66db5c0a8db86075ef505a (diff) |
The alert-tracks script should write a log file.
It should also be automatically restarted if it dies
and the init.d script should not start the daemon
if it is already running (i.e. we should use --startas instead of --exec, when invoking start-stop-daemon).
Diffstat (limited to 'script')
-rwxr-xr-x | script/runner | 46 |
1 files changed, 29 insertions, 17 deletions
diff --git a/script/runner b/script/runner index c12421aa2..8cb4ec9d1 100755 --- a/script/runner +++ b/script/runner @@ -6,22 +6,34 @@ script_dir = File.dirname(__FILE__) alaveteli_dir = File.join(script_dir, "..") Dir.chdir(alaveteli_dir) do - require File.join(alaveteli_dir, 'config', 'boot') - if daemon_mode - # Run in daemon mode. - # - # If the environment variable PIDFILE is present, - # write the pid of the daemon process to that file. - - pid = fork { require 'commands/runner' } - if ENV.has_key? "PIDFILE" - File.open(ENV["PIDFILE"], 'w') do |fh| - fh.puts pid - end + require File.join(alaveteli_dir, 'config', 'boot') + if daemon_mode + # Run in daemon mode. + + # If the environment variable LOGFILE is present, + # redirect STDERR and STDOUT to that file. + if ENV.has_key? "LOGFILE" + STDERR.reopen(STDOUT.reopen(ENV["LOGFILE"], "a")) + STDOUT.sync=true + end + + # Load the runner in a subprocess + pid = fork do + require 'commands/runner' + exit 0 + end + + # If the environment variable PIDFILE is present, + # write the pid of the daemon process to that file. + if ENV.has_key? "PIDFILE" + File.open(ENV["PIDFILE"], 'w') do |fh| + fh.puts pid + end + end + + Process.detach(pid) + else + # Not daemon mode + require 'commands/runner' end - Process.detach(pid) - else - - require 'commands/runner' - end end |