[systemd-devel] lighttp unit - graceful reload of configfiles by sending signal to $MAINPID

Alexander E. Patrakov patrakov at gmail.com
Tue Jan 11 02:51:49 PST 2011


10.01.2011 22:49, Marius Tolzmann wrote:
>
> hi..
>
> can the initial problem of restarting the lighttpd gracefully be 
> solved by something like this?:
> Restart=on-success ( or on-abort or always .. don't know what the
> exit-status after graceful kill is in lighty)

After more research, I found the under-documented lighttpd-angel 
program. It does what is needed for babysitting lighttpd: performs the 
"send SIGINT to the old copy and immediately start the new one" dance 
when it receives SIGHUP. See 
http://blog.lighttpd.net/articles/2007/09/02/there-is-an-angel-for-lighty . 
So here is a working unit file for lighttpd, with graceful reloading:

==========
[Unit]
Description=Lighttpd Web Server
After=network.target

[Service]
ExecStart=/usr/sbin/lighttpd-angel -f /etc/lighttpd/lighttpd.conf -D
ExecReload=/bin/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target
WantedBy=http-daemon.target
==========

While this works, it looks somehow ugly because of a special 
"lighttpd-angel" program that only launches and restarts lighttpd (i.e., 
performs a job that is IMHO more suited for systemd) - but well, 
lighttpd's requirements are special. Here is what it looks like normally:

home ~ # systemctl status lighttpd.service
lighttpd.service - Lighttpd Web Server
Loaded: loaded (/etc/systemd/system/lighttpd.service)
Active: active (running) since Tue, 11 Jan 2011 15:46:50 +0500; 1s ago
Main PID: 12659 (lighttpd-angel)
CGroup: name=systemd:/system/lighttpd.service
├ 12659 /usr/sbin/lighttpd-angel -f /etc/lighttpd/lighttpd.conf -D
└ 12660 /usr/sbin/lighttpd -f /etc/lighttpd/lighttpd.conf -D

Here is what it looks like during graceful restart:

home ~ # systemctl status lighttpd.service
lighttpd.service - Lighttpd Web Server
Loaded: loaded (/etc/systemd/system/lighttpd.service)
Active: active (running) since Tue, 11 Jan 2011 15:46:50 +0500; 58s ago
Process: 12670 (/bin/kill -HUP $MAINPID, code=exited, status=0/SUCCESS)
Main PID: 12659 (lighttpd-angel)
CGroup: name=systemd:/system/lighttpd.service
├ 12659 /usr/sbin/lighttpd-angel -f /etc/lighttpd/lighttpd.conf -D
├ 12660 /usr/sbin/lighttpd -f /etc/lighttpd/lighttpd.conf -D
└ 12671 /usr/sbin/lighttpd -f /etc/lighttpd/lighttpd.conf -D

And here is the final status when the long transfer which kept PID 12660 
busy is finished:

home ~ # systemctl status lighttpd.service
lighttpd.service - Lighttpd Web Server
Loaded: loaded (/etc/systemd/system/lighttpd.service)
Active: active (running) since Tue, 11 Jan 2011 15:46:50 +0500; 1min 41s ago
Process: 12670 (/bin/kill -HUP $MAINPID, code=exited, status=0/SUCCESS)
Main PID: 12659 (lighttpd-angel)
CGroup: name=systemd:/system/lighttpd.service
├ 12659 /usr/sbin/lighttpd-angel -f /etc/lighttpd/lighttpd.conf -D
└ 12671 /usr/sbin/lighttpd -f /etc/lighttpd/lighttpd.conf -D

If you also want graceful stop, you may want to add:

ExecStop=/bin/kill -INT $MAINPID

but this doesn't work, as lighttpd gets killed immediately. I don't know 
why this happens.

Also, the "test config before reloading" feature still doesn't work 
right. If I add this ExecReload line before the existing one:

ExecReload=/usr/sbin/lighttpd -t -f /etc/lighttpd/lighttpd.conf

then systemd will kill lighttpd-angel when the configuration file is 
bad. It should instead complain to syslog and do nothing with the 
running instances of lighttpd and lighttpd-angel.

-- 
Alexander E. Patrakov


More information about the systemd-devel mailing list