summaryrefslogtreecommitdiffstats
path: root/meta-webserver
diff options
context:
space:
mode:
authorAdam Chappell <adam.chappell@ni.com>2015-08-20 17:48:22 -0500
committerMartin Jansa <Martin.Jansa@gmail.com>2015-08-31 20:09:30 +0200
commitfaf070c45a67f0ad49f52bc4cb79a77f64842d93 (patch)
treeceb19578661117ceb5e284bd47d93658c9be98cb /meta-webserver
parente5abd3c3fb72556dd6fdce126fe7b81ed1285401 (diff)
downloadmeta-openembedded-faf070c45a67f0ad49f52bc4cb79a77f64842d93.tar.gz
apache2: wait for server to start/stop/restart
Change start, stop, and restart functions in apache2 init script to return only after completion (i.e. the server has started/stopped, not just received a kill signal). Starting and stopping the server in quick sucession results in an error because the server will attempt to stop before it has had time to start and vice versa. Signed-off-by: Adam Chappell <adam.chappell@ni.com> Signed-off-by: Martin Jansa <Martin.Jansa@gmail.com>
Diffstat (limited to 'meta-webserver')
-rwxr-xr-xmeta-webserver/recipes-httpd/apache2/files/init165
1 files changed, 161 insertions, 4 deletions
diff --git a/meta-webserver/recipes-httpd/apache2/files/init b/meta-webserver/recipes-httpd/apache2/files/init
index a1adbd74f..758d133b9 100755
--- a/meta-webserver/recipes-httpd/apache2/files/init
+++ b/meta-webserver/recipes-httpd/apache2/files/init
@@ -28,14 +28,161 @@ test -f $APACHECTL || exit 0
28# ensure we don't leak environment vars into apachectl 28# ensure we don't leak environment vars into apachectl
29APACHECTL="env -i LANG=${LANG} PATH=${PATH} $APACHECTL" 29APACHECTL="env -i LANG=${LANG} PATH=${PATH} $APACHECTL"
30 30
31apache_conftest() {
32 if $($APACHECTL configtest > /dev/null 2>&1 ); then
33 return 0
34 else
35 return 1
36 fi
37}
38
39apache_wait_start() {
40 local STATUS=$1
41
42 if [ $STATUS != 0 ] ; then
43 return $STATUS
44 fi
45
46 local i=0
47 while : ; do
48 PIDTMP=$(pidof $DAEMON | tr ' ' '\n' | grep -w $(cat $PIDFILE))
49 if [ -n "${PIDTMP:-}" ] && kill -0 "${PIDTMP:-}" 2> /dev/null; then
50 return $STATUS
51 fi
52
53 if [ $i = "20" ] ; then
54 return 2
55 fi
56
57 sleep 1
58 i=$(($i+1))
59 done
60}
61
62apache_wait_stop() {
63 local STATUS=$1
64
65 if [ $STATUS != 0 ] ; then
66 return $STATUS
67 fi
68
69 PIDTMP=$(pidof $DAEMON | tr ' ' '\n' | grep -w $(cat $PIDFILE))
70 if [ -n "${PIDTMP:-}" ] && kill -0 "${PIDTMP:-}" 2> /dev/null; then
71 local i=0
72 while kill -0 "${PIDTMP:-}" 2> /dev/null; do
73 if [ $i = '60' ]; then
74 STATUS=2
75 break
76 fi
77 sleep 1
78 i=$(($i+1))
79 done
80 return $STATUS
81 else
82 return $STATUS
83 fi
84}
85
86#
87# Function that starts the daemon/service
88#
89do_start()
90{
91 # Return
92 # 0 if daemon has been started
93 # 1 if daemon was already running
94 # 2 if daemon could not be started
95
96 if [ -e $PIDFILE ] && pidof $DAEMON | tr ' ' '\n' | grep -w $(cat $PIDFILE) > /dev/null 2>&1 ; then
97 return 1
98 fi
99
100 if apache_conftest ; then
101 $APACHECTL start
102 apache_wait_start $?
103 return $?
104 else
105 return 2
106 fi
107}
108
109#
110# Function that stops the daemon/service
111#
112do_stop()
113{
114 # Return
115 # 0 if daemon has been stopped
116 # 1 if daemon was already stopped
117 # 2 if daemon could not be stopped
118 # other if a failure occurred
119
120 local AP_RET=0
121
122 if pidof $DAEMON > /dev/null 2>&1 ; then
123 if [ -e $PIDFILE ] && pidof $DAEMON | tr ' ' '\n' | grep -w $(cat $PIDFILE) > /dev/null 2>&1 ; then
124 AP_RET=2
125 else
126 AP_RET=1
127 fi
128 else
129 AP_RET=0
130 fi
131
132 # AP_RET is:
133 # 0 if Apache (whichever) is not running
134 # 1 if Apache (whichever) is running
135 # 2 if Apache from the PIDFILE is running
136
137 if [ $AP_RET = 0 ] ; then
138 return 1
139 fi
140
141 if [ $AP_RET = 2 ] && apache_conftest ; then
142 $APACHECTL stop
143 apache_wait_stop $?
144 return $?
145 else
146 if [ $AP_RET = 2 ]; then
147 kill $(pidof $DAEMON | tr ' ' '\n' | grep -w $(cat $PIDFILE))
148 apache_wait_stop $?
149 return $?
150 elif [ $AP_RET = 1 ] ; then
151 return 2
152 fi
153 fi
154
155}
156
31case "$1" in 157case "$1" in
32 start) 158 start)
33 echo -n "Starting web server: $NAME" 159 echo -n "Starting web server: $NAME"
34 $APACHECTL $ARGS 160 do_start
161 case $? in
162 0|1)
163 echo .
164 exit 0
165 ;;
166 2)
167 echo failed
168 exit 1
169 ;;
170 esac
35 ;; 171 ;;
36 172
37 stop) 173 stop)
38 $APACHECTL stop 174 echo -n "Stopping web server: $NAME"
175 do_stop
176 case $? in
177 0|1)
178 echo .
179 exit 0
180 ;;
181 2)
182 echo failed
183 exit 1
184 ;;
185 esac
39 ;; 186 ;;
40 187
41 reload) 188 reload)
@@ -49,8 +196,18 @@ case "$1" in
49 ;; 196 ;;
50 197
51 restart) 198 restart)
52 $APACHECTL restart 199 echo "Restarting web server: $NAME"
53 exit $? 200 do_stop
201 case "$?" in
202 0|1)
203 do_start
204 exit $?
205 ;;
206 *)
207 # Failed to stop
208 exit 1
209 ;;
210 esac
54 ;; 211 ;;
55 212
56 force-reload) 213 force-reload)