#!/bin/bash
### BEGIN INIT INFO
# Provides:          centralproxy
# Required-Start:    $local_fs $remote_fs $network $syslog
# Required-Stop:     $local_fs $remote_fs $network $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts centralproxy module
# Description:       starts centralproxy module using start-stop-daemon
### END INIT INFO

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
NAME=centralproxy
DESC=centralproxy
export CENTRALPROXY_HOME="/opt/bertin/centralproxy"
SCRIPTNAME=/etc/init.d/$NAME

user_exec() {
	su mediacentric -c "$*"
}

d_status() {
	user_exec $CENTRALPROXY_HOME/bin/centralproxy_launcher.sh status
}

d_start() {
	user_exec $CENTRALPROXY_HOME/bin/centralproxy_launcher.sh start
}

d_stop() {
	user_exec $CENTRALPROXY_HOME/bin/centralproxy_launcher.sh stop
}

case $1 in
	"start") d_start;;
	"stop") d_stop;;
	"status") d_status;;
	"restart")
		d_stop
		sleep 1
		d_start
		;;
	"shutdown")
		d_stop 
		;;

	*) echo "usage : $0 <start|stop|status>";;
esac

