]> git.pld-linux.org Git - packages/nginx.git/blame - nginx.init
init: use pidfiles
[packages/nginx.git] / nginx.init
CommitLineData
9d23b01f 1#!/bin/sh
2#
2cb3d9b2 3# nginx Nginx Web Server (@flavor@ version)
9d23b01f 4#
5# chkconfig: 345 85 15
e081a5bc
ER
6# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
7# proxy and IMAP/POP3 proxy server
2cb3d9b2
ER
8# processname: nginx-@flavor@
9# pidfile: /var/run/nginx-@flavor@.pid
10# config: /etc/nginx/nginx-@flavor@.conf
9d23b01f 11
9d23b01f 12# Source function library
13. /etc/rc.d/init.d/functions
14
e081a5bc 15# Source networking configuration.
9d23b01f 16. /etc/sysconfig/network
17
e081a5bc
ER
18nginx="/usr/sbin/nginx-@flavor@"
19svname="nginx (@flavor@)"
20prog=${nginx##*/}
21
22sysconfig="/etc/sysconfig/$prog"
23lockfile="/var/lock/subsys/$prog"
24pidfile="/var/run/$prog.pid"
25
26NGINX_CONF_FILE="/etc/nginx/$prog.conf"
27
9d23b01f 28# Get service config
e081a5bc 29[ -f $sysconfig ] && . $sysconfig
9d23b01f 30
31# Check that networking is up.
32if is_yes "${NETWORKING}"; then
33 if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then
e081a5bc 34 msg_network_down "$svname"
9d23b01f 35 exit 1
36 fi
37else
38 exit 0
39fi
40
ab8302f0
ER
41# configtest itself
42# must return non-zero if check failed
43# output is discarded if checkconfig is ran without details
44configtest() {
45 $nginx -t -c $NGINX_CONF_FILE
46}
47
48# wrapper for configtest
49checkconfig() {
50 local details=${1:-0}
51
52 if [ $details = 1 ]; then
53 # run config test and display report (status action)
54 show "Checking %s configuration" "$svname"; busy
55 local out
56 out=$(configtest 2>&1)
57 RETVAL=$?
58 if [ $RETVAL = 0 ]; then
59 ok
60 else
61 fail
62 fi
63 [ "$out" ] && echo >&2 "$out"
64 else
65 # run config test and abort with nice message if failed
66 # (for actions checking status before action).
67 configtest >/dev/null 2>&1
68 RETVAL=$?
69 if [ $RETVAL != 0 ]; then
70 show "Checking %s configuration" "$svname"; fail
71 nls 'Configuration test failed. See details with %s "checkconfig"' $0
72 exit $RETVAL
73 fi
74 fi
75}
76
9d23b01f 77start() {
78 # Check if the service is already running?
e081a5bc 79 if [ ! -f $lockfile ]; then
ab8302f0 80 checkconfig
e081a5bc
ER
81 msg_starting "$svname"
82 daemon $nginx -c $NGINX_CONF_FILE
9d23b01f 83 RETVAL=$?
e081a5bc 84 [ $RETVAL -eq 0 ] && touch $lockfile
9d23b01f 85 else
e081a5bc 86 msg_already_running "$svname"
9d23b01f 87 fi
88}
89
90stop() {
91 # Stop daemons.
e081a5bc
ER
92 if [ -f $lockfile ]; then
93 msg_stopping "$svname"
65840609
ER
94 killproc -p $pidfile $prog
95 RETVAL=$?
ff4955e8 96 rm -f $lockfile $pidfile >/dev/null 2>&1
9d23b01f 97 else
e081a5bc 98 msg_not_running "$svname"
9d23b01f 99 fi
100}
101
149be10d
ER
102reload() {
103 if [ -f $lockfile ]; then
ab8302f0 104 checkconfig
149be10d 105 msg_reloading "$svname"
65840609 106 killproc -p $pidfile $prog -HUP
149be10d
ER
107 RETVAL=$?
108 else
109 msg_not_running "$svname"
110 RETVAL=7
111 fi
112}
113
114condrestart() {
115 if [ ! -f $lockfile ]; then
116 msg_not_running "$svname"
117 RETVAL=$1
118 return
119 fi
120
ab8302f0 121 checkconfig
149be10d
ER
122 stop
123 start
124}
125
9d23b01f 126RETVAL=0
127# See how we were called.
128case "$1" in
129 start)
149be10d 130 start
9d23b01f 131 ;;
132 stop)
149be10d 133 stop
9d23b01f 134 ;;
135 restart)
ab8302f0 136 checkconfig
9d23b01f 137 stop
138 start
139 ;;
149be10d
ER
140 try-restart)
141 condrestart 0
142 ;;
9d23b01f 143 reload|force-reload|graceful)
149be10d
ER
144 reload
145 ;;
ab8302f0
ER
146 checkconfig|configtest)
147 checkconfig 1
148 ;;
149be10d 149 status)
65840609 150 status --pidfile $pidfile $prog
149be10d 151 RETVAL=$?
9d23b01f 152 ;;
153 *)
ab8302f0 154 msg_usage "$0 {start|stop|restart|try-restart|reload|force-reload|graceful|checkconfig|status}"
9d23b01f 155 exit 3
156 ;;
157esac
158
159exit $RETVAL
This page took 0.092245 seconds and 4 git commands to generate.