TMN on linux "autostart"

This is the place where you can find everything related to the dedicated server, control scripts and community tools.

Moderators: Pit Crew, TM-Patrol

dragu
wheelbarrow operator
wheelbarrow operator
Posts: 19
Joined: 24 Nov 2006 21:44
Owned TM-games: TMN
Location: Sweden
Contact:

TMN on linux "autostart"

Post by dragu » 03 Aug 2007 21:29

Well tried to post this under the tech support but didn't precisly get any responce there but has anyone worked on a script for init.d on linux so it'll easily kick started when the machine is
started? Have tried to search the forum after it but unfortunetly the search function isn't taking reasoning to init.d and only want to listen to just init which returns a tad to many hits
heh.
Image
Image

User avatar
CavalierDeVache
smooth traffic navigator
smooth traffic navigator
Posts: 191
Joined: 23 May 2006 23:47
Owned TM-games: tmu tmn tms tmo
Location: Yellowstone Valley
Contact:

Re: TMN on linux "autostart"

Post by CavalierDeVache » 04 Aug 2007 01:02

It would be helpful to know what Linux distribution you are talking about since there really is no common standard as to how /init.d is laid out file system wise. The Debian way and the Redhat way are two incompatible examples

I guess if you are only interested in the game server starting automatically at boot and don't really need sys V scripts to reload, restart, etc, the easiest would be to find /rc.local on your system then edit in the full path and command to start your game server there, "/home/userdirectory/tmserverdirectory/./TrackmaniaDedicatedServer.sh". But keep in mind that this will start the game server with root ownership.

dragu
wheelbarrow operator
wheelbarrow operator
Posts: 19
Joined: 24 Nov 2006 21:44
Owned TM-games: TMN
Location: Sweden
Contact:

Re: TMN on linux "autostart"

Post by dragu » 05 Aug 2007 11:13

I'm runing Fedora Core 6 at the moment but will in a few day perhaps upgrade to Fedora Core 7.
But of course it would be handy having things like restart in there as well as it would only be to
type that and it'd would perform it as well heh.
Image
Image

Xymph
Pit Crew
Pit Crew
Posts: 5650
Joined: 19 Aug 2007 12:58
Owned TM-games: TMN, TMU, TMF, TM²
Contact:

Re: TMN on linux "autostart"

Post by Xymph » 19 Aug 2007 13:14

I am running Centos 4.x, i.e. a RedHat-based distro, and have my TMN server running under a user called 'tmn' with group 'tm'. Here are my init.d scripts for starting/stopping the TMN dedicated server and the Aseco/Rasp system.

/etc/init.d/tmnd:

Code: Select all

#!/bin/sh
#
# Starts TMN script
#
# chkconfig: 345 94 06
# description: TMN is the TrackMania Nations server

MYDESC="tmn"
MYPATH=/home/tmn/TMN
MYNAME=tmnd
MYLOCK=$MYNAME
DAEMON=$MYPATH/RunTrackmaniaNations.sh
MYPIDF=/var/run/$MYNAME.pid
MYCMND="$MYPATH/RunTrackmaniaNations.sh"

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

# Make sure the daemon directory is in the front of the path list
PATH=$MYPATH:$PATH

# See how we were called.
case "$1" in
  start)
        # Change to package directory so config paths can be relative
        cd $MYPATH || \
          { echo "$0: Can't cd to $MYPATH" ; exit 1 ; }
        # Make sure the daemon exists
        [ -f $DAEMON ] || \
          { echo "$0: Daemon not found: $DAEMON" ; exit 1 ; }
        # See if we are already running
        # Note: kill -0 _PID_
        #       returns true if process _PID_ is alive and accepting signals.
        [ -f $MYPIDF ] && kill -0 `cat $MYPIDF` 2>/dev/null && \
          { echo "$0: $MYPIDF exists and process is running" ; exit 1 ; }
        echo -n "Starting $MYDESC: "
        echo "$MYNAME "
        su -l -c "$MYCMND" tmn | tee $MYPIDF
        PID=`sed -n 's~.*with pid=\([0-9][0-9]*\).*~\1~;/^[0-9]*$/p' $MYPIDF`
        echo $PID > $MYPIDF
        chown tmn.tm $MYPIDF
        touch /var/lock/subsys/$MYLOCK
        ;;
  stop)
        echo -n "Shutting down $MYDESC: "
        echo -n "$MYNAME "
        killproc TrackManiaServer
        rm -f $MYPIDF
        echo
        rm -f /var/lock/subsys/$MYLOCK
        ;;
  status)
        status $MYNAME
        ;;
  restart)
        $0 stop
        sleep 1
        $0 start
        ;;
  *)
        echo "Usage: $0 {start|stop|status|restart}"
        exit 1
