]> TLD Linux GIT Repositories - packages/apache.git/blob - apache.init
- updated to 2.4.55
[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.4 Web Server"
25                 exit 1
26         fi
27 else
28         exit 0
29 fi
30
31 SVC_NAME="Apache 2.4 Web Server"
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 itself
43 configtest() {
44         /usr/sbin/httpd -t $CFG $HTTPD_OPTS 2>&1
45         return $?
46 }
47
48 # wrapper for configtest:
49 checkconfig() {
50         local details=${1:-0}
51
52         if [ $details -eq 1 ]; then
53                 # run config test and display report (status action)
54                 show "Checking %s configuration" "$SVC_NAME"; busy
55                 local out
56                 out=`configtest 2>&1`
57                 RETVAL=$?
58                 [ $RETVAL -eq 0 ] && ok || fail
59                 [ "$out" ] && echo >&2 "$out"
60         else
61                 # run config test and abort with nice message if failed
62                 # (for actions checking status before action).
63                 show "Checking %s configuration" "$SVC_NAME"; busy
64                 configtest >/dev/null 2>&1
65                 RETVAL=$?
66                 if [ $RETVAL -eq 0 ]; then
67                         ok
68                 else
69                         fail
70                         nls 'Configuration test failed. See details with %s "checkconfig"' $0
71                         exit $RETVAL
72                 fi
73         fi
74 }
75
76 start() {
77         # Check if the service is already running?
78         if [ -f /var/lock/subsys/httpd ]; then
79                 msg_already_running "$SVC_NAME"
80                 return
81         fi
82
83         [ "$1" -eq 0 ] || checkconfig
84         msg_starting "$SVC_NAME"
85         # remove ssl_scache on startup, otherwise httpd may go into
86         # infinite loop if there are db transaction logs laying around
87         rm -f /var/cache/httpd/*ssl_scache*
88         daemon --pidfile /var/run/httpd.pid /usr/sbin/httpd $CFG $HTTPD_OPTS
89         RETVAL=$?
90         [ $RETVAL -eq 0 ] && touch /var/lock/subsys/httpd
91 }
92
93 stop() {
94         # Stop daemons.
95         if [ ! -f /var/lock/subsys/httpd ]; then
96                 msg_not_running "$SVC_NAME"
97                 return
98         fi
99
100         msg_stopping "$SVC_NAME"
101         killproc --pidfile /var/run/httpd.pid httpd
102         rm -f /var/lock/subsys/httpd /var/run/httpd.pid /var/run/httpd.loc* >/dev/null 2>&1
103 }
104
105
106 reload() {
107         if [ ! -f /var/lock/subsys/httpd ]; then
108                 msg_not_running "$SVC_NAME"
109                 RETVAL=7
110                 return
111         fi
112
113         checkconfig
114         msg_reloading "$SVC_NAME"
115         busy
116         /usr/sbin/httpd $CFG $HTTPD_OPTS -k graceful
117         RETVAL=$?
118         [ $RETVAL -eq 0 ] && ok || fail
119 }
120
121 condrestart() {
122         if [ ! -f /var/lock/subsys/httpd ]; then
123                 msg_not_running "$SVC_NAME"
124                 RETVAL=$1
125                 return
126         fi
127
128         checkconfig
129         stop
130         [ "$RESTART_DELAY" ] && usleep $RESTART_DELAY
131         start
132 }
133
134 RETVAL=0
135 # See how we were called.
136 case "$1" in
137   start)
138         start
139         ;;
140   stop)
141         stop
142         ;;
143   restart)
144         checkconfig
145         stop
146         [ "$RESTART_DELAY" ] && usleep $RESTART_DELAY
147         start 0
148         ;;
149   try-restart)
150         condrestart 0
151         ;;
152   reload|force-reload|graceful|flush-logs)
153         reload
154         ;;
155   checkconfig|configtest)
156         checkconfig 1
157         ;;
158   status)
159         status httpd
160         RETVAL=$?
161         /usr/sbin/httpd $CFG $HTTPD_OPTS -S
162         ;;
163   *)
164         msg_usage "$0 {start|stop|restart|try-restart|reload|force-reload|graceful|configtest|status}"
165         exit 3
166         ;;
167 esac
168
169 exit $RETVAL