#! /bin/sh
### BEGIN INIT INFO
# Provides:          Lightstreamer
# Required-Start:    $network
# Required-Stop:     $network
# Should-Start:
# Should-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Lightstreamer Server
# Description:       Lightstreamer Server, Real-Time Data Push - http://www.lightstreamer.com
### END INIT INFO

set -e

# Lightstreamer specific settings
# LS_HOME=/opt/Lightstreamer
LS_HOME=%LS_HOME%
# LS_USER=lightstreamer
LS_USER=%LS_USER%
# LS_GROUP=lightstreamer
LS_GROUP=%LS_GROUP%

DAEMON="${LS_HOME}/bin/unix-like/LS.sh"
PIDFILE=/var/run/lightstreamer.pid

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="Lightstreamer Server, Real-Time Data Push"
NAME="Lightstreamer"

STOP_TIMEOUT=${STOP_TIMEOUT-10}

test -x $DAEMON || exit 0

. /lib/lsb/init-functions

d_start() {
	start-stop-daemon --start --make-pidfile \
		--pidfile "${PIDFILE}" --oknodo \
		--background --user ${LS_USER} --group ${LS_GROUP} \
		--exec "${DAEMON}" -- run
}

d_stop() {
	start-stop-daemon --stop --pidfile "${PIDFILE}" --retry "${STOP_TIMEOUT}" --oknodo
}


case "$1" in
  start)
	log_daemon_msg "Starting ${DESC}" "${NAME}"
	d_start
	log_end_msg $?
	;;
  stop)
	log_daemon_msg "Stopping ${DESC}" "${NAME}"
	d_stop
	log_end_msg $?
	;;
  restart|force-reload)
	log_daemon_msg "Restarting ${DESC}" "${NAME}"
	d_stop
	d_start
	log_end_msg $?
	;;
  status)
	status_of_proc -p "${PIDFILE}" "${DAEMON}" "${NAME}" && exit 0 || exit $?
	;;
  *)
	echo "Usage: $0 {start|stop|restart|force-reload|status}" >&2
	exit 1
	;;
esac

exit 0

