#! /bin/sh
#
# wesnothd	Wesnoth server
#
# chkconfig:	345 98 02
#
# description:	This is a 'Battle for Wesnoth' daemon 
#
#		Modified for ALTLinux
#		by Gleb Stiblo <errandir@gmail.com>
#

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# Do not load RH compatibility interface.
WITHOUT_RC_COMPAT=1

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

DAEMON=/usr/sbin/wesnothd
NAME=wesnothd
USER=_wesnothd
LOCKFILE=/var/lock/subsys/wesnothd
PIDFILE=/var/run/wesnothd.pid
SOCKETDIR=/var/run/wesnothd
RETVAL=0

test -x $DAEMON || exit 0

WESNOTHD_OPTIONS=
# Include wesnoth defaults if available
SourceIfNotEmpty /etc/sysconfig/wesnoth || exit 1


start()
{
	# for /var/run on tmpfs
	/bin/mkdir -p $SOCKETDIR/
	/bin/chown -R $USER.$USER $SOCKETDIR/
	start_daemon --make-pidfile $PIDFILE --pidfile $PIDFILE --name $NAME --user $USER -- $DAEMON $WESNOTHD_OPTIONS
	RETVAL=$?
	return $RETVAL
}

stop()
{
	stop_daemon --pidfile $PIDFILE --name $NAME -- $DAEMON 

	RETVAL=$?
	return $RETVAL
}

restart()
{
	stop
	sleep 1
	start
}

# See how we were called.
case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  restart)
	restart
	;;
  reload)
	;;
  condstop)
	if [ -e "$LOCKFILE" ]; then
	    stop
	fi
	;;
  condrestart)
	if [ -e "$LOCKFILE" ]; then
	    restart
	fi
	;;
  condreload)
	;;
  status)
	status --pidfile "$PIDFILE" -- $DAEMON
	RETVAL=$?
	;;
  *)
	msg_usage "${0##*/} {start|stop|restart|reload|condstop|condrestart|condreload|status}"
	RETVAL=1
esac

exit $RETVAL
