[systemd-devel] lighttp unit - graceful reload of configfiles by sending signal to $MAINPID
Alexander E. Patrakov
patrakov at gmail.com
Mon Jan 10 20:54:16 PST 2011
10.01.2011 22:49, Marius Tolzmann wrote:
>
> hi..
>
>> [Unit]
>> Description=Lighttpd Web Server
>> After=network.target
>>
>> [Service]
>> Type=forking
>> EnvironmentFile=/etc/conf.d/lighttpd
>> PIDFile=/var/run/lighttpd.pid
>> ExecStartPre=/usr/sbin/lighttpd -t -f /etc/lighttpd/lighttpd.conf
>> ExecStart=/usr/sbin/lighttpd -f /etc/lighttpd/lighttpd.conf
>> ExecStop=/bin/kill -INT $MAINPID
>> ExecReload=/usr/sbin/lighttpd -t -f /etc/lighttpd/lighttpd.conf
>> ExecReload=/bin/kill -INT $MAINPID
>> ExecReload=/bin/sleep 1
>> ExecReload=/usr/sbin/lighttpd -f /etc/lighttpd/lighttpd.conf
>> StandardOutput=syslog
>> StandardError=syslog
>
> i still try to get behind all the systemd magic so i have some
> questions on this unit:
>
> can the initial problem of restarting the lighttpd gracefully be
> solved by something like this?:
>
> [Unit]
> ..
> ConditionPathExists=/etc/lighttpd/lighttpd.conf
>
> [Service]
> ExecStartPre=/usr/sbin/lighttpd -t ...
> ExecStart=/usr/sbin/lighttpd ...
> ExecStop=/bin/kill -INT $MAINPID
> ExecReload=/usr/sbin/lighttpd -t ...
> ExecReload=/bin/kill -INT $MAINPID
> StandardOutput=syslog
> Restart=on-success ( or on-abort or always .. don't know what the
> exit-status after graceful kill is in lighty)
No, the Restart logic in systemd is not right for lighttpd (or rather:
the logic required by lighttpd is insane). Systemd will start a new
instance of lighttpd as soon as the main PID (i.e., in the default setup
with server.max-worker = 1, the only PID) of the old instance exits,
which is too late. I want the old and the new instances of lighttpd to
coexist for some time. See: after SIGINT, the old instance does not
listen on port 80, but continues servicing large downloads that are
still in progress. The new instance accepts new connections and handles
them. The old instance will exit as soon as all old transfers ard completed.
>
> and why do you explicitly not use the -D option and let systemd do all
> the forking stuff for you..? you could get rid off the Type= PIDFile=
> lines..
This would indeed work if I didn't need the funky graceful restart logic.
> i also removed StandardError=syslog which seems to be redundant here..
OK. If you want to see what went into Gentoo systemd overlay, look here:
http://git.overlays.gentoo.org/gitweb/?p=user/systemd.git;a=commitdiff;h=d34961cf8be3743013d026c21ca64078ad0f1255
. Essentially, I gave up, but documented the effort.
> SignalStop=SIGINT and SignalReload=SIGINT or something similar may be
> a nice shortcut for doing those kind of things.. Since
> SignalReload=SIGHUP seems to be a way how it is done most of the time?
Yes, this would be a good shortcut.
>
> Another question: Doesn't the default KillMode=control-group would
> send a SIGTERM to the remaining processes of this service immediately
> after the ExecStop= returns and so break the idea behind a graceful
> shutdown where the main-process exits and all running http-requests
> will be finished? (Or is there also a delay of TimeoutSec= between
> ExecStop= and the first SIGTERM?)
The documentation (man systemd.service, search for TimeoutSec) says it
waits.
Anyway, lighttpd is very easy to set up, the default config works fine
for static files, and the only possible trouble is avoided by commenting
out the server.use-ipv6 = "enable" line, so you may want to play with it
yourself. To experiment with graceful restarts, you can put some music
in the document root and attempt to download it with wget -O /dev/null
--limit-rate=20k http://127.0.0.1/file.mp3 while restarting lighttpd.
--
Alexander E. Patrakov
More information about the systemd-devel
mailing list