#!/bin/bash # # spamass-milter-wrapper - wrapper script for spamass-milter # # This script backgrounds itself and then runs spamass-milter in a loop. # If the daemon exits then the script restarts it automatically. # wrapper_dir=$(dirname "$0") daemon=spamass-milter ( while : do # start the daemon in the foreground $wrapper_dir/$daemon "$@" milter_status=$? milter_date=$(date) # exit if we're shutting down [ -f /etc/nologin ] && exit sleep 1 # exit if we're deliberately stopped [ ! -f /var/lock/subsys/spamass-milter ] && exit # otherwise, send a notification about the daemon crash # and then restart sleep 9 ( echo "$daemon exited at $milter_date with status $milter_status" echo "You may wish to check /var/log/messages and/or /var/log/maillog" ) | mail -s "$daemon on `hostname` restarted" root done ) >& /dev/null & disown -ar