esac

exit 0
with /home/tmn/TMN/RunTrackmaniaNations.sh:

Code: Select all

cd /home/tmn/TMN
./TrackManiaServer /game=nations /internet /game_settings=MatchSettings/Internet/allraces.txt /dedicated_cfg=dedicated.cfg /autoquit
and /etc/init.d/aseco:

Code: Select all

#!/bin/sh
#
# Starts aseco script
#
# chkconfig: 345 94 06
# description: aseco is the TMN server controller.

MYDESC="aseco"
MYPATH=/home/tmn/aseco
MYNAME=aseco
MYLOCK=$MYNAME
DAEMON=$MYPATH/Aseco.sh
MYPIDF=/var/run/$MYNAME.pid
MYCMND="$MYPATH/Aseco.sh"

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

# Make sure the daemon directory is in the front of the path list
PATH=$MYPATH:$PATH

# See how we were called.
case "$1" in
  start)
        # Change to package directory so config paths can be relative
        cd $MYPATH || \
          { echo "$0: Can't cd to $MYPATH" ; exit 1 ; }
        # Make sure the daemon exists
        [ -f $DAEMON ] || \
          { echo "$0: Daemon not found: $DAEMON" ; exit 1 ; }
        # See if we are already running
        # Note: kill -0 _PID_
        #       returns true if process _PID_ is alive and accepting signals.
        [ -f $MYPIDF ] && kill -0 `cat $MYPIDF` 2>/dev/null && \
          { echo "$0: $MYPIDF exists and process is running" ; exit 1 ; }
        echo -n "Starting $MYDESC: "
        echo -n "$MYNAME "
        su -l -c "$MYCMND &" tmn > $MYPIDF
        chown tmn.tm $MYPIDF
        echo
        touch /var/lock/subsys/$MYLOCK
        ;;
  stop)
        echo -n "Shutting down $MYDESC: "
        echo -n "$MYNAME "
        killproc $MYNAME
        rm -f $MYPIDF
        echo
        rm -f /var/lock/subsys/$MYLOCK
        ;;
  status)
        status $MYNAME
        ;;
  restart)
        $0 stop
        sleep 1
        $0 start
        ;;
  *)
        echo "Usage: $0 {start|stop|status|restart}"
        exit 1
esac

exit 0
Hope it helps.
Xymph
Last edited by Xymph on 29 Jan 2008 17:13, edited 2 times in total.
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

dragu
wheelbarrow operator
wheelbarrow operator
Posts: 19
Joined: 24 Nov 2006 21:44
Owned TM-games: TMN
Location: Sweden
Contact:

Re: TMN on linux "autostart"

Post by dragu » 22 Aug 2007 18:12

*bows and salitutes*

Thank you alot for that, it's perfect and precisly what i was out after.
*does a imitational cartwheel of joy*
Image
Image

vatermaniac
pedestrian
pedestrian
Posts: 7
Joined: 18 Nov 2006 09:25
Owned TM-games: TMN,TMU,TMX,TMF
Location: Germany
Contact:

Re: TMN on linux "autostart"

Post by vatermaniac » 24 Sep 2007 11:13

Hey guys,

i found this thread after searching for a solution to start my tmn servers automatically. I'm not sure about that solution because i'm using Debian 4 Etch, so it won't work for me. Could anyone write this script for the Debian Way?

