#!/bin/sh
#
-# nginx Nginx Web Server (@flavor@ version)
+# nginx Nginx Web Server (@type@ version)
#
# chkconfig: 345 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
-# processname: nginx-@flavor@
-# pidfile: /var/run/nginx-@flavor@.pid
-# config: /etc/nginx/nginx-@flavor@.conf
+# processname: nginx-@type@
+# pidfile: /var/run/nginx-@type@.pid
+# config: /etc/nginx/nginx-@type@.conf
# Source function library
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
-nginx="/usr/sbin/nginx-@flavor@"
-svname="nginx (@flavor@)"
+nginx="/usr/sbin/nginx-@type@"
+svname="nginx (@type@)"
prog=${nginx##*/}
sysconfig="/etc/sysconfig/$prog"
# Stop daemons.
if [ -f $lockfile ]; then
msg_stopping "$svname"
- killproc $prog
+ killproc -p $pidfile $prog
+ RETVAL=$?
rm -f $lockfile $pidfile >/dev/null 2>&1
else
msg_not_running "$svname"
if [ -f $lockfile ]; then
checkconfig
msg_reloading "$svname"
- killproc $prog -HUP
+ killproc -p $pidfile $prog -HUP
RETVAL=$?
else
msg_not_running "$svname"
start
}
+# Upgrade the binary with no downtime.
+# http://nginx.org/en/docs/control.html#upgrade
+# TODO: handle revert back on failed upgrade
+upgrade() {
+ local oldbin_pidfile="${pidfile}.oldbin"
+
+ checkconfig
+ show "Upgrading $svname"
+ killproc -p $pidfile $prog -USR2
+ RETVAL=$?
+ sleep 1
+ if [ -f $oldbin_pidfile ] && [ -f $pidfile ]; then
+ show "Upgrade: stopping old process"
+ killproc -p $oldbin_pidfile $prog -QUIT
+ return 0
+ else
+ return 1
+ fi
+}
+
+# Tell nginx to reopen logs
+# http://nginx.org/en/docs/control.html#logs
+reopen_logs() {
+ show "Reopening $svname logs"
+ killproc -p $pidfile $prog -USR1
+}
+
RETVAL=0
# See how we were called.
case "$1" in
try-restart)
condrestart 0
;;
- reload|force-reload|graceful)
+ reload|graceful)
reload
;;
+ force-reload|upgrade)
+ upgrade
+ ;;
+ reopen-logs)
+ reopen_logs
+ ;;
checkconfig|configtest)
checkconfig 1
;;
status)
- status $prog
+ status --pidfile $pidfile $prog
RETVAL=$?
;;
*)
- msg_usage "$0 {start|stop|restart|try-restart|reload|force-reload|graceful|checkconfig|status}"
+ msg_usage "$0 {start|stop|restart|try-restart|reload|force-reload|graceful|reopen-logs|checkconfig|status}"
exit 3
;;
esac