systemd and nginx custom script
Jamie Nguyen
jamie at tomoyolinux.co.uk
Wed May 16 17:01:47 UTC 2012
Hi, I am co-maintainer for nginx Fedora package. We would like to
upstream our systemd service file. Could you consider including it in
the nginx tarball?
In other projects (e.g. rsyslog, mpd) the service file is only
installed if "--with-systemdsystemunitdir=/usr/lib/systemd/system" was
passed to the configure script. The service file we currently use
should work universally across systems using systemd:
$ cat /lib/systemd/system/nginx.service
[Unit]
Description=A high performance web server and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t
ExecStart=/usr/sbin/nginx
ExecReload=/usr/sbin/nginx -s reload
ExecStop=/usr/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
Most distributions implement a "zero-downtime upgrade" option in their
initscript. This cannot currently be implemented in systemd, so I
implemented it in a separate script. I paste the script below for
possible inclusion in http://wiki.nginx.org/CommandLine (Perhaps you
might even consider including this script (or something similar) in
the nginx tarball as it would be helpful for systems using systemd.)
#!/bin/sh
[ ! -f /run/nginx.pid ] && exit 1
echo "Start new nginx master..."
/bin/systemctl kill --signal=USR2 nginx.service
sleep 5
[ ! -f /run/nginx.pid.oldbin ] && sleep 5
if [ ! -f /run/nginx.pid.oldbin ]; then
echo "Failed to start new nginx master."
exit 1
fi
echo "Stop old nginx master gracefully..."
oldpid=`cat /run/nginx.pid.oldbin 2>/dev/null`
/bin/kill -s QUIT $oldpid 2>/dev/null
Kind regards,
Jamie
More information about the nginx-devel
mailing list