aboutsummaryrefslogtreecommitdiffstats
path: root/script/runner
blob: c12421aa21d80b3d7cd01c005a3dd8ee48275f5f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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.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