Startup Script ubuntu server

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

Moderators: Pit Crew, TM-Patrol

Post Reply
penguisher
pedestrian
pedestrian
Posts: 12
Joined: 15 Oct 2009 15:11
Owned TM-games: TMNF

Startup Script ubuntu server

Post by penguisher » 16 Oct 2009 12:49

Hello everyone,

I am looking for a working startup script for ubuntu, I tried several startup scripts but they didn't work for me.

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

Re: Startup Script ubuntu server

Post by Xymph » 16 Oct 2009 15:02

penguisher wrote:I am looking for a working startup script for ubuntu, I tried several startup scripts but they didn't work for me.
To start up an Ubuntu server, press the power button. :wink:

If, on the other hand, you mean starting a dedicated TM server under Ubuntu, it would be useful to mention exactly which scripts you tried and exactly why they didn't work.
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

penguisher
pedestrian
pedestrian
Posts: 12
Joined: 15 Oct 2009 15:11
Owned TM-games: TMNF

Re: Startup Script ubuntu server

Post by penguisher » 17 Oct 2009 09:48

Well the last script I tried was this one:

Code: Select all

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

MYDESC="penguisher"
MYPATH=/home/penguisher/TrackmaniaServer_2009-08-01
MYNAME=TM
MYPROC=TrackmaniaServerF
MYLOCK=$MYNAME
DAEMON=$MYPATH/server.sh
MYPIDF=/var/run/$MYNAME.pid
MYCMND="$MYPATH/server.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" penguisher | 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
This piece of code is the first problem I think.

Code: Select all

# Source function library.
. /etc/rc.d/init.d/functions 
When I try to start that script I get this error:
.: 18: Can't open /etc/rc.d/init.d/functions
and I really can't find any "functions" anywhere in etc and sub-directories.

So I simply deleted the line in search for more errors
then I get this error:
/etc/init.d/TM: Daemon not found: /home/penguisher/TrackmaniaServer_2009-08-01/server.sh

Also I don't know what this does:

Code: Select all

MYPROC=TrackmaniaServerF
So I left it the way it was in the example.

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

Re: Startup Script ubuntu server

Post by Xymph » 17 Oct 2009 10:34

penguisher wrote:This piece of code is the first problem I think.

Code: Select all

# Source function library.
. /etc/rc.d/init.d/functions 
When I try to start that script I get this error:
.: 18: Can't open /etc/rc.d/init.d/functions
and I really can't find any "functions" anywhere in etc and sub-directories.
That shell file (in other Linux distros such as Red Hat and derivatives) provides support routines for init.d scripts, such as killproc and status. It's not needed if you rewrite that functionality directly into your init.d script. See other init.d scripts on your system for how to do that.
penguisher wrote:So I simply deleted the line in search for more errors
then I get this error:
/etc/init.d/TM: Daemon not found: /home/penguisher/TrackmaniaServer_2009-08-01/server.sh
If there's no server.sh file in that directory, then obviously it cannot be found. This shell script simply calls the dedicated with the right parameters, e.g.:

Code: Select all

cd /home/<your path>
./TrackmaniaServer /internet /game_settings=MatchSettings/<your settings>.txt /dedicated_cfg=dedicated_cfg.txt
penguisher wrote:Also I don't know what this does:

Code: Select all

MYPROC=TrackmaniaServerF
So I left it the way it was in the example.
On my system I run multiple classic TMN and TMF servers, so I renamed each dedicated executable into a unique name in order to distinguish them in a process list (necessary for the init.d stop command, for example). In your case, if you run just one server, you can use the default name 'TrackmaniaServer' there.
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

penguisher
pedestrian
pedestrian
Posts: 12
Joined: 15 Oct 2009 15:11
Owned TM-games: TMNF

Re: Startup Script ubuntu server

Post by penguisher » 17 Oct 2009 13:11

Ok thank you, I fixed those problems, I do have a server.sh but it didn't have the right permissions xD.

The next errors are displayed after running the script now:
Executing /etc/init.d/TM start ..

Code: Select all

