Welcome! Log In Create A New Profile

Advanced

systemd and nginx custom script

Jamie Nguyen
May 16, 2012 01:02PM
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

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

systemd and nginx custom script

Jamie Nguyen 1540 May 16, 2012 01:02PM

Re: systemd and nginx custom script

Maxim Dounin 775 May 16, 2012 01:30PM

Re: systemd and nginx custom script

Jamie Nguyen 697 May 16, 2012 04:06PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 123
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready