Nice reload of config with sendmail
Logan Shaw
lshaw at emitinc.com
Wed Jul 12 20:00:29 IST 2006
On Wed, 12 Jul 2006, Arthur Sherman wrote:
>>> What is the less disturbing way to reload the MS/Sendmail config on a
>>> server?
James wrote:
>> Personally, I just HUP the MS parent[1] (which kills all the
>> kids before
>> spawning a new brood of rug-rats) and "killall -HUP sendmail". I put
>> all that in a bash script and dumped it in /root/bin/mail-reload.sh
> Could you post it here?
> I would like to see it.
I find the easiest way to go in search of pids like this is to
use the formatting capabilities that "ps" has on many versions
of Unix, combined with awk. For example, on Linux:
ps -e -o pid,ppid,comm |
awk '$3 == "MailScanner" && $2 == 1 { print $1 }'
That prints pid, parent pid, and command only as output from
"ps". Then awk checks for processes whose name is "MailScanner"
and whose parent is "1" (the init process). That should be
the master MailScanner process. From there, it's just a matter
of killing that one pid:
kill `ps -e -o pid,ppid,comm |
awk '$3 == "MailScanner" && $2 == 1 { print $1 }'`
Or the more elaborate and verbose version:
ps -e -o pid,ppid,comm |
awk '$3 == "MailScanner" && $2 == 1 { print $1 }' |
while read pid
do
echo "Killing this process:"
ps -f -p "$pid"
kill "$pid"
done
Or the more elaborate and verbose and paranoid version:
ps -e -o pid,ppid,comm |
awk '$3 == "MailScanner" && $2 == 1 { print $1 }' |
while read pid
do
echo "Kill this process?"
ps -f -p "$pid"
# gotta redirect stdin here, else it will come from pipe
read response < /dev/tty
case "$response" in
y|Y)
echo "killing $pid"
kill "$pid"
;;
*)
echo "leaving $pid alone"
;;
esac
done
Of course, your script will want a delay in there to be sure
that MailScanner really has exited. If you want to do the
really obnoxious thing, you could always do this:
#! /bin/sh
get_mailscanner_pid ()
{
ps -e -o pid,ppid,comm |
awk '$3 == "MailScanner" && $2 == 1 { print $1 }'
}
stop_ms ()
{
p=$1
echo "Killing $p."
kill "$p"
echo
echo "Waiting for $p to exit..."
while ps -p "$p"
do
sleep 3
done
echo "$p has exited."
}
start_ms ()
{
echo "Restarting."
/opt/MailScanner/bin/check_mailscanner
}
ms_pid=`get_mailscanner_pid`
stop_ms "$ms_pid"
start_ms "$ms_pid"
By the way, I've always used just "kill" and not "kill -HUP"
with MailScanner and this seems to work fine -- it changes its
argv[0] string to indicate it's gracefully exiting (killing
children -- bwahahaha), so I'm not sure if SIGHUP matters
or not.
- Logan
More information about the MailScanner
mailing list