]> git.pld-linux.org Git - packages/nginx.git/blobdiff - nginx.init
- rebuild with perl 5.30.0
[packages/nginx.git] / nginx.init
index ad6d1dcc8ddba74a29c6c8cfcdbbaa85cbdd6a64..1d62b97a8577ea655521e4496666881d7440489d 100755 (executable)
@@ -1,13 +1,13 @@
 #!/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
+# pidfile:     /var/run/nginx.pid
+# config:      /etc/nginx/nginx.conf
 
 # Source function library
 . /etc/rc.d/init.d/functions
@@ -15,8 +15,8 @@
 # Source networking configuration.
 . /etc/sysconfig/network
 
-nginx="/usr/sbin/nginx-@flavor@"
-svname="nginx (@flavor@)"
+nginx="/usr/sbin/nginx"
+svname="nginx"
 prog=${nginx##*/}
 
 sysconfig="/etc/sysconfig/$prog"
@@ -88,8 +88,14 @@ start() {
 }
 
 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=$?
@@ -123,6 +129,49 @@ condrestart() {
        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" retry
+
+       checkconfig
+       show "Upgrading $svname"
+       killproc -p $pidfile $prog -USR2
+       RETVAL=$?
+
+       # 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
+}
+
 RETVAL=0
 # See how we were called.
 case "$1" in
@@ -140,9 +189,15 @@ 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
        ;;
@@ -151,7 +206,7 @@ case "$1" in
        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
This page took 0.059725 seconds and 4 git commands to generate.