Creating the functions script

Create a new file /etc/init.d/functions containing the following:



#!/bin/sh
# Begin /etc/init.d/functions

COL=60
SET_COL="echo -en \\033[${COL}G"
NORMAL="echo -en \\033[0;39m"
GREEN="echo -en \\033[1;32m"
RED="echo -en \\033[1;31m"

evaluate_retval()
{
        if [ $? = 0 ]
        then
                $SET_COL
                echo -n "[  "
                $GREEN
                echo -n "OK"
                $NORMAL
                echo "  ]"
                echo -en "\r"
        else
                $SET_COL
                echo -n "["
                $RED
                echo -n "FAILED"
                $NORMAL
                echo -n "]"
                echo -en "\r"
        fi
}

status()
{
        if [ $# = 0 ]
        then
                echo "Usage: status {program}"
                return 1
        fi

        pid=`pidof -o $$ -o $PPID -o %PPID -x $1`
        if [ "$pid" != "" ]
        then
                echo "$1 running with Process ID $pid"
                return 0
        fi

        if [ -f /var/run/$1.pid ]
        then
                pid=`head -1 /var/run/$1.pid`
                if [ "$pid" != "" ]
                then
                        echo "$1 not running but /var/run/$1.pid exists"
                        return 1
                fi
        fi

}

# End /etc/init.d/functions