Startup Script ubuntu server
Moderators: Pit Crew, TM-Patrol
-
- pedestrian
- Posts: 12
- Joined: 15 Oct 2009 15:11
- Owned TM-games: TMNF
Startup Script ubuntu server
Hello everyone,
I am looking for a working startup script for ubuntu, I tried several startup scripts but they didn't work for me.
I am looking for a working startup script for ubuntu, I tried several startup scripts but they didn't work for me.
Re: Startup Script ubuntu server
To start up an Ubuntu server, press the power button.penguisher wrote:I am looking for a working startup script for ubuntu, I tried several startup scripts but they didn't work for me.

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
Find your way around the Mania community from the TMN ESWC hub, TMF hub, TM² hub, and SM hub
-
- pedestrian
- Posts: 12
- Joined: 15 Oct 2009 15:11
- Owned TM-games: TMNF
Re: Startup Script ubuntu server
Well the last script I tried was this one:
This piece of code is the first problem I think.
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:
So I left it the way it was in the example.
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
Code: Select all
# Source function library.
. /etc/rc.d/init.d/functions
.: 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
Re: Startup Script ubuntu server
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:This piece of code is the first problem I think.When I try to start that script I get this error:Code: Select all
# Source function library. . /etc/rc.d/init.d/functions
.: 18: Can't open /etc/rc.d/init.d/functions
and I really can't find any "functions" anywhere in etc and sub-directories.
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.: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
Code: Select all
cd /home/<your path>
./TrackmaniaServer /internet /game_settings=MatchSettings/<your settings>.txt /dedicated_cfg=dedicated_cfg.txt
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.penguisher wrote:Also I don't know what this does:So I left it the way it was in the example.Code: Select all
MYPROC=TrackmaniaServerF
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
Find your way around the Mania community from the TMN ESWC hub, TMF hub, TM² hub, and SM hub
-
- pedestrian
- Posts: 12
- Joined: 15 Oct 2009 15:11
- Owned TM-games: TMNF
Re: Startup Script ubuntu server
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 ..
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
init.d/TM
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
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
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
Re: Startup Script ubuntu server
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.penguisher wrote:I don't know which user I should enter in the script.Code: Select all
chown: invalid user: `tmf.tm' touch: cannot touch `/var/lock/subsys/TM': No such file or directory

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.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?
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
Find your way around the Mania community from the TMN ESWC hub, TMF hub, TM² hub, and SM hub
-
- pedestrian
- Posts: 12
- Joined: 15 Oct 2009 15:11
- Owned TM-games: TMNF
Re: Startup Script ubuntu server
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.
Thanks again for your help.
Re: Startup Script ubuntu server
Wrong.penguisher wrote:the thing is there is not much information about tm servers.
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
Find your way around the Mania community from the TMN ESWC hub, TMF hub, TM² hub, and SM hub
-
- pedestrian
- Posts: 12
- Joined: 15 Oct 2009 15:11
- Owned TM-games: TMNF
Re: Startup Script ubuntu server
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.
/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.
Re: Startup Script ubuntu server
So you dug up /lib/lsb/init-functions ... well done, I didn't know it was buried there.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.

Re: Startup Script ubuntu server
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
Find your way around the Mania community from the TMN ESWC hub, TMF hub, TM² hub, and SM hub
-
- highway camper
- Posts: 1
- Joined: 24 Jul 2011 10:49
- Owned TM-games: TMUF
Re: Startup Script ubuntu server
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
Enjoy
jam-man
Works a dream now

names have been changed to protect the innocent

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