Thx in Advance
VaterManiaC

______

Have a look at: http://die-maniacs.de/

User avatar
Fisch.666
happy cruiser
happy cruiser
Posts: 136
Joined: 18 May 2006 01:13
Owned TM-games: TMU, TMN, TMUF, TMNF
Location: Germany
Contact:

Re: TMN on linux "autostart"

Post by Fisch.666 » 24 Sep 2007 13:14

Hi!

Just use this script, works here on my debian server without a problem:

http://counter-strike.de/content/server/srcds

Xymph
Pit Crew
Pit Crew
Posts: 5650
Joined: 19 Aug 2007 12:58
Owned TM-games: TMN, TMU, TMF, TM²
Contact:

Re: TMN on linux "autostart"

Post by Xymph » 13 Jan 2008 16:05

My /etc/init.d/tmnd script would not always correctly write the server's PID to the /var/run/tmnd.pid file, so I changed the way that's done in the post above.
Just a FYI.
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

hssemichi
highway camper
highway camper
Posts: 1
Joined: 07 May 2008 21:22
Owned TM-games: tmnf

Re: TMN on linux "autostart"

Post by hssemichi » 07 May 2008 21:29

i've modified the scripts above a bit for using tmnf & aseco (using this guide)

running on centos 5, all files chmod 755
my user+group is tmf.tmf, directory is /home/tmf/tmf and /home/tmf/aseco

/etc/init.d/tmnfd

Code: Select all

MYDESC="tmf"
MYPATH=/home/tmf/tmf
MYNAME=tmnfd
MYLOCK=$MYNAME
DAEMON=$MYPATH/RunTrackmaniaNations.sh
MYPIDF=/var/run/$MYNAME.pid
MYCMND="$MYPATH/RunTrackmaniaNations.sh"

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

# Make sure the daemon directory is in the front of the path list
PATH=$MYPATH:$PATH

# See how we were called.
case "$1" in
  start)
        # Change to package directory so config paths can be relative
        cd $MYPATH || \
          { echo "$0: Can't cd to $MYPATH" ; exit 1 ; }
        # Make sure the daemon exists
        [ -f $DAEMON ] || \
          { echo "$0: Daemon not found: $DAEMON" ; exit 1 ; }
        # See if we are already running
        # Note: kill -0 _PID_
        #       returns true if process _PID_ is alive and accepting signals.
        [ -f $MYPIDF ] && kill -0 `cat $MYPIDF` 2>/dev/null && \
          { echo "$0: $MYPIDF exists and process is running" ; exit 1 ; }
        echo -n "Starting $MYDESC: "
        echo "$MYNAME "
        su -l -c "$MYCMND" tmf | tee $MYPIDF
        PID=`sed -n 's~.*with pid=\([0-9][0-9]*\).*~\1~;/^[0-9]*$/p' $MYPIDF`
        echo $PID > $MYPIDF
        chown tmf.tmf $MYPIDF
        touch /var/lock/subsys/$MYLOCK
        ;;
  stop)
        echo -n "Shutting down $MYDESC: "
        echo -n "$MYNAME "
        killproc TrackManiaServer
        rm -f $MYPIDF
        echo
        rm -f /var/lock/subsys/$MYLOCK
        ;;
  status)
        status $MYNAME
        ;;
  restart)
        $0 stop
        sleep 1
        $0 start
        ;;
  *)
        echo "Usage: $0 {start|stop|status|restart}"
        exit 1
esac

exit 0
/home/tmf/tmf/RunTrackmaniaNations.sh

Code: Select all

#!/bin/bash
cd /home/tmf/tmf
./TrackmaniaServer /game_settings=MatchSettings/Nations/NationsBlue.txt /dedicated_cfg=dedicated_cfg.txt
/etc/init.d/aseco

Code: Select all

#!/bin/sh
#
# Starts aseco script
#
# chkconfig: 345 94 06
# description: aseco is the TMF server controller.

