#! /bin/sh
#
# chkconfig: - 85 15
# description:  Luanti multiplayer server
# processname: luantiserver
# config: /etc/luanti/default.conf
# config: /etc/sysconfig/luanti/default.conf
#
### BEGIN INIT INFO
# Provides:          luanti-server
# Required-Start:    $remote_fs $network
# Required-Stop:     $remote_fs $network
# Default-Start:     3 5
# Default-Stop:      0 1 6
# Short-Description: Start luanti network game server
# Description:       dedicated game server for Luanti
### END INIT INFO

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

# Check that networking is up.
. /etc/sysconfig/network

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

if [ "$NETWORKING" = "no" ]
then
        exit 0
fi

RETVAL=0
prog="luantiserver"
user="luanti"
lockfile=${LOCKFILE-/var/lock/subsys/luanti}
configfile="/etc/luanti/default.conf"
mapdir="/var/lib/luanti/default"
OPTS="--quiet --config ${configfile} --port $PORT --map-dir ${mapdir} &"

start () {
	echo -n $"Starting $prog: "
	daemon --user ${user} ${prog} ${OPTS}
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && touch ${lockfile}
}
stop () {
	echo -n $"Stopping $prog: "
	killproc $prog -HUP
	RETVAL=$?
	echo
	if [ $RETVAL -eq 0 ] ; then
		rm -f ${lockfile}
	fi
}

restart () {
        stop
        start
}

# See how we were called.
case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  status)
	status luantiserver
	RETVAL=$?
	;;
  restart)
	restart
	;;
  condrestart|try-restart)
	[ -f ${lockfile} ] && restart || :
	;;
  *)
	echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart}"
	RETVAL=2
        ;;
esac

exit $RETVAL
