#!/bin/sh
#
# scheduler: Startup Ahsay Online Backup Manager Scheduler
#
# chkconfig: 35 99 99
#
### BEGIN INIT INFO
# Provides:          scheduler
# Required-Start:    $local_fs $remote_fs $syslog 
# Required-Stop:     $local_fs $remote_fs $syslog 
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start daemon at boot time
# Description:       Running scheduler on system startup
### END INIT INFO

case "$1" in
'start')
        echo "Starting Ahsay Online Backup Manager Scheduler"
        APP_HOME=@sed.product.home@
        if [ -f "${APP_HOME}/bin/Scheduler.sh" ]; then
            USER_ID=`id -u`
            if [ ${USER_ID} -ne 0 ]; then
                echo "Current user (UID=${USER_ID}) is not root, start obmscheduler with su root"
                su root -c "nohup sh \"${APP_HOME}/bin/Scheduler.sh\" > /dev/null"
            else
                echo "Current user (UID=${USER_ID}) is root, start obmscheduler directly"
                nohup sh "${APP_HOME}/bin/Scheduler.sh" > /dev/null
            fi
        fi
        echo ""
        ;;
'stop')
        APP_HOME=@sed.product.home@
        if [ -f "${APP_HOME}/bin/StopScheduler.sh" ]; then
        sh "${APP_HOME}/bin/StopScheduler.sh"
        fi
        ;;
*)
        echo "Usage: $0 { start | stop }"
        ;;
esac

