~ubuntu-branches/ubuntu/feisty/apache2/feisty

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Barth
  • Date: 2006-12-09 21:05:45 UTC
  • mfrom: (0.6.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20061209210545-h70s0xaqc2v8vqr2
Tags: 2.2.3-3.2
* Non-maintainer upload.
* 043_ajp_connection_reuse: Patch from upstream Bugzilla, fixing a critical
  issue with regard to connection reuse in mod_proxy_ajp.
  Closes: #396265

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh -e
 
2
#
 
3
# apache2               This init.d script is used to start apache2.
 
4
#                       It basically just calls apache2ctl.
 
5
 
 
6
ENV="env -i LANG=C PATH=/usr/local/bin:/usr/bin:/bin"
 
7
 
 
8
#[ `ls -1 /etc/apache2/sites-enabled/ | wc -l | sed -e 's/ *//;'` -eq 0 ] && \
 
9
#echo "You haven't enabled any sites yet, so I'm not starting apache2." && \
 
10
#echo "To add and enable a host, use addhost and enhost." && exit 0
 
11
 
 
12
#edit /etc/default/apache2 to change this.
 
13
NO_START=0
 
14
 
 
15
set -e
 
16
if [ -x /usr/sbin/apache2 ] ; then
 
17
        HAVE_APACHE2=1
 
18
else
 
19
        echo "No apache MPM package installed"
 
20
        exit 0
 
21
fi
 
22
 
 
23
. /lib/lsb/init-functions
 
24
 
 
25
test -f /etc/default/rcS && . /etc/default/rcS
 
26
test -f /etc/default/apache2 && . /etc/default/apache2
 
27
if [ "$NO_START" != "0" -a "$1" != "stop" ]; then 
 
28
        [ "$VERBOSE" != no ] && log_warning_msg "Not starting apache2 - edit /etc/default/apache2 and change NO_START to be 0.";
 
29
        exit 0;
 
30
fi
 
31
 
 
32
APACHE2="$ENV /usr/sbin/apache2"
 
33
APACHE2CTL="$ENV /usr/sbin/apache2ctl"
 
34
 
 
35
pidof_apache() {
 
36
    # if pidof is null for some reasons the script exits automagically
 
37
    # classified as good/unknown feature
 
38
    PIDS=`pidof apache2` || true
 
39
    
 
40
    PID=""
 
41
    
 
42
    # let's try to find the pid file
 
43
    # apache2 allows more than PidFile entry in the config but only
 
44
    # the last found in the config is used
 
45
    for PFILE in `grep ^PidFile /etc/apache2/* -r | awk '{print $2}'`; do
 
46
        if [ -e $PFILE ]; then
 
47
            cat $PFILE
 
48
            return 0
 
49
        fi
 
50
    done
 
51
    REALPID=0
 
52
    # if there is a pid we need to verify that belongs to apache2
 
53
    # for real
 
54
    for i in $PIDS; do
 
55
        if [ "$i" = "$PID" ]; then
 
56
            # in this case the pid stored in the
 
57
            # pidfile matches one of the pidof apache
 
58
            # so a simple kill will make it
 
59
            echo $PID
 
60
            return 0
 
61
        fi
 
62
    done
 
63
    return 1
 
64
}
 
65
 
 
66
apache_stop() {
 
67
        if `apache2 -t > /dev/null 2>&1`; then
 
68
                # if the config is ok than we just stop normaly
 
69
                $APACHE2 -k stop
 
70
        else
 
71
                # if we are here something is broken and we need to try
 
72
                # to exit as nice and clean as possible
 
73
                PID=$(pidof_apache)
 
74
 
 
75
                if [ "${PID}" ]; then
 
76
                        # in this case it is everything nice and dandy
 
77
                        # and we kill apache2
 
78
                        kill $PID
 
79
                elif [ "$(pidof apache2)" ]; then
 
80
                        if [ "$VERBOSE" != no ]; then
 
81
                                echo " ... failed!"
 
82
                                echo "You may still have some apache2 processes running.  There are"
 
83
                                echo "processes named 'apache2' which do not match your pid file,"
 
84
                                echo "and in the name of safety, we've left them alone.  Please review"
 
85
                                echo "the situation by hand."
 
86
                        fi
 
87
                        return 1
 
88
                fi
 
89
        fi
 
90
}
 
91
 
 
92
# Stupid hack to keep lintian happy. (Warrk! Stupidhack!).
 
93
case $1 in
 
94
        start)
 
95
                [ -f /etc/apache2/httpd.conf ] || touch /etc/apache2/httpd.conf
 
96
                [ -d /var/run/apache2 ] || mkdir -p /var/run/apache2
 
97
                [ -d /var/lock/apache2 ] || mkdir -p /var/lock/apache2
 
98
                #ssl_scache shouldn't be here if we're just starting up.
 
99
                [ -f /var/run/apache2/ssl_scache ] && rm -f /var/run/apache2/*ssl_scache*
 
100
                log_begin_msg "Starting web server (apache2)..."
 
101
                if $APACHE2CTL start; then
 
102
                        log_end_msg 0
 
103
                else
 
104
                        log_end_msg 1
 
105
                fi
 
106
        ;;
 
107
        stop)
 
108
                log_begin_msg "Stopping web server (apache2)..."
 
109
                if apache_stop; then
 
110
                        log_end_msg 0
 
111
                else
 
112
                        log_end_msg 1
 
113
                fi
 
114
        ;;
 
115
        reload)
 
116
                if ! $APACHE2CTL configtest > /dev/null 2>&1; then
 
117
                    $APACHE2CTL configtest || true
 
118
                    log_end_msg 1
 
119
                    exit 1
 
120
                fi
 
121
                log_begin_msg "Reloading web server config..."
 
122
                if pidof_apache; then
 
123
                    if $APACHE2CTL graceful $2 ; then
 
124
                        log_end_msg 0
 
125
                    else
 
126
                        log_end_msg 1
 
127
                    fi
 
128
                fi
 
129
        ;;
 
130
        restart | force-reload)
 
131
                log_begin_msg "Forcing reload of web server (apache2)..."
 
132
                if ! apache_stop; then
 
133
                        log_end_msg 1
 
134
                fi
 
135
                sleep 10
 
136
                if $APACHE2CTL start; then
 
137
                        log_end_msg 0
 
138
                else
 
139
                        log_end_msg 1
 
140
                fi
 
141
        ;;
 
142
        *)
 
143
                log_success_msg "Usage: /etc/init.d/apache2 {start|stop|restart|reload|force-reload}"
 
144
        ;;
 
145
esac