Killing and restart of armagetron advanced dedicated server
-
- On Lightcycle Grid
- Posts: 37
- Joined: Tue Jan 08, 2008 1:40 pm
Killing and restart of armagetron advanced dedicated server
hi,
I have a script running multiple servers using screen (as I explain in the wiki).
The problem I have is that if I restart an arma server, when I kill it it does not free the port, and when it start again, it considers the port taken, and use the next one free, even by using the SERVER_PORT variable.
How can I fix that ? is there aynway I can kill the server, and close the port in the same process, before to restart the server ? or is there a bash command to ensure the port is closed so when the game restart it can use the port it should ?
Cheers
I have a script running multiple servers using screen (as I explain in the wiki).
The problem I have is that if I restart an arma server, when I kill it it does not free the port, and when it start again, it considers the port taken, and use the next one free, even by using the SERVER_PORT variable.
How can I fix that ? is there aynway I can kill the server, and close the port in the same process, before to restart the server ? or is there a bash command to ensure the port is closed so when the game restart it can use the port it should ?
Cheers
-
- On Lightcycle Grid
- Posts: 37
- Joined: Tue Jan 08, 2008 1:40 pm
Re: Killing and restart of armagetron advanced dedicated server
Ok, I have found part of the problem... When I kill the screen session, it does not kill the contained processes .... Therefore, it means everytime I restart a server, in fact, it did not die, and I have multiple identical servers running That explains things.
So now the question is: How do I kill a specific process ?
Let's say, I have a process /bin/sh /etc/arma/scripts/srv deathwalls
I know it's name. From this, what command can I use to be sure it is killed before to restart the server ?
So now the question is: How do I kill a specific process ?
Let's say, I have a process /bin/sh /etc/arma/scripts/srv deathwalls
I know it's name. From this, what command can I use to be sure it is killed before to restart the server ?
- kyle
- Reverse Outside Corner Grinder
- Posts: 1876
- Joined: Thu Jun 08, 2006 3:33 pm
- Location: Indiana, USA, Earth, Milky Way Galaxy, Universe, Multiverse
- Contact:
Re: Killing and restart of armagetron advanced dedicated server
you can do it that way or you can hack arma so it does not "reload settings" when screen get killed and sends it a SIGHUP.
something like that (that is a very old diff i took).
Code: Select all
=== modified file 'src/tools/tConfiguration.cpp'
--- src/tools/tConfiguration.cpp 2008-03-20 17:35:47 +0000
+++ src/tools/tConfiguration.cpp 2008-08-19 22:10:59 +0000
@@ -952,9 +952,10 @@
static void st_DoHandleSigHup()
{
- con << tOutput("$config_sighup");
- st_SaveConfig();
- st_LoadConfig();
+ exit(0);
}
static void st_HandleSigHup( int signal )
- compguygene
- Adjust Outside Corner Grinder
- Posts: 2346
- Joined: Thu Aug 21, 2008 12:09 pm
- Location: Cleveland, Ohio
- Contact:
Re: Killing and restart of armagetron advanced dedicated server
I also use a variant of your script to start my servers. You should never kill a screen. You should type exit into the server console, and then press crtl-c as directed by the script. For me, that does kill the processes.
Armagetron: It's a video game that people should just play and enjoy
https://bit.ly/2KBGYjvCheck out the simple site about TheServerPharm
https://bit.ly/2KBGYjvCheck out the simple site about TheServerPharm
-
- On Lightcycle Grid
- Posts: 37
- Joined: Tue Jan 08, 2008 1:40 pm
Re: Killing and restart of armagetron advanced dedicated server
The idea is to restart the screen automatically if for any reason the server dies... That is why I've made the srv script below which is constantly running:
If I look in ps aux, I have three processes involved with each server I'm running:
If I kill SCREEN -dmS mw or /bin/sh srv... , armagetronad-dedicated is still running
Therefore I need to find a mean to kill all three processes when I'm killing the parent process which is screen.
EDIT: I have found now a script that kills a process and its child processes. Works perfecly.
My only problem now is to retrieve the parent process ID (i.. SCREEN -dmS mw) without getting fancies PID like the grep one, I don't care ...
I could try to save the process at start with $$ but I wonder it if will save the screen PID or the armagetronad PID or the srv PID as all three start together... I'll try... and let you know.
Code: Select all
#!/bin/bash
arma="/etc/arma"
screen -S $1 -X logtstamp on # print timestamps in log file
logdir=$arma/servers/$1/logs
test -d "$logdir" || mkdir -p "$logdir"
timestamp=`date +%d%m%Y-%H%M`
screen -S $1 -X logfile $arma/servers/$1/logs/$1_$timestamp.log # create a logfile in the logs subfolder
screen -S $1 -X log on # Turn on logging for the server window
while true; do # start a loop to allow server restart if it crashes
# runs the actual server
$arma/bin/armagetronad-dedicated --configdir $arma/servers/$1/settings --vardir $arma/servers/$1/var
# Clear the display, and indicates that the server has crashed, and then, wait 5 seconds before to restart the server, allowing you to quit with CTRL-C
clear
echo "Server has crashed. It will restart immediately..., press CTRL-C to cancel"
sleep 5
done # end the loop
Code: Select all
root 32333 0.0 0.1 2988 1044 ? Ss Jul20 0:00 SCREEN -dmS mw /etc/arma/scripts/srv mw
root 32334 0.0 0.1 2560 1060 pts/2 Ss+ Jul20 0:00 /bin/sh /etc/arma/scripts/srv mw
root 32339 0.0 0.4 7640 5104 pts/2 S+ Jul20 1:11 /etc/arma/bin/armagetronad-dedicated --configdir /etc/arma/servers/mw/settings --vardir /etc/arma/servers/mw/var
Therefore I need to find a mean to kill all three processes when I'm killing the parent process which is screen.
Code: Select all
32333 32333 32333 ? -1 Ss 0 0:00 SCREEN -dmS mw /etc/arma/scripts/srv mw
32333 32334 32334 32334 pts/2 32334 Ss+ 0 0:00 \_ /bin/sh /etc/arma/scripts/srv mw
32334 32339 32334 32334 pts/2 32334 S+ 0 1:11 \_ /etc/arma/bin/armagetronad-dedicated --configdir /etc/arma/servers/mw/settings --vardir /etc/arma/servers/mw/var
My only problem now is to retrieve the parent process ID (i.. SCREEN -dmS mw) without getting fancies PID like the grep one, I don't care ...
Code: Select all
#########################################
#!/bin/sh
# This script will kill all the child process id fo r a given pid
#Store the current Process ID, we don't want to kil l the current executing process id
CURPID=$$
# This is process id, parameter passed by user
ppid=$1
if [ -z $ppid ] ; then
echo No PID given.
exit;
fi
arraycounter=1
while true
do
FORLOOP=FALSE
# Get all the child process id
for i in `ps -ef| awk '$3 == '$ppid' { prin t $2 }'`
do
if [ $i -ne $CURPID ] ; then
procid[$arraycounter]=$i
arraycounter=`expr $arrayco unter + 1`
ppid=$i
FORLOOP=TRUE
fi
done
if [ "$FORLOOP" = "FALSE" ] ; then
arraycounter=`expr $arraycounter - 1`
## We want to kill child process id firs t and then parent id's
while [ $arraycounter -ne 0 ]
do
kill -9 "${procid[$arraycounter]}" >/d ev/null
arraycounter=`expr $arraycounter - 1`
done
exit
fi
done
#####################################
-
- On Lightcycle Grid
- Posts: 37
- Joined: Tue Jan 08, 2008 1:40 pm
Re: Killing and restart of armagetron advanced dedicated server
Ok, I sorted it out.
Instead of using
to kill my server game before to restart in case it is still running, I send "quit" to the armagetronad server, then I send CTRL-C to kill my loop:
This is my "start" script.
start all my servers
start only the chosen server
Then, my srv script which actually launch the armagetronad process:
Instead of using
Code: Select all
screen -S $f -X quit
This is my "start" script.
Code: Select all
./start
Code: Select all
./start servername
Code: Select all
#!/bin/bash
arma="/etc/arma"
# If you run the script with a parameter (server name), only that server will be start. Otherwise, all servers in the /etc/arma/servers directory will be started
if [ "$1" != "" ]; then
screen -S $1 -X stuff $'quit\n'
screen -S $1 -X stuff $'\cC\n'
screen -dmS $1 $arma/scripts/srv $1 # start a GNU screen window with the specified server inside
else
for f in $(ls $arma/servers/.) # start a loop running the following command for any existing folders in the /etc/arma/servers folder
do
screen -S $f -X stuff $'quit\n'
sleep 1
screen -S $f -X stuff $'\cC\n'
sleep 1
screen -dmS $f $arma/scripts/srv $f # start a GNU screen window with the server inside for each server folder
done # ends the loop
Code: Select all
#!/bin/bash
arma="/etc/arma"
screen -S $1 -X logtstamp on # print timestamps in log file
logdir=$arma/servers/$1/logs
test -d "$logdir" || mkdir -p "$logdir"
timestamp=`date +%d%m%Y-%H%M`
screen -S $1 -X logfile $arma/servers/$1/logs/$1_$timestamp.log # create a logfile in the logs subfolder
screen -S $1 -X log on # Turn on logging for the server window
while true; do # start a loop to allow server restart if it crashes
# runs the actual server
$arma/bin/armagetronad-dedicated --configdir $arma/servers/$1/settings --vardir $arma/servers/$1/var
# Clear the display, and indicates that the server has crashed, and then, wait 5 seconds before to restart the server, allowing you to quit with CTRL-C
clear
echo "Server has crashed. It will restart immediately..., press CTRL-C to cancel"
sleep 5
done # end the loop
- compguygene
- Adjust Outside Corner Grinder
- Posts: 2346
- Joined: Thu Aug 21, 2008 12:09 pm
- Location: Cleveland, Ohio
- Contact:
Re: Killing and restart of armagetron advanced dedicated server
Thank you for sharing the updated scripts. I will update the scripts I use, and add the script that you made that automatically restarts servers!
Armagetron: It's a video game that people should just play and enjoy
https://bit.ly/2KBGYjvCheck out the simple site about TheServerPharm
https://bit.ly/2KBGYjvCheck out the simple site about TheServerPharm