File nginx.init of Package nginx (Revision fda17218f58e35383c70142f2c049a5f)
Currently displaying revision fda17218f58e35383c70142f2c049a5f, show latest
x
1
#!/bin/sh
2
#
3
# nginx - this script starts and stops the nginx daemon
4
#
5
# chkconfig: - 85 15
6
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
7
# proxy and IMAP/POP3 proxy server
8
# processname: nginx
9
# config: /etc/nginx/nginx.conf
10
# config: /etc/sysconfig/nginx
11
# pidfile: /var/run/nginx.pid
12
13
# Source function library.
14
. /etc/rc.d/init.d/functions
15
16
# Source networking configuration.
17
. /etc/sysconfig/network
18
19
# Check that networking is up.
20
[ "$NETWORKING" = "no" ] && exit 0
21
22
nginx="/usr/sbin/nginx"
23
prog=$(basename $nginx)
24
25
NGINX_CONF_FILE="/etc/nginx/nginx.conf"
26
27
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
28
29
lockfile=/var/lock/subsys/nginx
30
31
start() {
32
[ -x $nginx ] || exit 5
33
[ -f $NGINX_CONF_FILE ] || exit 6
34
echo -n $"Starting $prog: "
35
daemon $nginx -c $NGINX_CONF_FILE
36
retval=$?
37
echo
38
[ $retval -eq 0 ] && touch $lockfile
39
return $retval
40
}
41
42
stop() {
43
echo -n $"Stopping $prog: "
44
killproc $prog
45
retval=$?
46
echo
47
[ $retval -eq 0 ] && rm -f $lockfile
48
return $retval
49
}
50
51
restart() {
52
configtest_q || configtest || return 6
53
stop
54
start
55
}
56
57
reload() {
58
configtest_q || configtest || return 6
59
echo -n $"Reloading $prog: "
60
killproc $nginx -HUP
61
echo
62
}
63
64
configtest() {
65
$nginx -t -c $NGINX_CONF_FILE
66
}
67
68
configtest_q() {
69
configtest >/dev/null 2>&1
70
}
71
72
rh_status() {
73
status $prog
74
}
75
76
rh_status_q() {
77
rh_status >/dev/null 2>&1
78
}
79
80
# Online upgrade nginx binary on the fly, with no downtime.
81
# details: http://sysoev.ru/nginx/docs/control.html#upgrade
82
upgrade() {
83
configtest_q || configtest || return 6
84
echo -n $"Upgrading $prog: "
85
kill -USR2 `cat /var/run/$prog.pid`
86
sleep 1
87
if test -f /var/run/$prog.pid.oldbin
88
then
89
killproc -p /var/run/$prog.pid.oldbin -QUIT
90
echo
91
else
92
failure $"$prog online upgrade"
93
echo
94
exit 1
95
fi
96
}
97
98
case "$1" in
99
start)
100
rh_status_q && exit 0
101
$1
102
;;
103
stop)
104
rh_status_q || exit 0
105
$1
106
;;
107
reload)
108
rh_status_q || exit 7
109
$1
110
;;
111
upgrade|force-reload)
112
rh_status_q || exit 7
113
upgrade
114
;;
115
condrestart|try-restart)
116
rh_status_q || exit 7
117
restart
118
;;
119
restart|configtest)
120
$1
121
;;
122
status|status_q)
123
rh_$1
124
;;
125
*)
126
echo $"Usage: $0 {start|stop|reload|force-reload|restart|try-restart|status|configtest}"
127
exit 2
128
esac
129
130