#! /bin/sh
#
# chkconfig: - 92 9
# description: pnfs startup script
#
#  $Id$
#
if [ -r /etc/rc.d/init.d/functions ] ; then
    . /etc/rc.d/init.d/functions
fi

RETVAL=0
prog="pnfs_wrapper"


PNFS=/opt/pnfs/bin/pnfs
POSTGRES_CHECK=/opt/pnfs/tools/postgres_check

start() {
    echo -n $"$prog: checking postgresql:"
    $POSTGRES_CHECK
    RETVAL=$?
    [ $RETVAL -eq 0 ] && success || failure
    echo
    [ $RETVAL -eq 0 ]
    if [ ! $RETVAL -eq 0 ]; then
	return $RETVAL
    fi
    $PNFS start
    RETVAL=$?
    return $RETVAL
}

stop() {
    echo -n $"Shutting down $prog: "
    $PNFS stop
    RETVAL=$?
    echo
    [ $RETVAL -eq 0 ]
    return $RETVAL
}

case "$1" in
    start)
	start
	;;
    stop)
	stop
	;;
	*)
	$PNFS $1
        RETVAL=$?
	;;
esac

exit $RETVAL
