Page 1 of 1

[TUT] ManiaPlanet Daemon (CentOS Only)

Posted: 20 Jul 2013, 17:02
by Logistik
Hello

I've created a little init.d script for CentOS (Linux). :yes:
I share it here :)

You just need to create a file at : /etc/init.d/maniaplanet

File Content and edit:

Code: Select all

#!/bin/bash
# maniaplanet Daemon
# chkconfig: 345 20 80
# processname: maniaplanet
#
# Created by Logistik for CentOS 6 Compatibility
# Under What The Fuck Public Licence v2

DAEMON_PATH="[b]YOUR MANIAPLANET DIRECTORY[/b]"
#e.g : "/home/tm2/TM2/"
SERVERTYPE="[b]YOUR SERVERTYPE HERE[/b]"
#e.g : "TMValley", "TMCanyon", "TMStadium"
MATCHSETTING_FILE="[b]YOUR MATCHSETTING PATH HERE[/b]"
#e.g : "MatchSettings/TMValleyA.txt"
DEDICATED_CONFIG_FILE="[b]YOUR DEDICATED CONFIG PATH HERE[/b]"
#e.g : "dedicated.cfg.txt"
DAEMON="./ManiaPlanetServer /title=$SERVERTYPE /game_settings=$MATCHSETTING_FILE /dedicated_cfg=$DEDICATED_CONFIG_FILE"

NAME=maniaplanet
DESC="maniaplanet Daemon"
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME

case "$1" in
start)
	printf "%-50s" "Starting $NAME..."
	cd $DAEMON_PATH
	PID=`$DAEMON > /dev/null 2>&1 & echo $!`
	(( PID = $PID + 1 ))
        if [ -z $PID ]; then
            printf "%s\n" "Fail"
        else
            echo $PID > $PIDFILE
            printf "%s\n" "Ok"
        fi
;;
status)
        printf "%-50s" "Checking $NAME..."
        if [ -f $PIDFILE ]; then
            PID=`cat $PIDFILE`
            if [ -z "`ps axf | grep ${PID} | grep -v grep`" ]; then
                printf "%s\n" "Process dead but pidfile exists"
            else
                echo "Running"
            fi
        else
            printf "%s\n" "Service not running"
        fi
;;
stop)
        printf "%-50s" "Stopping $NAME"
            PID=`cat $PIDFILE`
            cd $DAEMON_PATH
        if [ -f $PIDFILE ]; then
            kill -HUP $PID
            printf "%s\n" "Ok"
            rm -f $PIDFILE
        else
            printf "%s\n" "pidfile not found"
        fi
;;

restart)
  	$0 stop
  	$0 start
;;

*)
        echo "Usage: $0 {status|start|stop|restart}"
        exit 1
esac
Command to Start Maniaplanet:
service maniaplanet start

Command to Stop Maniaplanet:
service maniaplanet stop

Command to restart Maniaplanet:
service maniaplanet restart

Command to check status:
service maniaplanet start

Tip: Your ManiaPlanet Server can start automatically when Dedicated server is started, just type this command in terminal:
chkconfig maniaplanet on


Give me a Thanks if i have helped you ! :)
Levy's Pig :pil

Re: [TUT] ManiaPlanet Daemon (CentOS Only)

Posted: 20 Jul 2013, 17:30
by Xymph
Edit your post to put Code tags around the script, not Quote. That preserves the indenting and eases copy/pasting.

Re: [TUT] ManiaPlanet Daemon (CentOS Only)

Posted: 20 Jul 2013, 18:00
by TMarc
Xymph wrote:Edit your post to put Code tags around the script, not Quote. That preserves the indenting and eases copy/pasting.
Edited :thumbsup:

Re: [TUT] ManiaPlanet Daemon (CentOS Only)

Posted: 20 Jul 2013, 18:59
by Logistik
Thank you Tmarc

Re: [TUT] ManiaPlanet Daemon (CentOS Only)

Posted: 11 Nov 2013, 21:20
by froGHead
Hi,
i try to handle my dedicated TM²Canyon with start and stop commands.
I tried to adapt your CentOS code for my Debian, but it seems to fail with the PID.

In detail I get the server to start on system startup via an init.d-script, an updated header and an

Code: Select all

update-rc.defaults
command. The generated process returns a PID and saves it to the destinated PID-File. But when i login to the shell, i cannot stop/restart since the process ID now is different from the stored one (maybe 1307 stored and 2982 running process).

Anyone can help?
Thanks in advance ... and excuse my cryptic english - i hope someone can understand :mrgreen:

Greetz, frog

Re: [TUT] ManiaPlanet Daemon (CentOS Only)

Posted: 11 Nov 2013, 21:35
by TMarc
Did you try to printout the running processes just from inside your launching shell script, and when you try to stop it?

Code: Select all

ps -aux
or something like that.

Are you detaching the daemon?

Re: [TUT] ManiaPlanet Daemon (CentOS Only)

Posted: 12 Nov 2013, 09:42
by tcq
Try to get the actual running PID number from something like this (google wins :) )

Code: Select all

ps -ef | grep "keyword" | cut -f1 -d" "
OR
ps -ef | grep "KEYWORD" | awk '{print $2}'