TM-FORUM

The TrackMania universal forum ^_^
It is currently 28 May 2017 05:49

All times are UTC + 1 hour




Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: Startup Script ubuntu server
PostPosted: 16 Oct 2009 13:49 
Offline
pedestrian
pedestrian

Joined: 15 Oct 2009 16:11
Posts: 12
Owned TM-games: TMNF
Hello everyone,

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


Top
 Profile  
 
 Post subject: Re: Startup Script ubuntu server
PostPosted: 16 Oct 2009 16:02 
Offline
Pit Crew
Pit Crew

Joined: 19 Aug 2007 13:58
Posts: 5639
Owned TM-games: TMN, TMU, TMF, TM²
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


Top
 Profile  
 
 Post subject: Re: Startup Script ubuntu server
PostPosted: 17 Oct 2009 10:48 
Offline
pedestrian
pedestrian

Joined: 15 Oct 2009 16:11
Posts: 12
Owned TM-games: TMNF
Well the last script I tried was this one:
Code:
#!/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:
# 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:
MYPROC=TrackmaniaServerF

So I left it the way it was in the example.


Top
 Profile  
 
 Post subject: Re: Startup Script ubuntu server
PostPosted: 17 Oct 2009 11:34 
Offline
Pit Crew
Pit Crew

Joined: 19 Aug 2007 13:58
Posts: 5639
Owned TM-games: TMN, TMU, TMF, TM²
penguisher wrote:
This piece of code is the first problem I think.
Code:
# 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:
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:
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


Top
 Profile  
 
 Post subject: Re: Startup Script ubuntu server
PostPosted: 17 Oct 2009 14:11 
Offline
pedestrian
pedestrian

Joined: 15 Oct 2009 16:11
Posts: 12
Owned TM-games: TMNF
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:
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:
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:
#!/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


Top
 Profile  
 
 Post subject: Re: Startup Script ubuntu server
PostPosted: 17 Oct 2009 16:54 
Offline
Pit Crew
Pit Crew

Joined: 19 Aug 2007 13:58
Posts: 5639
Owned TM-games: TMN, TMU, TMF, TM²
penguisher wrote:
Code:
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


Top
 Profile  
 
 Post subject: Re: Startup Script ubuntu server
PostPosted: 17 Oct 2009 23:45 
Offline
pedestrian
pedestrian

Joined: 15 Oct 2009 16:11
Posts: 12
Owned TM-games: TMNF
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.


Top
 Profile  
 
 Post subject: Re: Startup Script ubuntu server
PostPosted: 18 Oct 2009 00:08 
Offline
Pit Crew
Pit Crew

Joined: 19 Aug 2007 13:58
Posts: 5639
Owned TM-games: TMN, TMU, TMF, TM²
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


Top
 Profile  
 
 Post subject: Re: Startup Script ubuntu server
PostPosted: 19 Oct 2009 18:51 
Offline
pedestrian
pedestrian

Joined: 15 Oct 2009 16:11
Posts: 12
Owned TM-games: TMNF
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:
#!/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 12:35, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Startup Script ubuntu server
PostPosted: 19 Oct 2009 19:25 
Offline
Pit Crew
Pit Crew

Joined: 19 Aug 2007 13:58
Posts: 5639
Owned TM-games: TMN, TMU, TMF, TM²
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:


Top
 Profile  
 
 Post subject: Re: Startup Script ubuntu server
PostPosted: 02 Jan 2011 21:27 
Offline
Pit Crew
Pit Crew

Joined: 19 Aug 2007 13:58
Posts: 5639
Owned TM-games: TMN, TMU, TMF, TM²
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


Top
 Profile  
 
 Post subject: Re: Startup Script ubuntu server
PostPosted: 24 Jul 2011 12:01 
Offline
highway camper
highway camper

Joined: 24 Jul 2011 11:49
Posts: 1
Owned TM-games: TMUF
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:
#! /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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group