diff options
-rw-r--r-- | config/alert-tracks-debian.ugly | 53 | ||||
-rw-r--r-- | config/crontab.ugly | 2 | ||||
-rwxr-xr-x | script/runner | 46 |
3 files changed, 69 insertions, 32 deletions
diff --git a/config/alert-tracks-debian.ugly b/config/alert-tracks-debian.ugly index 6dfa811a4..3263002a1 100644 --- a/config/alert-tracks-debian.ugly +++ b/config/alert-tracks-debian.ugly @@ -13,33 +13,58 @@ # !!(*= $daemon_name *)!! Start the WhatDoTheyKnow email alert daemon NAME=!!(*= $daemon_name *)!! -DAEMON=/data/vhost/!!(*= $vhost *)!!/alaveteli/script/alert-tracks-daemon +DAEMON=/data/vhost/!!(*= $vhost *)!!/alaveteli/script/runner +DAEMON_ARGS="--daemon TrackMailer.alert_tracks_loop" PIDFILE=/data/vhost/!!(*= $vhost *)!!/alert-tracks.pid +LOGFILE=/data/vhost/!!(*= $vhost *)!!/logs/alert-tracks.log DUSER=!!(*= $user *)!! trap "" 1 export PIDFILE +quietly_start_daemon() { + start-stop-daemon --quiet --start --pidfile "$PIDFILE" --chuid "$DUSER" --startas "$DAEMON" -- $DAEMON_ARGS +} + +start_daemon() { + start-stop-daemon --start --pidfile "$PIDFILE" --chuid "$DUSER" --startas "$DAEMON" -- $DAEMON_ARGS \ + > "$LOGFILE" 2>&1 +} + +stop_daemon() { + start-stop-daemon --stop --pidfile "$PIDFILE" +} + +restart() { stop; start; } + case "$1" in + check) + quietly_start_daemon + if [ $? -ne 1 ] + then + echo "WhatDoTheyKnow alert daemon was not running; restarting now" + fi + ;; + start) - echo -n "Starting WhatDoTheyKnow alert daemon: $NAME" - start-stop-daemon --start --pidfile $PIDFILE --chuid $DUSER --exec $DAEMON > /dev/null - ;; - + echo -n "Starting WhatDoTheyKnow alert daemon: $NAME" + start_daemon + ;; + stop) - echo -n "Stopping WhatDoTheyKnow alert daemon: $NAME" - start-stop-daemon --stop --pidfile $PIDFILE --oknodo - ;; - + echo -n "Stopping WhatDoTheyKnow alert daemon: $NAME" + stop_daemon + ;; + restart) - echo -n "Restarting WhatDoTheyKnow alert daemon: $NAME" - start-stop-daemon --stop --pidfile $PIDFILE --oknodo - start-stop-daemon --start --pidfile $PIDFILE --chuid $DUSER --exec $DAEMON > /dev/null - ;; + echo -n "Restarting WhatDoTheyKnow alert daemon: $NAME" + stop_daemon + start_daemon + ;; *) - echo "Usage: /etc/init.d/$NAME {start|stop|restart}" + echo "Usage: /etc/init.d/$NAME {start|stop|restart|check}" exit 1 ;; esac diff --git a/config/crontab.ugly b/config/crontab.ugly index 9193899af..d67eec769 100644 --- a/config/crontab.ugly +++ b/config/crontab.ugly @@ -12,7 +12,7 @@ MAILTO=cron-!!(*= $site *)!!@mysociety.org # Every 5 minutes */5 * * * * !!(*= $user *)!! run-with-lockfile -n /data/vhost/!!(*= $vhost *)!!/update-xapian-index.lock /data/vhost/!!(*= $vhost *)!!/!!(*= $vcspath *)!!/script/update-xapian-index || echo "stalled?" # # Every 10 minutes -# 5,15,25,35,45,55 * * * * !!(*= $user *)!! run-with-lockfile -n /data/vhost/!!(*= $vhost *)!!/alert-tracks.lock /data/vhost/!!(*= $vhost *)!!/!!(*= $vcspath *)!!/script/alert-tracks || echo "stalled?" +5,15,25,35,45,55 * * * * !!(*= $user *)!! /etc/init.d/foi-alert-tracks check # Once an hour 39 * * * * !!(*= $user *)!! run-with-lockfile -n /data/vhost/!!(*= $vhost *)!!/alert-overdue-requests.lock /data/vhost/!!(*= $vhost *)!!/!!(*= $vcspath *)!!/script/alert-overdue-requests || echo "stalled?" 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 |