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