Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

yet another lighttpd restart script (with status) (See related posts)

#!/bin/sh

# Author: Nathaniel Brown
# Date: December 16, 2005
# URL: http://nshb.net/lighttpd-restart-script.html
# Version: 1.0
# License: MIT

#Binary Paths
CAT="/bin/cat"
PS="/bin/ps"
HTTPD="/usr/local/sbin/lighttpd"

# Modifiy this line for each install
PATH="/home/httpd/vhosts/domain.com/lighttpd/"
LIGHTTPD_CONF=$PATH"lighttpd.conf"
PIDFILE=$PATH"var/run/lighttpd.pid"


PID=0
if [ -e $PIDFILE ]; then
    PID=`$CAT $PIDFILE`
    if [ "x" == "x$PID" ]; then
        PID=0
    fi
fi


case "$1" in
    start)
        if [ 0 -ne $PID ]; then
            running=`$PS --pid $PID | grep $PID`
            if [ $running ]; then
                echo "lighttpd is already running"
                exit 1
            fi
            rm $PIDFILE
            PID=0
        fi
        $HTTPD -f $LIGHTTPD_CONF
        ;;
    stop)
        if [ 0 -eq $PID ]; then
            echo "lighttpd was not running"
            exit 1
        fi
        kill $PID
        tries=""
        while [ -e $PIDFILE ]; do
            if [ "x$tries" == "x.........." ]; then
                break
            fi
            sleep 2
            tries=".$tries"
        done
        if [ -e $PIDFILE ]; then
            echo "lighttpd did not go gentle into that good night, murdering"
            kill -9 $PID
            rm $PIDFILE
        fi
        ;;
    restart)
        $0 stop
        $0 start
        ;;
    reload)
        if [ 0 -eq $PID ]; then
            echo "lighttpd was not running"
        fi
        kill -HUP $PID
        ;;
    status)
       if [ 0 -eq $PID ]; then
            echo "lighttpd is not running"
       fi
       if [ 0 -ne $PID ]; then
            echo "lighttpd (pid $PID) is running..."
       fi
       ;;
    *)
        echo "Usage: "`basename $0`" (start|stop|restart|reload|status)"
        exit 1
        ;;
esac

You need to create an account or log in to post comments to this site.


Related Posts