#!/bin/sh

### BEGIN INIT INFO
# Provides:          gatling
# Required-Start:    $network $remote_fs
# Required-Stop:     $network $remote_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Gatling
# Description:       Gatling - High performance webserver and fileserver
### END INIT INFO

. /lib/lsb/init-functions

LOGFILE=/var/log/gatling.log
DAEMON=tlsgatling

# Include defaults if available
if [ -f /etc/default/gatling ] ; then
	. /etc/default/gatling
fi

start() {
	if [ "$START_DAEMON" != "YES" ] ; then
		log_warning_msg "Not starting Gatling (edit /etc/default/gatling to enable)"
		exit 0 ;
	fi
	
	log_daemon_msg "Starting Gatling" "$DAEMON"
	start-stop-daemon --pidfile /var/run/gatling.pid --make-pidfile \
		--background --exec /sbin/logsave --start -- \
		-a /var/log/gatling.log /usr/bin/tlsgatling $DAEMON_OPTS
	log_end_msg 0
}

stop() {
	log_daemon_msg "Stopping Gatling" "$DAEMON"
	start-stop-daemon --oknodo --pidfile /var/run/gatling.pid --stop
	log_end_msg 0
}

restart() {
	stop
	start
}

case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  restart|force-reload)
	restart
	;;
  *)
	log_daemon_msg "Usage: $0 {start|stop|restart}"
	exit 1
esac
