diff options
| author | Robin Houston <robin@lenny.robin> | 2011-06-22 12:58:42 +0100 | 
|---|---|---|
| committer | Robin Houston <robin@lenny.robin> | 2011-06-22 12:58:42 +0100 | 
| commit | 2b702618b958143df675302b80a0c480be7dd8ed (patch) | |
| tree | dbaf53fe2b0c5e6993fde2a28f3e559d2c0d1527 | |
| parent | d7865323b12686b34cee8657440c0637f01c978d (diff) | |
Ah, the alert-tracks daemon needs to put itself into the background,
and write a pid file.
| -rw-r--r-- | config/alert-tracks-debian.ugly | 2 | ||||
| -rwxr-xr-x | script/alert-tracks-daemon | 4 | ||||
| -rwxr-xr-x | script/runner | 22 | 
3 files changed, 24 insertions, 4 deletions
| diff --git a/config/alert-tracks-debian.ugly b/config/alert-tracks-debian.ugly index 8c2acdbb9..6dfa811a4 100644 --- a/config/alert-tracks-debian.ugly +++ b/config/alert-tracks-debian.ugly @@ -19,6 +19,8 @@ DUSER=!!(*= $user *)!!  trap "" 1 +export PIDFILE +  case "$1" in    start)      echo -n "Starting WhatDoTheyKnow alert daemon: $NAME" diff --git a/script/alert-tracks-daemon b/script/alert-tracks-daemon index 7d3c2e4b5..9064eaa05 100755 --- a/script/alert-tracks-daemon +++ b/script/alert-tracks-daemon @@ -1,6 +1,6 @@ -#!/bin/bash +#!/bin/sh  LOC=`dirname $0` -"$LOC/runner" 'TrackMailer.alert_tracks_loop' +"$LOC/runner" --daemon TrackMailer.alert_tracks_loop 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 | 
