# chkconfig: 345 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
-# processname: nginx-@type@
-# pidfile: /var/run/nginx-@type@.pid
-# config: /etc/nginx/nginx-@type@.conf
+# processname: nginx
+# pidfile: /var/run/nginx.pid
+# config: /etc/nginx/nginx.conf
# Source function library
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
-nginx="/usr/sbin/nginx-@type@"
-svname="nginx (@type@)"
+nginx="/usr/sbin/nginx"
+svname="nginx"
prog=${nginx##*/}
sysconfig="/etc/sysconfig/$prog"
}
stop() {
+ local oldbin_pidfile="${pidfile}.oldbin"
+
# Stop daemons.
if [ -f $lockfile ]; then
+ if [ -f $oldbin_pidfile ] && [ -f $pidfile ]; then
+ msg_stopping "$svname (old process)"
+ killproc -p $oldbin_pidfile $prog -TERM
+ fi
msg_stopping "$svname"
killproc -p $pidfile $prog
RETVAL=$?
# http://nginx.org/en/docs/control.html#upgrade
# TODO: handle revert back on failed upgrade
upgrade() {
- local oldbin_pidfile="${pidfile}.oldbin"
+ local oldbin_pidfile="${pidfile}.oldbin" retry
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
+
+ # wait for 15s
+ retry=60
+ while [ $retry -gt 0 ]; do
+ if [ -f $oldbin_pidfile ] && [ -f $pidfile ]; then
+ show "Upgrade: stopping old process"
+ killproc -p $oldbin_pidfile $prog -QUIT
+ return 0
+ else
+ usleep 250000
+ retry=$(($retry -1))
+ fi
+ done
+
+ show "Upgrade: stopping old process"; fail
+ nls 'old process pid file was not found'
+ return 1
}
# Tell nginx to reopen logs
# http://nginx.org/en/docs/control.html#logs
reopen_logs() {
+ local oldbin_pidfile="${pidfile}.oldbin"
+
+ if [ -f $oldbin_pidfile ]; then
+ show "Reopening $svname (oldbin) logs"
+ killproc -p $oldbin_pidfile $prog -USR1
+ fi
+
show "Reopening $svname logs"
killproc -p $pidfile $prog -USR1
}