Starting penguisher: TM 
/home/penguisher/TrackmaniaServer_2009-08-01/server.sh: line 2:  3701 Segmentation fault      ./TrackmaniaServer /game_settings=MatchSettings/Nations/NationsBlue.txt /dedicated_cfg=dedicated_cfg.txt /nodaemon /internet
Sessions still open, not unmounting
chown: invalid user: `tmf.tm'
touch: cannot touch `/var/lock/subsys/TM': No such file or directory
I don't know which user I should enter in the script.
Is it my TrackMania account name or is it the servers TrackMania account name or is it one of those Admin or SuperAdmin accounts?? And what about that /var/lock/subsys/TM error? should I manually create that directory? And what permissions should that directory have?

Here are my scripts:

server.sh

Code: Select all

cd /home/penguisher/TrackmaniaServer_2009-08-01
./TrackmaniaServer /game_settings=MatchSettings/Nations/NationsBlue.txt /dedicated_cfg=dedicated_cfg.txt /nodaemon /internet
init.d/TM

Code: Select all

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

MYDESC="penguisher"
MYPATH=/home/penguisher/TrackmaniaServer_2009-08-01
MYNAME=TM
MYPROC=TrackmaniaServerF
MYLOCK=$MYNAME
DAEMON=$MYPATH/server.sh
MYPIDF=/var/run/$MYNAME.pid
MYCMND="$MYPATH/server.sh"

# Source function library.
. /lib/lsb/init-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" penguisher | 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

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

Re: Startup Script ubuntu server

Post by Xymph » 17 Oct 2009 15:54

penguisher wrote:

Code: Select all

chown: invalid user: `tmf.tm'
touch: cannot touch `/var/lock/subsys/TM': No such file or directory
I don't know which user I should enter in the script.
A Linux user and group that have access to the TM tree. Not to sound snobbish or anything, but if you don't know 'chown' and other basic Unix/Linux features, maybe it's time to follow a course in that before trying to run a server. :wink:
penguisher wrote:Is it my TrackMania account name or is it the servers TrackMania account name or is it one of those Admin or SuperAdmin accounts?? And what about that /var/lock/subsys/TM error? should I manually create that directory? And what permissions should that directory have?
The /var/lock/subsys/ stuff is another Red Hat (etc.) feature that's different on Ubuntu. I don't have time to port the whole startup script to Ubuntu.
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

penguisher
pedestrian
pedestrian
Posts: 12
Joined: 15 Oct 2009 15:11
Owned TM-games: TMNF

Re: Startup Script ubuntu server

Post by penguisher » 17 Oct 2009 22:45

Well ok thank you for your help. It's true this is my first linux server and I am trying to learn all the different things. I think the best way to learn all those things is to just do them and try to solve every problem, the thing is there is not much information about tm servers. So the only way to learn this is to ask in this forum :p and just put a lot of effort in it.

Thanks again for your help.

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

Re: Startup Script ubuntu server

Post by Xymph » 17 Oct 2009 23:08

penguisher wrote:the thing is there is not much information about tm servers.
Wrong.
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

penguisher
pedestrian
pedestrian
Posts: 12
Joined: 15 Oct 2009 15:11
Owned TM-games: TMNF

Re: Startup Script ubuntu server

Post by penguisher » 19 Oct 2009 17:51

Well my problem is solved. The startup script does what it should do. I will post my code below for everyone who wants to use it. THANKS Xymph for all the help.

/edit: removed the code, because I accidentally posted the wrong script. The code below is the script I use at this moment, but it is far from optimal, because it just kills the process instead of shutting down the server properly.

Code: Select all

#!/bin/sh
# Starts TM Server

case "$1" in
'start')
	cd /home/tmnf/tm
	sudo -u tmnf ./TrackmaniaServer /game_settings=MatchSettings/Nations/NationsBlue.txt /dedicated_cfg=dedicated_cfg.txt /internet
	;;
'stop')
        tmpid=`pidof TrackmaniaServer`
        sudo -u tmnf kill -9 $tmpid
	;;
*)
	echo "Usage: $0 { start | stop }"
	;;
