#!/bin/sh
#
# teeworlds	A retro multiplayer shooter
#
# chkconfig: - 81 29
# description:  Teeworlds is a free online multiplayer game,
#		available for all major operating systems.

# Do not load RH compatibility interface.
WITHOUT_RC_COMPAT=1

# Source function library.
. /etc/init.d/functions

PIDFILE=/var/run/teeworlds/teeworlds-ctf.pid
BINARY=teeworlds_srv_wrapper
RUNAS=_teeworlds
RETVAL=0

SourceIfNotEmpty /etc/sysconfig/teeworlds-ctf

start()
{
	start_daemon --make-pidfile --pidfile "$PIDFILE" --user $RUNAS --displayname teeworlds-ctf \
	-- $BINARY ${0##*/} "$OPTIONS"
	RETVAL=$?
	return $RETVAL
}

stop()
{
	stop_daemon --pidfile "$PIDFILE" --expect-user root --displayname teeworlds-ctf -- su
	RETVAL=$?
	return $RETVAL
}

restart()
{
	stop
	start
}

# See how we were called.
case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	restart|reload)
		restart
		;;
	condstop)
			stop
		;;
	condrestart)
			restart
		;;
	condreload)
			reload
		;;
	status)
		status --pidfile "$PIDFILE" --expect-user root --displayname teeworlds-ctf -- su
		RETVAL=$?
		;;
	*)
		msg_usage "${0##*/} {start|stop|reload|restart|condstop|condrestart|condreload|status}"
		RETVAL=1
esac

exit $RETVAL
