[PATCH] Write pid-file in httpd

Ralf Friedl Ralf.Friedl at online.de
Mon Jul 21 08:29:00 UTC 2008


Denys Vlasenko wrote:
> On Friday 18 July 2008 16:24, Ralf Friedl wrote:
>   
>> This is a patch to create a pid-file when httpd is started.
>> A pid-file is useful to stop httpd or to send SIGHUP to reload the config.
>> The filename is passed as a parameter so that multiple instances can run 
>> at the same time, with different pid-files.
>>
>> It would also be possible to make this configurable.
>>     
> I was sitting on it for some time. You know, I am not a big fan
> of pid files. I am a fan of djb's style of doing things,
> when filesystem is used as a fairly natural mapping to the
> set(s) of running processes. I am talking about runsv/runsvdir
> applets. Look at this gem:
>
> SIGNALS
>     Syslogd reacts to a set of signals. You may easily send
>     a signal to syslogd using the following:
>         kill -SIGNAL `cat /var/run/syslogd.pid`
>
> Ok, I am not going to lecture everyone on "runsv way".
> But for god's sake, use "killall -SIGNAL syslogd" or, if your system
> has no killall (highly unlikely), "kill -SIGNAL `pidof syslogd`".
> This should work, right? And unlike pidfile, killall is immune to
> "stale pidfile" and "somehow two syslogd's were started, what now?!"
> problems.
>
> I remember that you propose having pifile's name specified as a param,
> which makes pidfile not as rediculous at /var/run/syslogd.pid.
>   
As I already mentioned, I want to run multiple instances of httpd at the 
same time with different configurations, so the approach with "killall" 
of "pidof" is not appropriate. Sending SUGHUP to all is possible, 
although not desirable, but with SIGTERM it is important to send it only 
to the right process.
> But still, would this work as well?
>
> #!/bin/sh
> echo $$ >pidfile
> exec httpd "$@"
>   
Using a wrapper Script should be possible, but it would probably need 
more bytes that creating the pid-file in httpd itself.
Also it would be necessary to run httpd in foreground mode, and the 
possibility of different pid-files. Something like this might work:

#!/bin/sh
echo $$ > "$1"
shift
exec httpd -f "$@"

Regards
Ralf Friedl



More information about the busybox mailing list