[nginx/f17] Add nginx-upgrade and improve nginx.service
Jamie Nguyen
jamielinux at fedoraproject.org
Wed May 16 21:18:27 UTC 2012
commit 79f3e300779c149eac6793a30ba15b5abe744c9d
Author: Jamie Nguyen <jamie at tomoyolinux.co.uk>
Date: Wed May 16 22:18:06 2012 +0100
Add nginx-upgrade and improve nginx.service
README.fedora | 15 +++++++++++++++
nginx-upgrade | 13 +++++++++++++
nginx.logrotate | 2 +-
nginx.service | 12 +++++++-----
nginx.spec | 21 +++++++++++++++++++--
5 files changed, 55 insertions(+), 8 deletions(-)
---
diff --git a/README.fedora b/README.fedora
new file mode 100644
index 0000000..401b2af
--- /dev/null
+++ b/README.fedora
@@ -0,0 +1,15 @@
+Upgrade without any downtime
+============================
+
+Before migration to systemd, the nginx initscript provided the ability to
+upgrade the running nginx server without any downtime.
+
+This functionality has now been replaced with a downstream shell script,
+located at /usr/bin/nginx-upgrade.
+
+Following an update to nginx via the package manager, running nginx-upgrade
+will cause a new nginx master to be created, which will then take all new
+requests. The old master and workers are then gracefully shutdown without
+breaking any existing connections.
+
+See http://wiki.nginx.org/CommandLine for more information.
diff --git a/nginx-upgrade b/nginx-upgrade
new file mode 100755
index 0000000..4200876
--- /dev/null
+++ b/nginx-upgrade
@@ -0,0 +1,13 @@
+#!/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
diff --git a/nginx.logrotate b/nginx.logrotate
index cf4cdc5..19af788 100644
--- a/nginx.logrotate
+++ b/nginx.logrotate
@@ -6,7 +6,7 @@
compress
sharedscripts
postrotate
- /bin/kill -USR1 $(cat /run/nginx.pid 2>/dev/null) 2>/dev/null || :
+ /bin/systemctl kill --signal=USR1 nginx.service
endscript
}
diff --git a/nginx.service b/nginx.service
index cf6f62f..0a2aac2 100644
--- a/nginx.service
+++ b/nginx.service
@@ -1,13 +1,15 @@
[Unit]
-Description=A high performance web server and reverse proxy server
+Description=The nginx HTTP 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 -c /etc/nginx/nginx.conf
-ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf
-ExecReload=/usr/sbin/nginx -c /etc/nginx/nginx.conf -s reload
-ExecStop=/usr/sbin/nginx -s quit
+ExecStartPre=/usr/sbin/nginx -t
+ExecStart=/usr/sbin/nginx
+ExecReload=/bin/kill -s HUP $MAINPID
+ExecStop=/bin/kill -s QUIT $MAINPID
+PrivateTmp=true
[Install]
WantedBy=multi-user.target
diff --git a/nginx.spec b/nginx.spec
index 61a9724..e2d808a 100644
--- a/nginx.spec
+++ b/nginx.spec
@@ -11,7 +11,7 @@
Name: nginx
Epoch: 1
Version: 1.0.15
-Release: 3%{?dist}
+Release: 4%{?dist}
Summary: A high performance web server and reverse proxy server
Group: System Environment/Daemons
@@ -27,6 +27,8 @@ Source3: nginx.conf
Source4: default.conf
Source5: ssl.conf
Source6: virtual.conf
+Source7: nginx-upgrade
+Source8: README.fedora
Source100: index.html
Source101: poweredby.png
Source102: nginx-logo.png
@@ -66,6 +68,7 @@ memory usage.
%prep
%setup -q
%patch0 -p0
+cp -a %{SOURCE8} .
%build
@@ -144,6 +147,8 @@ install -p -m 0644 %{SOURCE101} %{SOURCE102} \
install -p -m 0644 %{SOURCE103} %{SOURCE104} \
%{buildroot}%{nginx_webroot}
+install -p -D -m 0755 %{SOURCE7} %{buildroot}%{_bindir}/nginx-upgrade
+
%pre
if [ $1 -eq 1 ]; then
@@ -180,8 +185,9 @@ fi
%files
-%doc LICENSE CHANGES README
+%doc LICENSE CHANGES README README.fedora
%{nginx_datadir}/
+%{_bindir}/nginx-upgrade
%{_sbindir}/nginx
%{_mandir}/man3/nginx.3pm.gz
%{_unitdir}/nginx.service
@@ -213,6 +219,17 @@ fi
%changelog
+* Wed May 16 2012 Jamie Nguyen <jamie at tomoyolinux.co.uk> - 1:1.0.15-4
+- add nginx-upgrade to replace functionality from the nginx initscript
+ that was lost after migration to systemd
+- add README.fedora to describe usage of nginx-upgrade
+- nginx.logrotate: use built-in systemd kill command in postrotate script
+- nginx.service: start after syslog.target and network.target
+- nginx.service: remove unnecessary references to config file location
+- nginx.service: use /bin/kill instead of "/usr/sbin/nginx -s" following
+ advice from nginx-devel
+- nginx.service: use private /tmp
+
* Mon May 14 2012 Jamie Nguyen <jamie at tomoyolinux.co.uk> - 1:1.0.15-3
- fix incorrect postrotate script in nginx.logrotate
More information about the scm-commits
mailing list