aboutsummaryrefslogtreecommitdiffstats
path: root/script/runner
diff options
context:
space:
mode:
Diffstat (limited to 'script/runner')
-rwxr-xr-xscript/runner22
1 files changed, 20 insertions, 2 deletions
diff --git a/script/runner b/script/runner
index e6b09cfe5..c12421aa2 100755
--- a/script/runner
+++ b/script/runner
@@ -1,9 +1,27 @@
#!/usr/bin/ruby
+daemon_mode = !ARGV.empty? && ARGV[0] == "--daemon"
+
script_dir = File.dirname(__FILE__)
alaveteli_dir = File.join(script_dir, "..")
Dir.chdir(alaveteli_dir) do
- require File.dirname(__FILE__) + '/../config/boot'
- require 'commands/runner'
+ 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
+ end
+ Process.detach(pid)
+ else
+
+ require 'commands/runner'
+ end
end