diff options
Diffstat (limited to 'meta-webserver/recipes-httpd/apache2/files/init')
| -rwxr-xr-x | meta-webserver/recipes-httpd/apache2/files/init | 165 |
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 a1adbd74f9..758d133b9e 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 |
| 29 | APACHECTL="env -i LANG=${LANG} PATH=${PATH} $APACHECTL" | 29 | APACHECTL="env -i LANG=${LANG} PATH=${PATH} $APACHECTL" |
| 30 | 30 | ||
| 31 | apache_conftest() { | ||
| 32 | if $($APACHECTL configtest > /dev/null 2>&1 ); then | ||
| 33 | return 0 | ||
| 34 | else | ||
| 35 | return 1 | ||
| 36 | fi | ||
| 37 | } | ||
| 38 | |||
| 39 | apache_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 | |||
| 62 | apache_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 | # | ||
| 89 | do_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 | # | ||
| 112 | do_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 | |||
| 31 | case "$1" in | 157 | case "$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) |
