#!/bin/sh
#
### BEGIN INIT INFO
# Provides: vpdupdater
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Should-Start:
# Required-Start:
# Required-Stop:
# Short-Description: Start and stop the VPD database manager
# Description: vpdupdater starts the vpdupdate daemon which is responsible
#              for keeping the VPD database up to date for commands such
#              as lsvpd.
### END INIT INFO
#
# The fields below are left around for legacy tools (will remove later).
#
# chkconfig: 2345 65 35
# description: vpdupdater is the VPD database manager
# processname: vpdupdate
# pidfile: /var/run/vpdupdate.pid

. /etc/init.d/functions

RETVAL=0

prog=vpdupdate
vpdupdate=/usr/sbin/vpdupdate
lockfile=/var/lock/subsys/vpdupdater
pidfile=/var/run/vpdupdate.pid
statedir=/var/lib/lsvpd

start() {
    [ -x $vpdupdate ] || return 5

    pidofproc $prog >/dev/null 2>&1
    RETVAL=$?
    [ $RETVAL -eq 0 ] && return $RETVAL

    echo -n $"Starting $prog: "
    daemon $vpdupdate 2>/dev/null
    RETVAL=$?
    echo
    [ $RETVAL = 0 ] && touch $lockfile
    return $RETVAL
}

stop() {
    pidofproc $prog >/dev/null 2>&1
    if [ $? -ne 0 ]; then
        RETVAL=7
        return $RETVAL
    fi

    echo -n $"Shutting down $prog: "
    $vpdupdate -a
    RETVAL=$?

    pidofproc $prog >/dev/null 2>&1
    if [ $? -eq 3 ]; then
        killproc $prog
        RETVAL=$?
    fi

    [ $RETVAL = 0 ] && success || failure
    echo
    [ $RETVAL = 0 ] && rm -f $lockfile
    return $RETVAL
}

if [ $# -gt 1 ]; then
    RETVAL=2
    exit $RETVAL
fi

case "$1" in
    start)
        start
        RETVAL=$?
        ;;
    stop)
        stop
        RETVAL=$?
        ;;
    restart|force-reload)
        stop ; start
        RETVAL=$?
        ;;
    try-restart|reload)
        RETVAL=3
        ;;
    condrestart)
        if [ -f $lockfile ]; then
            stop ; start
            RETVAL=$?
        fi
        ;;
    configtest)
        RETVAL=3
        ;;
    status)
        status $vpdupdate
        RETVAL=$?
        ;;
    *)
        echo $"Usage: $0 {start|stop|restart|condrestart|status}"
        RETVAL=3
        ;;
esac

exit $RETVAL