MYDESC="aseco"
MYPATH=/home/tmf/aseco
MYNAME=aseco
MYLOCK=$MYNAME
DAEMON=$MYPATH/Aseco.sh
MYPIDF=/var/run/$MYNAME.pid
MYCMND="$MYPATH/Aseco.sh"

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

# Make sure the daemon directory is in the front of the path list
PATH=$MYPATH:$PATH

# See how we were called.
case "$1" in
  start)
        # Change to package directory so config paths can be relative
        cd $MYPATH || \
          { echo "$0: Can't cd to $MYPATH" ; exit 1 ; }
        # Make sure the daemon exists
        [ -f $DAEMON ] || \
          { echo "$0: Daemon not found: $DAEMON" ; exit 1 ; }
        # See if we are already running
        # Note: kill -0 _PID_
        #       returns true if process _PID_ is alive and accepting signals.
        [ -f $MYPIDF ] && kill -0 `cat $MYPIDF` 2>/dev/null && \
          { echo "$0: $MYPIDF exists and process is running" ; exit 1 ; }
        echo -n "Starting $MYDESC: "
        echo -n "$MYNAME "
        su -l -c "$MYCMND &" tmf > $MYPIDF
        chown tmf.tmf $MYPIDF
        echo
        touch /var/lock/subsys/$MYLOCK
        ;;
  stop)
        echo -n "Shutting down $MYDESC: "
        echo -n "$MYNAME "
        killproc $MYNAME
        rm -f $MYPIDF
        echo
        rm -f /var/lock/subsys/$MYLOCK
        ;;
  status)
        status $MYNAME
        ;;
  restart)
        $0 stop
        sleep 1
        $0 start
        ;;
  *)
        echo "Usage: $0 {start|stop|status|restart}"
        exit 1
esac

exit 0
works just fine ;-)

Xymph
Pit Crew
Pit Crew
Posts: 5650
Joined: 19 Aug 2007 12:58
Owned TM-games: TMN, TMU, TMF, TM²
Contact:

Re: TMN on linux "autostart"

Post by Xymph » 07 May 2008 21:41

hssemichi wrote:i've modified the scripts above a bit for using tmnf & aseco (using this guide)
[...]
works just fine ;-)
Oh good. I did that at the start of the alpha testing but forgot to post them. Thanks. :thumbsup:
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
www.22ndsas.org.uk
happy cruiser
happy cruiser
Posts: 110
Joined: 08 Jun 2006 17:17
Owned TM-games: Orig, Sunrise, Tmnuf
Location: East Coast (UK)
Contact:

Re: TMN on linux "autostart"

Post by www.22ndsas.org.uk » 02 Jul 2008 14:06

Would these work on fedora core 8 ??

Xymph
Pit Crew
Pit Crew
Posts: 5650
Joined: 19 Aug 2007 12:58
Owned TM-games: TMN, TMU, TMF, TM²
Contact:

Re: TMN on linux "autostart"

Post by Xymph » 02 Jul 2008 16:38

www.22ndsas.org.uk wrote:Would these work on fedora core 8 ??
Yeah, any RedHat-spinoff should work, I used them on CentOS myself, so just give them a try. Debian and FreeBSD probably require tweaks.
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

dragu
wheelbarrow operator
wheelbarrow operator
Posts: 19
Joined: 24 Nov 2006 21:44
Owned TM-games: TMN
Location: Sweden
Contact:

Re: TMN on linux "autostart"

Post by dragu » 05 Jul 2008 12:27

Aye i can vouch for that as well with consideration that it is Fedora 8 which my server is running on.
But as Xymph said , every RedHat spinoff should be possible to run this script as they are based
more or less on the very same code.
Image
Image

Xymph
Pit Crew
Pit Crew
Posts: 5650
Joined: 19 Aug 2007 12:58
Owned TM-games: TMN, TMU, TMF, TM²
Contact:

Re: TMN on linux "autostart"

Post by Xymph » 10 Jul 2008 10:02

I belatedly discovered that the 'status' option for these scripts doesn't work, due to the fact that the startup scripts call wrapper scripts which in turn call the dedicated server and XAseco PHP system. Here are updated versions to correct that:

/home/tmf/TMF/RunTrackmaniaForever.sh :

Code: Select all

cd /home/tmf/TMF
./TrackmaniaServerF /game_settings=MatchSettings/stadium_all.txt /dedicated_cfg=dedicated_cfg.txt
/etc/init.d/tmfd :

Code: Select all

#!/bin/sh
#
# Starts TMF script
#
# chkconfig: 345 94 06
# description: TMF is the TrackMania Forever server

MYDESC="tmf"
MYPATH=/home/tmf/TMF
MYNAME=tmfd
MYPROC=TrackmaniaServerF
MYLOCK=$MYNAME
DAEMON=$MYPATH/RunTrackmaniaForever.sh
MYPIDF=/var/run/$MYNAME.pid
MYCMND="$MYPATH/RunTrackmaniaForever.sh"

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

# Make sure the daemon directory is in the front of the path list
PATH=$MYPATH:$PATH

# See how we were called.
case "$1" in
  start)
        # Change to package directory so config paths can be relative
        cd $MYPATH || \
          { echo "$0: Can't cd to $MYPATH" ; exit 1 ; }
        # Make sure the daemon exists
        [ -f $DAEMON ] || \
          { echo "$0: Daemon not found: $DAEMON" ; exit 1 ; }
        # See if we are already running
        # Note: kill -0 _PID_
        #       returns true if process _PID_ is alive and accepting signals.
        [ -f $MYPIDF ] && kill -0 `cat $MYPIDF` 2>/dev/null && \
          { echo "$0: $MYPIDF exists and process is running" ; exit 1 ; }
        echo -n "Starting $MYDESC: "
        echo "$MYNAME "
        su -l -c "$MYCMND" tmf | tee $MYPIDF
        PID=`sed -n 's~.*with pid=\([0-9][0-9]*\).*~\1~;/^[0-9]*$/p' $MYPIDF`
        echo $PID > $MYPIDF
        chown tmf.tm $MYPIDF
        touch /var/lock/subsys/$MYLOCK
        ;;
  stop)
        echo -n "Shutting down $MYDESC: "
        echo -n "$MYNAME "
        killproc $MYNAME
        rm -f $MYPIDF
        echo
        rm -f /var/lock/subsys/$MYLOCK
        ;;
  status)
        status $MYPROC
        ;;
  restart)
        $0 stop
        sleep 1
        $0 start
        ;;
  *)
        echo "Usage: $0 {start|stop|status|restart}"
        exit 1
esac

exit 0
/home/tmf/aseco/Aseco.sh :

Code: Select all

cd /home/tmf/aseco
php aseco.php TMF </dev/null >aseco.log 2>&1 &
echo $!
/etc/init.d/asecof :

Code: Select all

#!/bin/sh
#
# Starts asecof script
#
# chkconfig: 345 94 06
# description: asecof is the TMF server controller

MYDESC="asecof"
MYPATH=/home/tmf/aseco
MYNAME=asecof
MYPROC="aseco.php TMF"
MYLOCK=$MYNAME
DAEMON=$MYPATH/Aseco.sh
MYPIDF=/var/run/$MYNAME.pid
MYCMND="$MYPATH/Aseco.sh"

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

# Make sure the daemon directory is in the front of the path list
PATH=$MYPATH:$PATH

# See how we were called.
case "$1" in
  start)
        # Change to package directory so config paths can be relative
        cd $MYPATH || \
          { echo "$0: Can't cd to $MYPATH" ; exit 1 ; }
        # Make sure the daemon exists
        [ -f $DAEMON ] || \
          { echo "$0: Daemon not found: $DAEMON" ; exit 1 ; }
        # See if we are already running
        # Note: kill -0 _PID_
        #       returns true if process _PID_ is alive and accepting signals.
        [ -f $MYPIDF ] && kill -0 `cat $MYPIDF` 2>/dev/null && \
          { echo "$0: $MYPIDF exists and process is running" ; exit 1 ; }
        echo -n "Starting $MYDESC: "
        echo -n "$MYNAME "
        su -l -c "$MYCMND &" tmf > $MYPIDF
        chown tmf.tm $MYPIDF
        echo
        touch /var/lock/subsys/$MYLOCK
        ;;
  stop)
        echo -n "Shutting down $MYDESC: "
        echo -n "$MYNAME "
        killproc $MYNAME
        rm -f $MYPIDF
        echo
        rm -f /var/lock/subsys/$MYLOCK
        ;;
  status)
        pid=`ps ax | grep "$MYPROC\>" | grep -v grep | awk '{print $1}'`
        if [ -n "$pid" ]; then
                echo "$MYPROC (pid $pid) is running..."
                exit 0
        fi
        status $MYNAME
        ;;
  restart)
        $0 stop
        sleep 1
        $0 start
        ;;
  *)
        echo "Usage: $0 {start|stop|status|restart}"
        exit 1
esac

exit 0
A few things are important to note:

I have the dedicated in /home/tmf/TMF with the executable renamed to TrackmaniaServerF, to distinguish it from the TMN TrackmaniaServer executable that I still have running on the same machine. You can keep the original TrackmaniaServer name in both the RunTrackmaniaForever.sh and /etc/init.d/tmfd scripts, as long as that executable name is unique (in case of running multiple TMN and/or TMF servers) and is the same in both scripts.

Similarly, both the Aseco.sh and /etc/init.d/asecof scripts refer to XAseco with "aseco.php TMF", where "TMF" serves only one purpose: identifying which "php aseco.php" script belongs to which dedicated server. Again, the "TMF" can be anything as long as it's unique and the same in both scripts, and the same goes for the "asecof" script name itself.

From that follows how to start a second TMF server on the same box, the scripts then become:

/home/tmf2/TMF/RunTrackmaniaForever.sh :

Code: Select all

cd /home/tmf2/TMF
./TrackmaniaServerF2 /game_settings=MatchSettings/allraces.txt /dedicated_cfg=dedicated_cfg.txt
/etc/init.d/tmf2d :

Code: Select all

#!/bin/sh
#
# Starts TMF2 script
#
# chkconfig: 345 94 06
# description: TMF2 is the TrackMania Forever server 2

MYDESC="tmf2"
MYPATH=/home/tmf2/TMF
MYNAME=tmf2d
MYPROC=TrackmaniaServerF2
MYLOCK=$MYNAME
DAEMON=$MYPATH/RunTrackmaniaForever.sh
MYPIDF=/var/run/$MYNAME.pid
MYCMND="$MYPATH/RunTrackmaniaForever.sh"
[...same as above...]
/home/tmf2/aseco/Aseco.sh :

Code: Select all

cd /home/tmf2/aseco
php aseco.php TMF2 </dev/null >aseco.log 2>&1 &
echo $!
/etc/init.d/asecof2 :

Code: Select all

#!/bin/sh
#
# Starts asecof2 script
#
# chkconfig: 345 94 06
# description: asecof2 is the TMF server controller 2

MYDESC="asecof2"
MYPATH=/home/tmf2/aseco
MYNAME=asecof2
MYPROC="aseco.php TMF2"
MYLOCK=$MYNAME
DAEMON=$MYPATH/Aseco.sh
MYPIDF=/var/run/$MYNAME.pid
MYCMND="$MYPATH/Aseco.sh"
[...same as above...]
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
norico
wheelbarrow operator
wheelbarrow operator
Posts: 23
Joined: 24 Nov 2008 19:35
Owned TM-games: TM(U)/ TM²

Re: TMN on linux "autostart"

Post by norico » 24 Nov 2008 19:37

Status dont wok on my server !

Replace status code with

Code: Select all

  status)
		if [ -e $MYNAME.pid ]; then
			echo "the server seems to be running"
			exit 0
		else
			echo "the server seems to be stopped"
			exit 3
		fi
        ;;


Post Reply