12

In the init script of nginx in Debian 7 (Wheezy) I read the following exerpt:

status)
            status_of_proc -p /var/run/$NAME.pid "$DAEMON" nginx && exit 0 || exit $?
            ;;

This code runs just fine and sudo service nginx status outputs [ ok ] nginx is running. Yet status_of_proc is not defined in bash, neither in dash:

$ type status_of_proc
status_of_proc: not found

Though if I inserted the same check into the nginx-script I got the following result:

status_of_proc is a shell function

And running bash on the init file itself provided further explanation:

status_of_proc is a function
status_of_proc () 
{ 
    local pidfile daemon name status OPTIND;
    pidfile=;
    OPTIND=1;
    while getopts p: opt; do
        case "$opt" in 
            p)
                pidfile="$OPTARG"
            ;;
        esac;
    done;
    shift $(($OPTIND - 1));
    if [ -n "$pidfile" ]; then
        pidfile="-p $pidfile";
    fi;
    daemon="$1";
    name="$2";
    status="0";
    pidofproc $pidfile $daemon > /dev/null || status="$?";
    if [ "$status" = 0 ]; then
        log_success_msg "$name is running";
        return 0;
    else
        if [ "$status" = 4 ]; then
            log_failure_msg "could not access PID file for $name";
            return $status;
        else
            log_failure_msg "$name is not running";
            return $status;
        fi;
    fi
}

Yet inserting the same function call into an init script made by myself returned that the function was undefined. So it has nothing to with init scripts being special. Neither is it declared previously in the init script. Around the net I read that it is part of the LSB, but I can't figure out how call it. Will someone please help me figure out how to use this wonderful function?

Rovanion
  • 569
  • 3
  • 6
  • 22

1 Answers1

19

I found that the function was sourced from /lib/lsb/init-functions in the nginx init script. So adding:

. /lib/lsb/init-functions

To my init script solved the problem.

Rovanion
  • 569
  • 3
  • 6
  • 22