#! /bin/sh
### BEGIN INIT INFO
# Provides:          rozofs-geomgr
# Required-Start:    $network $local_fs $remote_fs
# Required-Stop:     $remote_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Geo-replication manager.
# Description:
### END INIT INFO

# Author: Fizians S.A.S. <devel@rozofs.com>

PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC=geomgr             # Introduce a short description here
NAME=geomgr             # Introduce the short server's name here
DAEMON=/usr/bin/geomgr  # Introduce the server's location here
DAEMON_ARGS=""          # Arguments to run the daemon with
PIDFILE=/var/run/launcher_${NAME}.pid
SCRIPTNAME=$0
LAUNCHER=/usr/bin/rozolauncher
. /lib/init/vars.sh

. /lib/lsb/init-functions

SCRIPTNAME=/etc/init.d/$NAME

# Exit if required binaries are missing

# Exit if the package is not installed
[ -x $DAEMON ] || exit 0
[ -x $LAUNCHER ] || exit 0

# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh

# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions

# Enable core files
ulimit -c unlimited


status () {

    if [ -f $PIDFILE ];
    then 
      return 0 
    else
      return 3
    fi
}
#
# Function that starts the daemon/service
#
do_start()
{
    $LAUNCHER start $PIDFILE $DAEMON $DAEMON_ARGS &
    return 0
}

#
# Function that stops the daemon/service
#
do_stop()
{
    $LAUNCHER stop $PIDFILE
    return 0
}


case "$1" in
  start|reload|restart|force-reload)
    [ "$VERBOSE" != no ] && log_daemon_msg "$1 $DESC " "$NAME"
    do_start
    case "$?" in
        0) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
        1) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
    esac
  ;;
  stop)
    [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
    do_stop
    case "$?" in
        0) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
        1) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
    esac
    ;;
  status) status;;

  *)
    echo "Usage: $SCRIPTNAME {start|stop|status|restart}" >&2
    exit 3
    ;;
esac

:
