~ubuntu-branches/ubuntu/trusty/apache2/trusty

« back to all changes in this revision

Viewing changes to debian/apache2.2-common.apache2.init

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2010-05-05 01:28:04 UTC
  • mfrom: (14.3.15 sid)
  • Revision ID: james.westby@ubuntu.com-20100505012804-vbouq0xs3tu2vvij
Tags: 2.2.15-5ubuntu1
* Merge from debian unstable.  Remaining changes:
  - debian/{control, rules}: Enable PIE hardening.
  - debian/{control, rules, apache2.2-common.ufw.profile}: Add ufw profiles.
  - debian/control: Add bzr tag and point it to our tree.
  - debian/apache2-2.common.apache2.init: Add graceful restart (LP: #456381)
  + Dropped:
    - debian/patches/206-fix-potential-memory-leaks.dpatch: No longer needed.
    - debian/patches/206-report-max-client-mpm-worker.dpatch: No longer needed.
    - debian/config-dir/apache2.conf: Merged back from debian.
    - mod-reqtimeout functionality: Merge back from debian.
    - debian/patches/204_CVE-2010-0408.dpatch: No longer needed.
    - debian/patches/205_CVE-2010-0434.dpatch: No longer needed.
    - debian/patches/203_fix-ab-segfault.dpatch: No longer needed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/sh -e
 
1
#!/bin/sh
2
2
### BEGIN INIT INFO
3
3
# Provides:          apache2
4
4
# Required-Start:    $local_fs $remote_fs $network $syslog
8
8
# X-Interactive:     true
9
9
# Short-Description: Start/stop apache2 web server
10
10
### END INIT INFO
11
 
#
12
 
# apache2               This init.d script is used to start apache2.
13
 
#                       It basically just calls apache2ctl.
 
11
 
 
12
set -e
 
13
 
 
14
if [ -n "$APACHE_CONFDIR" ] ; then
 
15
        if [ "${APACHE_CONFDIR##/etc/apache2-}" != "$APACHE_CONFDIR}" ] ; then
 
16
                DIR_SUFFIX="${APACHE_CONFDIR##/etc/apache2-}"
 
17
        else
 
18
                DIR_SUFFIX=
 
19
        fi
 
20
elif [ "${0##*/apache2-}" != "$0" ] ; then
 
21
        DIR_SUFFIX="-${0##*/apache2-}"
 
22
        APACHE_CONFDIR=/etc/apache2$DIR_SUFFIX
 
23
else
 
24
        DIR_SUFFIX=
 
25
        APACHE_CONFDIR=/etc/apache2
 
26
fi
 
27
if [ -z "$APACHE_ENVVARS" ] ; then
 
28
        APACHE_ENVVARS=$APACHE_CONFDIR/envvars
 
29
fi
 
30
export APACHE_CONFDIR APACHE_ENVVARS
14
31
 
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"
 
35
fi
 
36
if [ "$APACHE_ENVVARS" != "$APACHE_CONFDIR/envvars" ] ; then
 
37
        ENV="$ENV APACHE_ENVVARS=$APACHE_ENVVARS"
 
38
fi
16
39
 
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
20
40
 
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=""
28
48
 
29
 
set -e
30
 
if [ -x /usr/sbin/apache2 ] ; then
31
 
        HAVE_APACHE2=1
32
 
else
 
49
APACHE_HTTPD=$(. $APACHE_ENVVARS && echo $APACHE_HTTPD)
 
50
if [ -z "$APACHE_HTTPD" ] ; then
 
51
        APACHE_HTTPD=/usr/sbin/apache2
 
52
fi
 
53
if [ ! -x $APACHE_HTTPD ] ; then
33
54
        echo "No apache MPM package installed"
34
55
        exit 0
35
56
fi
37
58
. /lib/lsb/init-functions
38
59
 
39
60
test -f /etc/default/rcS && . /etc/default/rcS
40
 
test -f /etc/default/apache2 && . /etc/default/apache2
 
61
 
 
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
 
66
fi
41
67
 
42
68
APACHE2CTL="$ENV /usr/sbin/apache2ctl"
43
69
HTCACHECLEAN="$ENV /usr/sbin/htcacheclean"
44
70
 
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
48
74
        exit 2
49
75
fi
50
76
 
54
80
 
55
81
        [ "$HTCACHECLEAN_RUN"  = "yes"    ] && return 0
56
82
 
 
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 ] && \
 
86
                return 0
59
87
        
60
88
        return 1
61
89
}
62
90
 
63
91
start_htcacheclean() {
 
92
        if [ ! -d "$HTCACHECLEAN_PATH" ] ; then
 
93
                echo "... directory $HTCACHECLEAN_PATH does not exist!" >&2
 
94
                return 1
 
95
        fi      
64
96
        $HTCACHECLEAN $HTCACHECLEAN_OPTIONS -d$HTCACHECLEAN_DAEMON_INTERVAL \
65
97
                        -i -p$HTCACHECLEAN_PATH -l$HTCACHECLEAN_SIZE
66
 
                                
67
98
}
68
99
 
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
71
102
}
72
103
 
73
104
pidof_apache() {
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
78
109
                        return 0
79
110
                fi
80
111
        fi
91
122
                PID=$(pidof_apache) || true
92
123
 
93
124
                if [ "${PID}" ]; then
94
 
                        # in this case it is everything nice and dandy
95
 
                        # and we kill apache2
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
 
126
                        echo
 
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!"
97
128
                        kill $PID
98
129
                elif [ "$(pidof apache2)" ]; then
99
130
                        if [ "$VERBOSE" != no ]; then
163
194
                        log_end_msg 1
164
195
                fi
165
196
        ;;
 
197
        graceful-stop)
 
198
                if check_htcacheclean ; then
 
199
                        log_daemon_msg "Stopping web server" "htcacheclean"
 
200
                        stop_htcacheclean
 
201
                        log_progress_msg "apache2"
 
202
                else
 
203
                        log_daemon_msg "Stopping web server" "apache2"
 
204
                fi
 
205
                if $APACHE2CTL graceful-stop; then
 
206
                        log_end_msg 0
 
207
                else
 
208
                        log_end_msg 1
 
209
                fi
 
210
        ;;
166
211
        graceful | reload | force-reload)
167
212
                if ! $APACHE2CTL configtest > /dev/null 2>&1; then
168
213
                    $APACHE2CTL configtest || true
179
224
                fi
180
225
        ;;
181
226
        restart)
 
227
                if ! $APACHE2CTL configtest > /dev/null 2>&1; then
 
228
                    $APACHE2CTL configtest || true
 
229
                    log_end_msg 1
 
230
                    exit 1
 
231
                fi
182
232
                if check_htcacheclean ; then
183
233
                        log_daemon_msg "Restarting web server" "htcacheclean"
184
234
                        stop_htcacheclean
212
262
        status)
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)."
216
266
                        exit 0
217
267
                else
218
 
                        echo "Apache is NOT running."
 
268
                        echo "Apache2$DIR_SUFFIX is NOT running."
219
269
                        exit 1
220
270
                fi
221
271
        ;;
222
272
        *)
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}"
224
274
                exit 1
225
275
        ;;
226
276
esac