]> git.pld-linux.org Git - packages/apache.git/blob - apache.init
c6f40f9e5702969c613a708f38c36c74482bf6fa
[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() {
44         /usr/sbin/httpd.${HTTPD_MPM} -t $CFG $HTTPD_OPTS >/dev/null 2>&1
45         RETVAL=$?
46 }
47
48 start() {
49         # Check if the service is already running?
50         if [ ! -f /var/lock/subsys/httpd ]; then
51                 msg_starting "$SVC_NAME"
52                 daemon /usr/sbin/httpd.${HTTPD_MPM} $CFG $HTTPD_OPTS
53                 RETVAL=$?
54                 [ $RETVAL -eq 0 ] && touch /var/lock/subsys/httpd
55         else
56                 msg_already_running "$SVC_NAME"
57         fi
58 }
59
60 stop() {
61         # Stop daemons.
62         if [ -f /var/lock/subsys/httpd ]; then
63                 msg_stopping "$SVC_NAME"
64                 killproc --pidfile httpd.pid httpd.${HTTPD_MPM}
65                 rm -f /var/lock/subsys/httpd /var/run/httpd.pid /var/run/httpd.loc* >/dev/null 2>&1
66         else
67                 msg_not_running "$SVC_NAME"
68         fi
69 }
70
71 condrestart() {
72         if [ -f /var/lock/subsys/httpd ]; then
73                 stop
74                 start
75         else
76                 msg_not_running "$SVC_NAME"
77                 RETVAL=$1
78         fi
79 }
80
81 RETVAL=0
82 # See how we were called.
83 case "$1" in
84   start)
85         start
86         ;;
87   stop)
88         stop
89         ;;
90   status)
91         status httpd.${HTTPD_MPM}
92         RETVAL=$?
93         /usr/sbin/httpd.${HTTPD_MPM} $CFG $HTTPD_OPTS -S
94         ;;
95   restart)
96         stop
97         start
98         ;;
99   try-restart)
100         condrestart 0
101         ;;
102   reload|force-reload|graceful)
103         if [ -f /var/lock/subsys/httpd ]; then
104                 configtest
105                 if [ $RETVAL -eq 0 ]; then
106                         msg_reloading "$SVC_NAME"
107                         busy
108                         /usr/sbin/httpd.${HTTPD_MPM} $CFG $HTTPD_OPTS -k graceful
109                         RETVAL=$?
110                         [ $RETVAL -eq 0 ] && ok || fail
111                 fi
112         else
113                 msg_not_running "$SVC_NAME"
114                 RETVAL=7
115         fi
116         ;;
117   flush-logs)
118         if [ -f /var/lock/subsys/httpd ]; then
119                 msg_reloading "$SVC_NAME"
120
121                 configtest
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. Run $0 configtest to see errors."
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.038044 seconds and 3 git commands to generate.