]> git.pld-linux.org Git - packages/apache.git/blob - apache.init
- add configtest target, consistency
[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 httpd
25                 exit 1
26         fi
27 else
28         exit 0
29 fi
30
31 [ -z "$HTTPD_MPM" ] && HTTPD_MPM="prefork"
32
33 if [ -n "${HTTPD_CONF}" ]; then
34         if [ -d "${HTTPD_CONF}" ] || [ -f "${HTTPD_CONF}" ]; then
35                 CFG="-f ${HTTPD_CONF}"
36         else
37                 echo "error: HTTPD_CONF='$HTTPD_CONF': not a file, not a directory"
38                 exit 1
39         fi
40 fi
41
42 configtest() {
43         /usr/sbin/httpd.${HTTPD_MPM} -t $CFG $HTTPD_OPTS >/dev/null 2>&1
44 }
45
46 start() {
47         # Check if the service is already running?
48         if [ ! -f /var/lock/subsys/httpd ]; then
49                 msg_starting httpd.${HTTPD_MPM}
50                 daemon /usr/sbin/httpd.${HTTPD_MPM} $CFG $HTTPD_OPTS
51                 RETVAL=$?
52                 [ $RETVAL -eq 0 ] && touch /var/lock/subsys/httpd
53         else
54                 msg_already_running httpd.${HTTPD_MPM}
55         fi
56 }
57
58 stop() {
59         # Stop daemons.
60         if [ -f /var/lock/subsys/httpd ]; then
61                 msg_stopping httpd.${HTTPD_MPM}
62                 killproc --pidfile httpd.pid httpd.${HTTPD_MPM}
63                 rm -f /var/lock/subsys/httpd /var/run/httpd.pid /var/run/httpd.loc* >/dev/null 2>&1
64         else
65                 msg_not_running httpd.${HTTPD_MPM}
66         fi
67 }
68
69 condrestart() {
70         if [ -f /var/lock/subsys/httpd ]; then
71                 stop
72                 start
73         else
74                 msg_not_running httpd.${HTTPD_MPM}
75                 RETVAL=$1
76         fi
77 }
78
79 RETVAL=0
80 # See how we were called.
81 case "$1" in
82   start)
83         start
84         ;;
85   stop)
86         stop
87         ;;
88   status)
89         status httpd.${HTTPD_MPM}
90         RETVAL=$?
91         /usr/sbin/httpd.${HTTPD_MPM} $CFG $HTTPD_OPTS -S
92         ;;
93   restart)
94         stop
95         start
96         ;;
97   try-restart)
98         condrestart 0
99         ;;
100   reload|force-reload|graceful)
101         if [ -f /var/lock/subsys/httpd ]; then
102                 configtest
103                 RETVAL=$?
104                 if [ $RETVAL -eq 0 ]; then
105                         msg_reloading httpd.${HTTPD_MPM}
106                         busy
107                         /usr/sbin/httpd.${HTTPD_MPM} $CFG $HTTPD_OPTS -k graceful
108                         RETVAL=$?
109                         [ $RETVAL -eq 0 ] && ok || fail
110                 fi
111         else
112                 msg_not_running httpd.${HTTPD_MPM}
113                 RETVAL=7
114         fi
115         ;;
116   flush-logs)
117         if [ -f /var/lock/subsys/httpd ]; then
118                 msg_reloading httpd.${HTTPD_MPM}
119
120                 configtest
121                 RETVAL=$?
122                 if [ $RETVAL -eq 0 ]; then
123                         /usr/sbin/httpd.${HTTPD_MPM} $CFG -k graceful
124                         RETVAL=$?
125                         [ $RETVAL -eq 0 ] && ok || fail
126                 else
127                         fail
128                         echo >&2 "Configuration file syntax test failed."
129                 fi
130         fi
131         ;;
132   configtest)
133         /usr/sbin/httpd.${HTTPD_MPM} -t $CFG $HTTPD_OPTS
134         ;;
135   *)
136         msg_usage "$0 {start|stop|restart|try-restart|reload|force-reload|graceful|configtest|status}"
137         exit 3
138         ;;
139 esac
140
141 exit $RETVAL
This page took 0.046605 seconds and 4 git commands to generate.