8
8
# X-Interactive: true
9
9
# Short-Description: Start/stop apache2 web server
12
# apache2 This init.d script is used to start apache2.
13
# It basically just calls apache2ctl.
14
if [ -n "$APACHE_CONFDIR" ] ; then
15
if [ "${APACHE_CONFDIR##/etc/apache2-}" != "$APACHE_CONFDIR}" ] ; then
16
DIR_SUFFIX="${APACHE_CONFDIR##/etc/apache2-}"
20
elif [ "${0##*/apache2-}" != "$0" ] ; then
21
DIR_SUFFIX="-${0##*/apache2-}"
22
APACHE_CONFDIR=/etc/apache2$DIR_SUFFIX
25
APACHE_CONFDIR=/etc/apache2
27
if [ -z "$APACHE_ENVVARS" ] ; then
28
APACHE_ENVVARS=$APACHE_CONFDIR/envvars
30
export APACHE_CONFDIR APACHE_ENVVARS
15
32
ENV="env -i LANG=C PATH=/usr/local/bin:/usr/bin:/bin"
33
if [ "$APACHE_CONFDIR" != /etc/apache2 ] ; then
34
ENV="$ENV APACHE_CONFDIR=$APACHE_CONFDIR"
36
if [ "$APACHE_ENVVARS" != "$APACHE_CONFDIR/envvars" ] ; then
37
ENV="$ENV APACHE_ENVVARS=$APACHE_ENVVARS"
17
#[ $(ls -1 /etc/apache2/sites-enabled/ | wc -l | sed -e 's/ *//;') -eq 0 ] && \
18
#echo "You haven't enabled any sites yet, so I'm not starting apache2." && \
19
#echo "To add and enable a host, use addhost and enhost." && exit 0
21
41
#edit /etc/default/apache2 to change this.
22
42
HTCACHECLEAN_RUN=auto
23
43
HTCACHECLEAN_MODE=daemon
24
44
HTCACHECLEAN_SIZE=300M
25
45
HTCACHECLEAN_DAEMON_INTERVAL=120
26
HTCACHECLEAN_PATH=/var/cache/apache2/mod_disk_cache
46
HTCACHECLEAN_PATH=/var/cache/apache2$DIR_SUFFIX/mod_disk_cache
27
47
HTCACHECLEAN_OPTIONS=""
30
if [ -x /usr/sbin/apache2 ] ; then
49
APACHE_HTTPD=$(. $APACHE_ENVVARS && echo $APACHE_HTTPD)
50
if [ -z "$APACHE_HTTPD" ] ; then
51
APACHE_HTTPD=/usr/sbin/apache2
53
if [ ! -x $APACHE_HTTPD ] ; then
33
54
echo "No apache MPM package installed"
37
58
. /lib/lsb/init-functions
39
60
test -f /etc/default/rcS && . /etc/default/rcS
40
test -f /etc/default/apache2 && . /etc/default/apache2
62
if [ -f /etc/default/apache2$DIR_SUFFIX ] ; then
63
. /etc/default/apache2$DIR_SUFFIX
64
elif [ -f /etc/default/apache2 ] ; then
65
. /etc/default/apache2
42
68
APACHE2CTL="$ENV /usr/sbin/apache2ctl"
43
69
HTCACHECLEAN="$ENV /usr/sbin/htcacheclean"
45
PIDFILE=$(. /etc/apache2/envvars && echo $APACHE_PID_FILE)
71
PIDFILE=$(. $APACHE_ENVVARS && echo $APACHE_PID_FILE)
46
72
if [ -z "$PIDFILE" ] ; then
47
echo ERROR: APACHE_PID_FILE needs to be defined in /etc/apache2/envvars >&2
73
echo ERROR: APACHE_PID_FILE needs to be defined in $APACHE_ENVVARS >&2
55
81
[ "$HTCACHECLEAN_RUN" = "yes" ] && return 0
83
MODSDIR=$(. $APACHE_ENVVARS && echo $APACHE_MODS_ENABLED)
57
84
[ "$HTCACHECLEAN_RUN" = "auto" \
58
-a -e /etc/apache2/mods-enabled/disk_cache.load ] && return 0
85
-a -e ${MODSDIR:-$APACHE_CONFDIR/mods-enabled}/disk_cache.load ] && \
63
91
start_htcacheclean() {
92
if [ ! -d "$HTCACHECLEAN_PATH" ] ; then
93
echo "... directory $HTCACHECLEAN_PATH does not exist!" >&2
64
96
$HTCACHECLEAN $HTCACHECLEAN_OPTIONS -d$HTCACHECLEAN_DAEMON_INTERVAL \
65
97
-i -p$HTCACHECLEAN_PATH -l$HTCACHECLEAN_SIZE
69
100
stop_htcacheclean() {
70
pkill htcacheclean 2> /dev/null || echo ...not running
101
pkill -P 1 -f "htcacheclean.*\\<-p$HTCACHECLEAN_PATH\\>" 2> /dev/null || echo ...not running
74
105
# if there is actually an apache2 process whose pid is in PIDFILE,
75
106
# print it and return 0.
76
107
if [ -e "$PIDFILE" ]; then
77
if pidof apache2 | tr ' ' '\n' | grep $(cat $PIDFILE); then
108
if pidof apache2 | tr ' ' '\n' | grep -w $(cat $PIDFILE); then
91
122
PID=$(pidof_apache) || true
93
124
if [ "${PID}" ]; then
94
# in this case it is everything nice and dandy
96
log_warning_msg "We failed to correctly shutdown apache, so we're now killing all running apache processes. This is almost certainly suboptimal, so please make sure your system is working as you'd expect now!"
125
# in this case it is everything nice and dandy and we kill apache2
127
log_warning_msg "The apache2$DIR_SUFFIX configtest failed, so we are trying to kill it manually. This is almost certainly suboptimal, so please make sure your system is working as you'd expect now!"
98
129
elif [ "$(pidof apache2)" ]; then
99
130
if [ "$VERBOSE" != no ]; then
198
if check_htcacheclean ; then
199
log_daemon_msg "Stopping web server" "htcacheclean"
201
log_progress_msg "apache2"
203
log_daemon_msg "Stopping web server" "apache2"
205
if $APACHE2CTL graceful-stop; then
166
211
graceful | reload | force-reload)
167
212
if ! $APACHE2CTL configtest > /dev/null 2>&1; then
168
213
$APACHE2CTL configtest || true
213
263
PID=$(pidof_apache) || true
214
264
if [ -n "$PID" ]; then
215
echo "Apache is running (pid $PID)."
265
echo "Apache2$DIR_SUFFIX is running (pid $PID)."
218
echo "Apache is NOT running."
268
echo "Apache2$DIR_SUFFIX is NOT running."
223
log_success_msg "Usage: /etc/init.d/apache2 {start|stop|restart|reload|force-reload|start-htcacheclean|stop-htcacheclean|status}"
273
log_success_msg "Usage: /etc/init.d/apache2$DIR_SUFFIX {start|stop|graceful-stop|restart|reload|force-reload|start-htcacheclean|stop-htcacheclean|status}"