#!/bin/sh
#
# @package      hubzero-expire-sessions
# @file         expire-sessions
# @author       Rick Kennell <kennell@purdue.edu>
# @author       Nicholas J. Kisseberth <nkissebe@purdue.edu>
# @author	David Benham <dbenham@purdue.edu>
# @copyright    Copyright (c) 2005-2014 HUBzero Foundation, LLC.
# @license      http://www.gnu.org/licenses/lgpl-3.0.html LGPLv3
#
# Copyright (c) 2005-2014 HUBzero Foundation, LLC.
#
# This file is part of: The HUBzero(R) Platform for Scientific Collaboration
#
# The HUBzero(R) Platform for Scientific Collaboration (HUBzero) is free
# software: you can redistribute it and/or modify it under the terms of
# the GNU Lesser General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any
# later version.
#
# HUBzero 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 Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# HUBzero is a registered trademark of HUBzero Foundation, LLC.
#
### BEGIN INIT INFO
# Provides:          expire-sessions
# Required-Start:    $remote_fs $local_fs $network $time
# Required-Stop:     $remote_fs $local_fs $network $time
# Should-Start:      $syslog
# Should-Stop:       $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Runs the HUBzero session expiration daemon.
# Description:       Starts/Stops the HUBzero session expiration daemon.
#                     
### END INIT INFO

# Author: Rick Kennell <kennell@purdue.edu>
# Author: Nicholas J. Kisseberth <nkissebe@purdue.edu>
# Author: David Benham <dbenham@purdue.edu>
# Please remove the "Author" lines above and replace them
# with your own name if you copy and modify this script.

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

exec="/usr/sbin/expire-sessions"
prog="expire-sessions"
pidfile="/var/run/expire-sessions.pid"
lockfile=/var/lock/subsys/$prog

start() {
    [ -x $exec ] || exit 5
    echo -n $"Starting $prog: "
    daemon $exec --pidfile=$pidfile
    echo
    retval=$?
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
}

stop() {
    echo -n $"Stopping $prog: "
    killproc $prog
    retval=$?
    echo
    rm -f $pidfile
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
}


restart() {
    stop
    start
}

reload() {
    restart
}

force_reload() {
    restart
}

rh_status() {
    # run checks to determine if the service is running or use generic status
    status $prog
}

rh_status_q() {
    rh_status >/dev/null 2>&1
}

case "$1" in
    start)
        rh_status_q && exit 0
        $1
        ;;
    stop)
        rh_status_q || exit 0
        $1
        ;;
    restart)
        $1
        ;;
    reload)
        rh_status_q || exit 7
        $1
        ;;
    force-reload)
        force_reload
        ;;
    status)
        rh_status
        ;;
    condrestart|try-restart)
        rh_status_q || exit 0
        restart
        ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
        exit 2
esac
exit $?
