[Mimedefang] Re: OT: Sendmail Startup Script Question
Ashley M. Kirchner
ashley at pcraft.com
Thu Dec 19 11:51:01 EST 2002
John Rowan Littell wrote:
>Note that on RedHat 7.3, it looks to me like the daemon() function in
>startup scripts (/etc/rc.d/init.d/functions) will normally refuse to
>start two instances of a program. The reason Ashley's script works,
>it appears, is because sendmail doesn't have the privs to write a
>/var/run/sendmail.pid file, so the second daemon() call for sendmail
>succeeds -- daemon() checks to see if the process is running only by
>looking for /var/run/${base}.pid and not by using pidof (like
>killproc() does).
>
>
Hmm, yes and no. The daemon() function will check for $base.pid,
where $base is the program being started, and in this case it's
'sendmail'. A stock RH machine will create the sendmail.pid file,
which will make your statement true - if upon calling daemon() again, it
finds that pid file, it will refuse to start a second instance of
sendmail. On that same token, when shutting down, /var/run/sendmail.pid
only contains one pid, for one process, so it never kills both the MTA
as well as the MSP.
In my case, I don't let it create a 'sendmail.pid' file, instead I
create an sm-mta.pid file (specified in my sendmail.cf). Consequently,
if I wanted to call daemon() more than once, I can, but then I would
still be faced with the problem of the pid file only containing one pid.
Once again, I specify a separate pid file for the MSP process. But
wait, the smmsp user doesn't have enough privileges to write to
/var/run/ so it would fail to write it's own pid file. Scripting to the
rescue - I manually touch that sm-msp.pid file, and chown it to
smmsp.smmsp just prior to starting up the queue process. This way it
can write to it one it starts up. Now I have full control over both
processes, I have two separate pid files, and I can kill them both
without any problem..
Now, when stopping the service, if you notice, I only call
killproc() once. That's because the initial test for the $base.pid
fails (after al, it's expecting sendmail.pid - which doesn't exist). So
it continues on to the next step, which is checking actual processes:
pidof -o $$ -o $PPID -o %PPID -x ${base}
This piece (in /etc/init.d/functions) will find both running pids
for sendmail and will successfully kill both processes for me, without
having to call killproc() twice.
Hope this helps.
More information about the MIMEDefang
mailing list