esac
exit 0
Last edited by penguisher on 12 Feb 2010 11:35, edited 1 time in total.

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

Re: Startup Script ubuntu server

Post by Xymph » 19 Oct 2009 18:25

penguisher wrote:Well my problem is solved. The startup script does what it should do. I will post my code below for everyone who wants to use it.
So you dug up /lib/lsb/init-functions ... well done, I didn't know it was buried there. :thumbsup:

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

Re: Startup Script ubuntu server

Post by Xymph » 02 Jan 2011 20:27

Blast from the past, but I figured it might be useful to some that proper Ubuntu/Debian init.d scripts are now available on my official XAseco.org site for XAseco and dedicated server. Those pages also offer improved versions of the CentOS/RedHat variants that I posted in this forum even longer ago.
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

jammeraahz
highway camper
highway camper
Posts: 1
Joined: 24 Jul 2011 10:49
Owned TM-games: TMUF

Re: Startup Script ubuntu server

Post by jammeraahz » 24 Jul 2011 11:01

long time coming (great notes btw), but a slight mod for the debian script. Rather than calling the launch script, it will call the main executable and provide options. a modification to the start-stop-daemon line makes it change the working directory before launching - this makes the logs, gbx's (and other relative paths that were coded in and not made to be configurable) work.

Works a dream now :)

names have been changed to protect the innocent :D

Code: Select all

#! /bin/sh
### BEGIN INIT INFO
# Provides:          tmfd
# Default-Start:     2 3 4 5
# Default-Stop:      1
# Short-Description: TMF is the TrackMania Forever server
### END INIT INFO
#
# Author: Frans P. de Vries <tmn@gamers.org>
#
#set -e

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

MYUSER=<user to run as>
MYPATH=</path/to/server/directory>
MYNAME=`basename $0`
DAEMON=$MYPATH/TrackmaniaServ
OPTIONS="/game_settings=</path/to/Matchsettings/config.txt> /dedicated_cfg=dedicated.cfg"
MYPROC=$MYPATH/TrackmaniaServer
MYPIDF=/var/run/$MYNAME.pid

test -x $DAEMON || exit 0

if [ ! -d /var/lock/subsys ]; then
        mkdir -p /var/lock/subsys
fi

. /lib/lsb/init-functions

case "$1" in
  start)
        log_daemon_msg "Starting $MYNAME"
        pid=`pidofproc -p $MYPIDF $MYNAME`
        if [ $? -eq 0 -a -n "$pid" ]; then
                log_failure_msg "$MYPROC (pid $pid) is already running"
                exit 1
        fi
        start-stop-daemon --start --quiet --chdir $MYPATH --chuid $MYUSER --pidfile $MYPIDF --exec $DAEMON -- $OPTIONS | tee /tmp/$MYNAME$$
        pid=`sed -n 's~.*with pid=\([0-9][0-9]*\).*~\1~;/^[0-9]*$/p' /tmp/$MYNAME$$`
        echo $pid > $MYPIDF
        rm -f /tmp/$MYNAME$$
        log_end_msg $?
        ;;
  stop)
        log_daemon_msg "Stopping $MYNAME"
        pid=`pidofproc -p $MYPIDF $MYNAME`
        if [ $? -ne 0 -o -z "$pid" ]; then
                log_failure_msg "$MYPROC is not running"
                exit 1
        fi
        killproc -p $MYPIDF $MYPROC
        rm -f $MYPIDF
        log_end_msg $?
        ;;
  restart)
        $0 stop
        sleep 1
        $0 start
        ;;
  status)
        pid=`pidofproc -p $MYPIDF $MYNAME`
        if [ $? -eq 0 -a -n "$pid" ]; then
                log_success_msg "$MYPROC (pid $pid) is running"
                exit 0
        else
                log_failure_msg "$MYPROC is not running"
                exit 1
        fi
        ;;
  *)
        echo "Usage: /etc/init.d/$MYNAME {start|stop|restart|status}"
        exit 1
        ;;
esac

exit 0

Enjoy :)

jam-man

Post Reply

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest