[TUT] ManiaPlanet Daemon (CentOS Only)

Moderator: NADEO

Post Reply
Logistik
Posts: 2
Joined: 20 Jul 2013, 16:31

[TUT] ManiaPlanet Daemon (CentOS Only)

Post 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
Last edited by TMarc on 20 Jul 2013, 18:00, edited 1 time in total.
Reason: for scripts, use code instead of quote ;)
User avatar
Xymph
Posts: 1399
Joined: 15 Jun 2010, 20:35
Contact:

Re: [TUT] ManiaPlanet Daemon (CentOS Only)

Post by Xymph »

Edit your post to put Code tags around the script, not Quote. That preserves the indenting and eases copy/pasting.
Developer of XASECO for TMF/TMN ESWC & XASECO2 for TM²: see XAseco.org
Find your way around the Mania community from the TMN ESWC hub, TMF hub, TM² hub, and SM hub
User avatar
TMarc
Posts: 15255
Joined: 05 Apr 2011, 19:10
Location: Europe
Contact:

Re: [TUT] ManiaPlanet Daemon (CentOS Only)

Post 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:
Logistik
Posts: 2
Joined: 20 Jul 2013, 16:31

Re: [TUT] ManiaPlanet Daemon (CentOS Only)

Post by Logistik »

Thank you Tmarc
froGHead
Posts: 4
Joined: 13 Oct 2011, 19:09

Re: [TUT] ManiaPlanet Daemon (CentOS Only)

Post 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
User avatar
TMarc
Posts: 15255
Joined: 05 Apr 2011, 19:10
Location: Europe
Contact:

Re: [TUT] ManiaPlanet Daemon (CentOS Only)

Post 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?
tcq
Posts: 2645
Joined: 15 Jun 2010, 11:02

Re: [TUT] ManiaPlanet Daemon (CentOS Only)

Post 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}'
Post Reply

Return to “Dedicated Server”

Who is online

Users browsing this forum: No registered users and 1 guest