check_logfiles: 3.7.5.1
[omd.git] / packages / apache-omd / skel / etc / init.d / apache
blob022530ab0aee63af6df39a817b6ef0c3f2acaeb7
1 #!/bin/bash
3 cd ###ROOT###
4 . .profile
5 . lib/omd/init_profile
6 . etc/omd/site.conf
7 if [ "$CONFIG_APACHE_MODE" == none ]; then
8 exit 5
9 fi
11 # Start httpd in the C locale by default.
12 HTTPD_LANG="C"
14 # This will prevent initlog from swallowing up a pass-phrase prompt if
15 # mod_ssl needs a pass-phrase from the user.
16 INITLOG_ARGS=""
18 APACHE_RUN_USER="###SITE###"
19 APACHE_RUN_GROUP="###SITE###"
21 APACHE_BIN="###APACHE_BIN###"
22 PID_FILE=###ROOT###/tmp/apache/run/apache.pid
23 CONFIG_FILE=###ROOT###/etc/apache/apache.conf
25 pidof_apache() {
26 # if there is actually an apache2 process whose pid is in PIDFILE,
27 # print it and return 0.
28 if [ -e "$PID_FILE" ]; then
29 PID=$(cat "$PID_FILE")
30 if kill -0 $PID >/dev/null 2>&1; then
31 echo $PID
32 return 0
34 else
35 # It might happen that there is no pidfile but a process is running
36 # As fallback check the process table for the oldest apache process
37 # running as this user
38 PID=$(pgrep -u $OMD_SITE -o -f $APACHE_BIN)
39 if [ -n "$PID" ]; then
40 echo $PID
41 return 0
44 return 1
47 apache_wait_stop() {
48 # running ?
49 pid=$(pidof_apache) || true
50 if [ -n "${pid:-}" ]; then
51 kill ${pid:-}
52 else
53 echo -n '(not running)...'
54 return 0
57 # wait until really stopped
58 if [ -n "${pid:-}" ]; then
59 i=0
60 while kill -0 "${pid:-}" 2> /dev/null; do
61 if [ $i = '120' ]; then
62 kill_stale_php_cgis
63 return 1
64 else
65 echo -n "."
66 i=$(($i+1))
67 sleep 0.1
69 done
72 [ -f "$PID_FILE" ] && rm -f "$PID_FILE"
73 kill_stale_php_cgis
74 return 0
77 apache_wait_start() {
78 if pidof_apache >/dev/null 2>&1; then
79 echo -n '(already running)...'
80 return 0
83 mkdir -p ###ROOT###/tmp/apache/run
85 # (nearly) reproducible problems with apache at boot-time. (alloc_listener: failed to set up sockaddr for 127.0.0.1)
86 # With this ping the problem disappears.
87 test -f /etc/debian_version && test $(cut -f1 -d" " /proc/uptime | cut -f1 -d".") -lt 300 && ping -nqc 10 $CONFIG_APACHE_TCP_ADDR >/dev/null 2>&1
88 $APACHE_BIN -f "$CONFIG_FILE"
90 i=0
91 while ! pidof_apache >/dev/null 2>&1; do
92 if [ $i = '10' ]; then
93 return 1
94 else
95 echo -n "."
96 i=$(($i+1))
97 sleep 0.1
99 done
101 return 0
104 kill_stale_php_cgis()
107 killall -e ###PHP_FCGI_BIN### -u ###SITE### >/dev/null 2>&1
108 while killall -e ###PHP_FCGI_BIN### -u ###SITE### >/dev/null 2>&1
110 i=$((i+1))
111 if [ $i -gt 50 ] ; then
112 return
114 sleep 0.1
115 done
118 __init_hook $0 $1 pre
119 case $1 in
120 start)
121 echo -n "Starting dedicated Apache for site ###SITE###..."
122 if apache_wait_start; then
123 __init_hook $0 $1 post 0
124 echo 'OK'
125 exit 0
126 else
127 __init_hook $0 $1 post 1
128 echo 'ERROR'
129 exit 1
132 stop)
133 echo -n "Stopping dedicated Apache for site ###SITE###..."
134 if apache_wait_stop; then
135 __init_hook $0 $1 post 0
136 echo 'OK'
137 exit 0
138 else
139 __init_hook $0 $1 post 1
140 echo 'ERROR'
141 exit 1
144 restart)
145 $0 stop
146 $0 start
148 reload)
149 echo "Reloading dedicated Apache for site ###SITE###"
150 $APACHE_BIN -f "$CONFIG_FILE" -k graceful
151 __init_hook $0 $1 post $?
153 status)
154 PID=$(pidof_apache) || true
155 if [ -n "$PID" ]; then
156 echo "Apache is running (pid $PID)."
157 exit 0
158 else
159 echo "Apache is NOT running."
160 exit 1
164 echo "Usage: $0 {start|stop|restart|reload|status}"
166 esac