Puppet: System Administration Automated

Support

UsingMongrelOnDebian: apache2-puppetmaster

File apache2-puppetmaster, 4.8 kB (added by marthag, 10 months ago)

/etc/init.d/apache2-puppetmaster

Line 
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         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 -f /etc/apache2/puppetmaster.conf"
33 APACHE2CTL="$ENV /usr/sbin/apache2ctl -f /etc/apache2/puppetmaster.conf -k "
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/puppetmaster.conf -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 apache_sync_stop() {
93         # running ?
94         PIDTMP=$(pidof_apache)
95         if $(kill -0 "${PIDTMP:-}" 2> /dev/null); then
96             PID=$PIDTMP
97         fi
98
99         apache_stop
100
101         # wait until really stopped
102         if [ -n "${PID:-}" ]; then
103                 i=0
104                 while $(kill -0 "${PID:-}" 2> /dev/null);  do
105                         if [ $i = '30' ]; then
106                                 break;
107                         else
108                                 if [ $i = '0' ]; then
109                                         echo -n " waiting "
110                                 else
111                                         echo -n "."
112                                 fi
113                                 i=$(($i+1))
114                                 sleep 2
115                       fi
116                  done
117         fi
118 }
119
120 # Stupid hack to keep lintian happy. (Warrk! Stupidhack!).
121 case $1 in
122         start)
123                 [ -f /etc/apache2/httpd.conf ] || touch /etc/apache2/httpd.conf
124                 [ -d /var/run/apache2 ] || mkdir -p /var/run/apache2
125                 install -d -o www-data /var/lock/apache2
126                 #ssl_scache shouldn't be here if we're just starting up.
127                 [ -f /var/run/apache2/ssl_scache ] && rm -f /var/run/apache2/*ssl_scache*
128                 log_begin_msg "Starting web server (apache2)..."
129                 if $APACHE2CTL start; then
130                         log_end_msg 0
131                 else
132                         log_end_msg 1
133                 fi
134         ;;
135         stop)
136                 log_begin_msg "Stopping web server (apache2)..."
137                 if apache_stop; then
138                         log_end_msg 0
139                 else
140                         log_end_msg 1
141                 fi
142         ;;
143         reload)
144                 if ! $APACHE2CTL configtest > /dev/null 2>&1; then
145                     $APACHE2CTL configtest || true
146                     log_end_msg 1
147                     exit 1
148                 fi
149                 log_begin_msg "Reloading web server config..."
150                 if pidof_apache; then
151                     if $APACHE2CTL graceful $2 ; then
152                         log_end_msg 0
153                     else
154                         log_end_msg 1
155                     fi
156                 fi
157         ;;
158         restart | force-reload)
159                 log_begin_msg "Forcing reload of web server (apache2)..."
160                 if ! apache_sync_stop; then
161                         log_end_msg 1
162                 fi
163                 if $APACHE2CTL start; then
164                         log_end_msg 0
165                 else
166                         log_end_msg 1
167                 fi
168         ;;
169         *)
170                 log_success_msg "Usage: /etc/init.d/apache2-puppetmaster {start|stop|restart|reload|force-reload}"
171         ;;
172 esac