# Function: statusproc
#  Purpose: This function prints status of a particular daemon to stdout
#    Usage: statusproc [-p pidfile] pathname
#   Inputs: -p pidfile, use the specified pidfile instead of pidof
#            must be fully qualififed
#  Outputs: Status printed
function statusproc {
    local program=""
    local pidfile=""
    local pidlist=""
    local retval=""
    # Process arguments
    while [[ $# -gt 0 ]]; do
        case "${1}" in
            -p) shift; pidfile="${1}" ;;
            *)    program="${1}" ;;
        esac
        shift
    done
    # If a PID file is not specified, make one
    test -z "${pidfile}" && pidfile="/var/run/${program}.pid"
    # If a pid file exists and is readable, use it.
    if [[ -r "${pidfile}" ]];then
        pidlist=$(pidofproc -p "${pidfile}" "${program}")
    else
        pidlist=$(pidofproc "${program}")
    fi
    retval="${?}"
    pidlist="${pidlist% }" # Trim trailing blanks
    case ${retval} in
        0)    echo -e -n "${INFO}${program} is running with Process ID(s) ${pidlist}${NORMAL}" ;;         1)    echo -e -n "${WARNING}${program} is not running but ${pidfile} exists${NORMAL}" ;;
        3)    echo -e -n "${INFO}${program} is not running${NORMAL}" ;;
        *)  echo -e -n "${WARNING}Barfed!${NORMAL}" ;;
    esac
}

Tested

Test Function: statusproc: Start
    pidofproc /usr/sbin/dhcpcd: Pidlist: [479] Status: [0]
    /usr/sbin/dhcpcd is running with Process ID(s) 479
    pidofproc dhcpcd: Pidlist: [479] Status: [0]
    dhcpcd is running with Process ID(s) 479
    pidofproc -p /var/run/dhcpcd.pid dhcpcd: Pidlist: [479] Status: [0]
    dhcpcd is running with Process ID(s) 479
    pidofproc -p barf.pid /usr/sbin/dhcpcd: Pidlist: [479] Status: [0]
    /usr/sbin/dhcpcd is running with Process ID(s) 479
    pidofproc /usr/sbin/barf: Pidlist: [] Status: [3]
    /usr/sbin/barf is not running
    pidofproc /bin/ls: Pidlist: [] Status: [3]
    /bin/ls is not running

    pidofproc /bin/ls: Pidlist: [] Status: [1]
    /bin/ls is not running but /var/run//bin/ls.pid exists
    pidofproc -p /var/run/ls.pid /bin/ls: Pidlist: [] Status: [1]
    /bin/ls is not running but /var/run/ls.pid exists
Test Function: statusproc: Complete


--
http://lists.linuxfromscratch.org/listinfo/lfs-support
FAQ: http://www.linuxfromscratch.org/blfs/faq.html
Unsubscribe: See the above information page

Do not top post on this list.

A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing in e-mail?

http://en.wikipedia.org/wiki/Posting_style

Reply via email to