]> git.pld-linux.org Git - packages/apache.git/blob - apache.init
- more complicated (rock-solid ;-) HTTPD_CONF handling
[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/conf/access.conf
11 # config:       /etc/httpd/conf/httpd.conf
12 # config:       /etc/httpd/conf/srm.conf
13
14
15 # Source function library
16 . /etc/rc.d/init.d/functions
17
18 # Get network config
19 . /etc/sysconfig/network
20
21 # Get service config
22 [ -f /etc/sysconfig/apache ] && . /etc/sysconfig/apache
23
24 # Check that networking is up.
25 if is_yes "${NETWORKING}"; then
26         if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then
27                 # nls "ERROR: Networking is down. %s can't be run." <service>
28                 msg_network_down httpd
29                 exit 1
30         fi
31 else
32         exit 0
33 fi
34
35 [ -z "$HTTPD_MPM" ] && HTTPD_MPM="prefork"
36 if   [ -d "${HTTPD_CONF:-'/etc/httpd/httpd.conf'}" ]; then
37         CFG="-d ${HTTPD_CONF:-'/etc/httpd/httpd.conf'}"
38 elif [ -f "${HTTPD_CONF:-'/etc/httpd/httpd.conf'}" ]; then
39         CFG="-f ${HTTPD_CONF:-'/etc/httpd/httpd.conf'}"
40 elif [ -n "$HTTPD_CONF" ]; then
41         echo "error: HTTPD_CONF='$HTTPD_CONF': not a file, not a directory"
42         exit 1
43 else CFG=""; fi
44
45 RETVAL=0
46 # See how we were called.
47 case "$1" in
48   start)
49         # Check if the service is already running?
50         if [ ! -f /var/lock/subsys/httpd ]; then
51                 msg_starting httpd.${HTTPD_MPM}
52                 daemon httpd.${HTTPD_MPM} $CFG $HTTPD_OPTS
53                 RETVAL=$?
54                 [ $RETVAL -eq 0 ] && touch /var/lock/subsys/httpd
55         else
56                 msg_already_running httpd.${HTTPD_MPM}
57         fi
58         ;;
59   stop)
60         # Stop daemons.
61         if [ -f /var/lock/subsys/httpd ]; then
62                 msg_stopping httpd.${HTTPD_MPM}
63                 if [ -f /var/run/httpd.pid ]; then
64                         PID=$(filter_chroot `cat /var/run/httpd.pid`)
65                         if [ -z "$PID" ]; then
66                                 PID=0
67                         fi
68                 else
69                         PID=0
70                 fi
71                 daemon httpd.${HTTPD_MPM} -f /etc/httpd/httpd.conf -k stop
72                 RET=$?
73                 # Wait for httpd to really stop
74                 if [ ! $PID -eq 0 -a $RET -eq 0 ]; then
75                         show "Waiting for httpd to stop"
76                         busy
77                         while ps -o command $PID | grep -q ^httpd
78                         do
79                                 sleep 1
80                         done
81                         ok
82                 fi
83                 # Delete pidfile only when apache was called successfully
84                 if [ $RET -eq 0 ]; then
85                         rm -f /var/lock/subsys/httpd /var/run/httpd.pid /var/run/httpd.loc* >/dev/null 2>&1
86                 fi
87         else
88                 msg_not_running httpd.${HTTPD_MPM}
89         fi
90         ;;
91   status)
92         status httpd.${HTTPD_MPM}
93         RETVAL=$?
94         /usr/sbin/httpd.${HTTPD_MPM} -f /etc/httpd/httpd.conf -S
95         ;;
96   restart)
97         $0 stop
98         $0 start
99         ;;
100   reload|force-reload|graceful)
101         if [ -f /var/lock/subsys/httpd ]; then
102                 msg_reloading httpd.${HTTPD_MPM}
103                 daemon httpd.${HTTPD_MPM} -f /etc/httpd/httpd.conf -k graceful
104                 RETVAL=$?
105         else
106                 msg_not_running httpd.${HTTPD_MPM} >&2
107                 RETVAL=7
108         fi
109         ;;
110   *)
111         msg_usage "$0 {start|stop|restart|reload|force-reload|graceful|status}"
112         exit 3
113         ;;
114 esac
115
116 exit $RETVAL
This page took 0.035858 seconds and 4 git commands to generate.