#!/sbin/sh
# generated by pp 1.0.0.20210310

svc="sudo_logsrvd"
pidfile="/var/run/sudo/sudo_logsrvd.pid"
config_file="/etc/rc.config.d/sudo_logsrvd"

pp_start () {
    /usr/local/sbin/sudo_logsrvd
}

pp_disabled () {
    test ${RUN_SUDO_LOGSRVD:-0} -eq 0
}

pp_stop () {
    if test ! -s "$pidfile"; then
        echo "Unable to stop $svc (no pid file)"
        return 1
    else
        read pid < "$pidfile"
        if kill -0 "$pid" 2>/dev/null; then
            if kill -15 "$pid"; then
                rm -f "$pidfile"
                return 0
            else
                echo "Unable to stop $svc"
                return 1
            fi
        else
            rm -f "$pidfile"
            return 0
        fi
    fi
}

        pp_running () {
            if test -s "$pidfile"; then
                read pid < "$pidfile" 2>/dev/null
                if test ${pid:-0} -gt 1 && kill -0 "$pid" 2>/dev/null; then
                    # make sure command name matches
                    c="`echo /usr/local/sbin/sudo_logsrvd | sed -e 's: .*::' -e 's:^.*/::'`"
                    pid="`ps -p $pid 2>/dev/null | sed -n \"s/^ *\($pid\) .*$c *$/\1/p\"`"
                    if test -n "$pid"; then
                        return 0
                    fi
                fi
            fi
            return 1
        }

case $1 in
    start_msg) echo "Starting the $svc service";;
    stop_msg)  echo "Stopping the $svc service";;
    start)
            if test -f "$config_file"; then
                . $config_file
            fi
            if pp_disabled; then
                exit 2
            elif pp_running; then
                echo "$svc already running";
                exit 0
            elif pp_start; then
                echo "$svc started";
                # rc(1M) says we should exit 4, but nobody expects it!
                exit 0
            else
                exit 1
            fi;;
    stop)   if pp_stop; then
                echo "$svc stopped";
                exit 0
            else
                exit 1
            fi;;
    *) echo "usage: $0 {start|stop|start_msg|stop_msg}"
       exit 1;;
esac
