#!/bin/sh
##
## '##' is velocity comment -> use $H instead
##
#set( $H = '###' )
$H BEGIN INIT INFO
# Provides: $w_name
# Required-Start: $start_dependencies
# Required-Stop: $stop_dependencies
# Default-Start:  $w_start_levels
# Default-Stop: $w_stop_levels
# Short-Description: yajsw wrapper for $w_long_name
# Description: $w_description
$H END INIT INFO
# config: $w_conf_file
# pidfile: $w_wrapper_pid_file
# apppidfile: $w_app_pid_file
#-----------------------------------------------------------------------------
# YAJSW sh script template.  Suitable for starting and stopping
#  wrapped daemon on POSIX platforms.
#-----------------------------------------------------------------------------

xl_satellite_home=$(dirname $w_conf_file)
w_start_cmd_modified=""
for word in $w_start_cmd; do
    case "$word" in
        java|*/java)
            w_start_cmd_modified="$w_start_cmd_modified $word -Djava.util.logging.config.file=$xl_satellite_home/conf/logging.properties"
            ;;
        *)
            w_start_cmd_modified="$w_start_cmd_modified $word"
            ;;
    esac
done
w_stop_cmd_modified=""
for word in $w_stop_cmd; do
    case "$word" in
        java|*/java)
            w_stop_cmd_modified="$w_stop_cmd_modified $word -Djava.util.logging.config.file=$xl_satellite_home/conf/logging.properties"
            ;;
        *)
            w_stop_cmd_modified="$w_stop_cmd_modified $word"
            ;;
    esac
done

status() {
    if [ -f $w_wrapper_pid_file ]; then
        echo "XL Satellite Server is running."
    else
        echo "XL Satellite Server is not running."
    fi
}

stopit() {
    if [ "$(id -u)" != "0" ]; then
        echo "This action must be run as root" 1>&2
        exit 1
    fi
    echo "Stopping $w_name ..."
	 $w_stop_cmd_modified
}

startit() {
    if [ "$(id -u)" != "0" ]; then
        echo "This action must be run as root" 1>&2
        exit 1
    fi
    echo "Starting $w_name ..."
    sleep 2
    $w_start_cmd_modified
}


case "$1" in
    'start')
        startit
        ;;

    'stop')
        stopit
        ;;

    'restart')
        stopit
        startit
        ;;
        
        
    'force-reload')
        stopit
        startit
        ;;

    'status')
        status
        ;;

    *)
        echo "Usage: $0 { start | stop | restart | status }"
        exit 1
        ;;
esac

exit $?
