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