#!/bin/bash
### BEGIN INIT INFO
# Provides:          ocsmanager
# Required-Start:    $remote_fs $network
# Required-Stop:     $remote_fs $network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: OCSManager server
### END INIT INFO

# OCSManager init script for Debian GNU/Linux
#
# Copyright (C) 2012 Inverse inc.
#
# Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
#
# This file is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This file is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; see the file COPYING.  If not, write to
# the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
PATH=/sbin:/bin:/usr/sbin:/usr/bin
WITHOUT_RC_COMPAT=1

# Source function library.
. /etc/init.d/functions

NAME=ocsmanager
DAEMON=/usr/bin/paster
DESC="OCSManager application"

# OCSManager must be run as root, for now
USER=root

CONFFILE=/etc/ocsmanager/$NAME.ini
PIDFILE=/var/run/ocsmanager/$NAME.pid
LOGFILE=/var/log/ocsmanager/$NAME.log
start()
{
        start_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --user "$USER" "$DAEMON" $DAEMON_OPTS
        RETVAL=$?
        return $RETVAL
}

stop()
{
        stop_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user "$USER" "$DAEMON"
        RETVAL=$?
        return $RETVAL
}


restart()
{
        stop
        sleep 1
        start
}

case "$1" in
        start)
                start
                ;;
        stop)
                stop
                ;;
        reload|restart)
                restart
                ;;
        condstop)
                if [ -e "$LOCKFILE" ]; then
                        stop
                fi
                ;;
        condrestart)
                if [ -e "$LOCKFILE" ]; then
                        restart
                fi
                ;;
        condreload)
                if [ -e "$LOCKFILE" ]; then
                        reload
                fi
                ;;
        status)
                status --pidfile "$PIDFILE" --displayname "$DESC" -- "$DAEMON"
                RETVAL=$?
                ;;
        *)
                msg_usage "${0##*/} {start|stop|reload|restart|condstop|condrestart|condreload|status}"
                RETVAL=1


esac

exit $?
