#!/bin/sh
#
### BEGIN INIT INFO
# Provides:          pvfs2-server
# Required-Start:    $remote_fs $local_fs $syslog
# Required-Stop:     $remote_fs $local_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start pvfs2 at boot time.
# Description:       Enable service provided by pvfs2.
### END INIT INFO
#
#
# chkconfig: 345 35 55
# Source function library.
#
#. /etc/rc.d/init.d/functions
. /lib/lsb/init-functions
#LD_LIBRARY_PATH=/usr/local/BerkeleyDB.6.0/lib:$LD_LIBRARY_PATH
#export LD_LIBRARY_PATH
# set these if you want to hard code the location of the config files:
PVFS2_FS_CONF=/etc/pvfs2-fs.conf
# override this if your server binary resides elsewhere
PVFS2SERVER=/opt/pvfs2/sbin/pvfs2-server
# override this if you want servers to automatically pick a conf file,
#   but you just need to specify what directory they are in
PVFS2_CONF_PATH=/etc
# the server will record its PID in this file
#PVFS2_PIDFILE=/var/run/pvfs2.pid
#
# verify presence of server binary
if ! [ -x ${PVFS2SERVER} ]; then
    echo "Erro: não foi possível encontrar o executável ${PVFS2SERVER}"
    exit 1
fi

# look for fs conf
if test "x$PVFS2_FS_CONF" = x
then
    PVFS2_FS_CONF=${PVFS2_CONF_PATH}/pvfs2-fs.conf
fi

if ! [ -r ${PVFS2_FS_CONF} ]; then
    echo "Erro: não foi possível ler o arquivo ${PVFS2_FS_CONF}"
    exit 1
fi

# See how we were called.
case "$1" in
    start)
        echo "Iniciando PVFS2..."
        /opt/pvfs2/sbin/pvfs2-server ${PVFS2_FS_CONF}
        echo "Feito."
        ;;
    stop)
        echo "Parando PVFS2..."
        killproc /opt/pvfs2/sbin/pvfs2-server
        echo "Feito."
        ;;
    status)
        echo "Iniciando a verificação... se quiser parar tecle ctrl+c."
        /opt/pvfs2/bin/pvfs2-check-server -h $(hostname) -f pvfs2-fs -n tcp -p 3334
        echo "Feito."
        ;;
    restart)
        $0 stop
        # give server time to die cleanly
        sleep 2
        $0 start
        ;;
    *)
        echo "Use o comando $0 seguido de uma dessas opções: {start|stop|status|restart}"
        exit 1
esac
exit 0
