aboutsummaryrefslogtreecommitdiffstats
path: root/script
diff options
context:
space:
mode:
authorSeb Bacon <seb.bacon@gmail.com>2011-07-05 09:56:59 +0100
committerSeb Bacon <seb.bacon@gmail.com>2011-07-05 09:56:59 +0100
commit74a7c2a1659ce9101c11e7bf6c53eeca2feef576 (patch)
tree959a25e29dca3e18f3fba6715549245648a26855 /script
parent5b78f72751b0bfa24f436420131e6ac6514ffa80 (diff)
parent74249524b08a2782d1f7272af3c66f081977367d (diff)
Merge branch 'master' of github.com:sebbacon/alaveteli
Diffstat (limited to 'script')
-rwxr-xr-xscript/runner47
1 files changed, 30 insertions, 17 deletions
diff --git a/script/runner b/script/runner
index c12421aa2..5a5254c47 100755
--- a/script/runner
+++ b/script/runner
@@ -6,22 +6,35 @@ 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
+ puts "Daemon starting at #{Time.new}"
+ 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