File xonotic.init of Package xonotic

#!/bin/sh
#set -x
# $Id: xonotic,v 0.1 Martin Caj <mcaj@suse.cz>
#
# xonotic: Starts, Stops and  Check status the service
#
# chkconfig: 2345 40 60
# description: Server with dedicated xonotic running as services unter the specific user.
# processname: xonotic-dedicated
# pidfile: /var/run/xonotic-dedicated.pid
# check $PID
#

### BEGIN INIT INFO
# Provides:		xonotix
# Required-Start:    	$local_fs $remote_fs $time 
# Required-Stop:     	$local_fs $remote_fs
# Should-Start:
# Should-Stop:
# Default-Start:	2 3 5
# Default-Stop:		0 1 6
# Short-Description:	Xonotic dedicated server
# Description:		Server with dedicated xonotic running as services unter the specific user.
### END INIT INFO

# Source function library.

. /etc/rc.status
rc_reset

. /lib/lsb/init-functions

# Local variables:
DAEMON="$(which xonotic-dedicated)"
PID="/var/run/xonotic-dedicated.pid"
PROC="$(basename $DAEMON)"
RETVAL=0
XONOTIC_USER="xonotic"
XONOTIC_GROUP="xonotic"
XONOTIC_HOME="$(grep ^xonotic /etc/passwd|cut -d":" -f6)"

if ! [ $DAEMON ] ; then
	echo "ERROR: DEAMON "$DAEMON" not found!"
	exit 1
fi

if ! [ $XONOTIC_HOME ] ; then
	echo "ERROR: the home for user xonotic not found in /etc/passwd."
	exit 1
fi


start() {
	# Start daemons.
	if checkproc -k -p "$PID" "$DAEMON" ; then
                echo ""$PROC" already started. Not starting."
                exit 0
        fi  
        if [ -e $PID ] ; then
                echo "Removing stale PID file $PID."
                rm -f $PID
        fi  
        echo -n "Starting Xonotic daemon"

# user is not working yes	
#	startproc -f -p "$PID" -e "$DAEMON" -u "$XONOTIC_USER" -g "$XONOTIC_GROUP" 
	startproc -f -p "$PID" -e "$DAEMON" -u "$XONOTIC_USER" -g "$XONOTIC_GROUP" 
	return "$?"
}

stop() {
	# Stop daemons.
	echo -n $"Shutting down "$DAEMON": "
	killproc "$PROC"
	if [ $? -eq 0 ]; then
		rm -f "$PID"
		return 0
	else
		echo ""$PROC" was not Shutdown correctly, please check ps." 
		return 3
	fi
}

restart() {
	$0 stop
	$0 start
	rc_status
}


status() {
	echo "Checking status of the $DAEMON:"
	if [ -e $PID ] ; then
		echo
		echo "$DAEMON is running:"
		return 0
	else
		checkproc -k -p $PID $DAEMON
        		if [ $? -eq 7 ]; then
                		return 3
        		fi
	fi
}


# See how we were called.
case "$1" in
  start)
	start
	rc_status -v
	;;
  stop)
	stop
	rc_status -v
	;;
  restart)
	restart
	;;
  reload)
	reload
	rc_status -v
	;;
  condrestart)
	echo "The condrestart calls :"
	[ -f "$PID" ] && restart || :
	rc_status -v
	;;
  status)
	status
	rc_status -v
	;;
  *)
	echo "Usage: "$PROC" {start|stop|restart|condrestart|status}"
	exit 1
esac

exit $?