3 # nginx Nginx Web Server (@type@ version)
6 # description: Nginx is an HTTP(S) server, HTTP(S) reverse \
7 # proxy and IMAP/POP3 proxy server
9 # pidfile: /var/run/nginx.pid
10 # config: /etc/nginx/nginx.conf
12 # Source function library
13 . /etc/rc.d/init.d/functions
15 # Source networking configuration.
16 . /etc/sysconfig/network
18 nginx="/usr/sbin/nginx"
22 sysconfig="/etc/sysconfig/$prog"
23 lockfile="/var/lock/subsys/$prog"
24 pidfile="/var/run/$prog.pid"
26 NGINX_CONF_FILE="/etc/nginx/$prog.conf"
29 [ -f $sysconfig ] && . $sysconfig
31 # Check that networking is up.
32 if is_yes "${NETWORKING}"; then
33 if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then
34 msg_network_down "$svname"
42 # must return non-zero if check failed
43 # output is discarded if checkconfig is ran without details
45 $nginx -t -c $NGINX_CONF_FILE
48 # wrapper for configtest
52 if [ $details = 1 ]; then
53 # run config test and display report (status action)
54 show "Checking %s configuration" "$svname"; busy
56 out=$(configtest 2>&1)
58 if [ $RETVAL = 0 ]; then
63 [ "$out" ] && echo >&2 "$out"
65 # run config test and abort with nice message if failed
66 # (for actions checking status before action).
67 configtest >/dev/null 2>&1
69 if [ $RETVAL != 0 ]; then
70 show "Checking %s configuration" "$svname"; fail
71 nls 'Configuration test failed. See details with %s "checkconfig"' $0
78 # Check if the service is already running?
79 if [ ! -f $lockfile ]; then
81 msg_starting "$svname"
82 daemon $nginx -c $NGINX_CONF_FILE
84 [ $RETVAL -eq 0 ] && touch $lockfile
86 msg_already_running "$svname"
91 local oldbin_pidfile="${pidfile}.oldbin"
94 if [ -f $lockfile ]; then
95 if [ -f $oldbin_pidfile ] && [ -f $pidfile ]; then
96 msg_stopping "$svname (old process)"
97 killproc -p $oldbin_pidfile $prog -TERM
99 msg_stopping "$svname"
100 killproc -p $pidfile $prog
102 rm -f $lockfile $pidfile >/dev/null 2>&1
104 msg_not_running "$svname"
109 if [ -f $lockfile ]; then
111 msg_reloading "$svname"
112 killproc -p $pidfile $prog -HUP
115 msg_not_running "$svname"
121 if [ ! -f $lockfile ]; then
122 msg_not_running "$svname"
132 # Upgrade the binary with no downtime.
133 # http://nginx.org/en/docs/control.html#upgrade
134 # TODO: handle revert back on failed upgrade
136 local oldbin_pidfile="${pidfile}.oldbin" retry
139 show "Upgrading $svname"
140 killproc -p $pidfile $prog -USR2
145 while [ $retry -gt 0 ]; do
146 if [ -f $oldbin_pidfile ] && [ -f $pidfile ]; then
147 show "Upgrade: stopping old process"
148 killproc -p $oldbin_pidfile $prog -QUIT
156 show "Upgrade: stopping old process"; fail
157 nls 'old process pid file was not found'
161 # Tell nginx to reopen logs
162 # http://nginx.org/en/docs/control.html#logs
164 local oldbin_pidfile="${pidfile}.oldbin"
166 if [ -f $oldbin_pidfile ]; then
167 show "Reopening $svname (oldbin) logs"
168 killproc -p $oldbin_pidfile $prog -USR1
171 show "Reopening $svname logs"
172 killproc -p $pidfile $prog -USR1
176 # See how we were called.
195 force-reload|upgrade)
201 checkconfig|configtest)
205 status --pidfile $pidfile $prog
209 msg_usage "$0 {start|stop|restart|try-restart|reload|force-reload|graceful|reopen-logs|checkconfig|status}"