systemd and nginx custom script

Jamie Nguyen jamie at
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
Description=A high performance web server and reverse proxy server

ExecStartPre=/usr/sbin/nginx -t
ExecReload=/usr/sbin/nginx -s reload
ExecStop=/usr/sbin/nginx -s quit


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 (Perhaps you
might even consider including this script (or something similar) in
the nginx tarball as it would be helpful for systems using systemd.)

[ ! -f /run/ ] && exit 1
echo "Start new nginx master..."
/bin/systemctl kill --signal=USR2 nginx.service
sleep 5
[ ! -f /run/ ] && sleep 5
if [ ! -f /run/ ]; then
	echo "Failed to start new nginx master."
	exit 1
echo "Stop old nginx master gracefully..."
oldpid=`cat /run/ 2>/dev/null`
/bin/kill -s QUIT $oldpid 2>/dev/null

Kind regards,

More information about the nginx-devel mailing list