#!/bin/sh NAME="Web server" COMMAND=/opt/bin/httpd ARGS="-f /etc/opt/httpd/httpd.conf" OUTPUT_LOG=/dev/null START_TIMEOUT=3 STOP_TIMEOUT=3 PATH=/sbin:/bin:/usr/sbin:/usr/bin case $1 in start) # check the current state of the daemon if [ "$(pidof $COMMAND)" = "" ]; then # as long as the deamon is not running, give the command to start it echo "$NAME is starting." $COMMAND $ARGS >>$OUTPUT_LOG 2>&1 # verify that it actually started, but be patient TIMER=$START_TIMEOUT while [ "$(pidof $COMMAND)" = "" ] && [ $TIMER -gt 0 ]; do sleep 1 TIMER=$(($TIMER-1)) done # report an error if it has not started by now if [ "$(pidof $COMMAND)" = "" ]; then echo "$NAME failed to start in a timely manner." fi fi ;; stop) # check the current state of the daemon if ! [ "$(pidof $COMMAND)" = "" ]; then # as long as the deamon is running, give the command to stop it echo "$NAME is stopping." killall $COMMAND # verify that it actually stopped, but be patient TIMER=$STOP_TIMEOUT while [ "$(pidof $COMMAND)" != "" ] && [ $TIMER -gt 0 ]; do sleep 1 TIMER=$(($TIMER-1)) done # report an error if it has not stopped by now if [ "$(pidof $COMMAND)" != "" ]; then echo "$NAME failed to stop in a timely manner." fi fi ;; restart) $0 stop $0 start ;; status|stat) if ! [ "$(pidof $COMMAND)" = "" ]; then echo "$NAME is running." else echo "$NAME is stopped." fi ;; *) echo "usage: $0 start|stop|restart|status" ;; esac