#!/bin/bash
#
# UNICORE Gateway

### BEGIN INIT INFO
# Provides:          unicore-gateway
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start daemon at boot time
# Description:       UNICORE gateway
### END INIT INFO

# Source function library.
. /lib/lsb/init-functions

NAME="UNICORE gateway"

#This must be equal to this file name
SERVICE=unicore-gateway
UNICORE_USER=unicore
START=/usr/sbin/unicore-gateway-start.sh
STOP=/usr/sbin/unicore-gateway-stop.sh
LASTPID=/var/run/unicore/gateway.pid

[ -f /etc/default/$SERVICE ] && . /etc/default/$SERVICE

start() {
	log_daemon_msg "Starting $NAME"
	start-stop-daemon --start --chuid $UNICORE_USER --exec "$START"
	RETVAL=$?
	[ $RETVAL -eq 0 ] && touch "/var/lock/$SERVICE"
	log_end_msg $RETVAL	
	echo
	return $RETVAL
}
stop() {
	 log_daemon_msg "Stopping $NAME"
	 echo
	 su $UNICORE_USER -p "$STOP"
	 log_end_msg $?
	 rm -f "/var/lock/$SERVICE"
	 echo
}
status() {
	if [ -a "$LASTPID" ]; then
                 status_of_proc -p "$LASTPID" "$SERVICE"
        else
                 log_failure_msg "$SERVICE is not running"
        fi

}

# See how we were called.
case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  status)
	status
	;;
  restart)
	stop
	start
	;;
  force-reload)
	;;
  *)
	echo $"Usage: $0 {start|stop|status|restart|force-reload|help}"
	exit 1
esac

exit $RETVAL
