how to check that the server is shutdown in bash?

For all the help you need with Armagetron!
Post Reply
User avatar
Galaxip
Core Dumper
Posts: 120
Joined: Wed Aug 24, 2016 10:49 pm
Contact:

how to check that the server is shutdown in bash?

Post by Galaxip »

hi, I have a script for starting and stopping servers in bash and would like a way to check when the server is actually shut down after sending it an EXIT command

this is part of the bash script for shutting down, I want to check when its off so I can safely write to /var/players.txt and replace the text with 'OFFLINE' so that my server display at https://lovebug.ml reflects this, currently I just sleep 0.2 seconds but sometmes the server is still active and the write to players.txt fails

ideally I would like to replace the sleep 0.2 with a while loop that tests and waits until the server is shutdown, I could just increase the sleep time to 1 or 2 seconds but that means that if im doing a full shutdown of all servers i'll be waiting 30 or 60 seconds :(

thanks

Code: Select all

    # stop command
 66     stop)
 67
 68       # if server is already stopped
 69       if ! screen -list | grep -q $serverPort;
 70
 71       then
 72
 73         # then display message
 74         printf '%s - already stopped\n' "$serverPort"
 75
 76       else
 77
 78         # else stop the server
 79         printf '%s - stopping\n' "$serverPort"
 80         printf 'EXIT\n' >> $commandTxt
 81
 82         # wait a little
 83         sleep 0.2
 84
 85         # stop the screen session
 86         screen -S $serverPort -X quit
 87
 88         # set server status as offline (for website)
 89         printf 'OFFLINE\n' > $playersTxt
 90
 91       fi
 92     ;;
 93
if you want the full scripts they are available on the server @ http://lovebug.servegame.com:32767/misc ... d/scripts/
Last edited by Galaxip on Fri Jan 29, 2021 9:35 pm, edited 3 times in total.
Image Image Image Image
User avatar
aP|Nelg
Match Winner
Posts: 621
Joined: Wed Oct 22, 2014 10:22 pm
Contact:

Re: how to check that the server is shutdown in bash?

Post by aP|Nelg »

Perhaps check to see if the last line of the ladderlog starts with "SHUTDOWN"?
User avatar
Galaxip
Core Dumper
Posts: 120
Joined: Wed Aug 24, 2016 10:49 pm
Contact:

Re: how to check that the server is shutdown in bash?

Post by Galaxip »

ah great idea thanks, I was thinking crazy things like finding the PID and all sorts or nonsense
Image Image Image Image
User avatar
Galaxip
Core Dumper
Posts: 120
Joined: Wed Aug 24, 2016 10:49 pm
Contact:

Re: how to check that the server is shutdown in bash?

Post by Galaxip »

hmmm I just checked ladderlog and theres 2 lines after shutdown, is that always the case ?

Code: Select all

132619 SHUTDOWN 2021-01-29 20:09:41 GMT
132620 ENCODING latin1
132621 ENCODING latin1
hmmm looks like the rtc emulation on the pi is a bit off too :P
Image Image Image Image
User avatar
Galaxip
Core Dumper
Posts: 120
Joined: Wed Aug 24, 2016 10:49 pm
Contact:

Re: how to check that the server is shutdown in bash?

Post by Galaxip »

i hate bash , trying to test the last 10 lines of the ladderlog file for shutdown but I made a mess
any ideas ?

Code: Select all

 while(( tail -n 10 $ladderLogTxt | grep -i 'shutdown' == ''))

if I run this command from terminal it does work and outputs the line from ladderlog if 'shutdown' was found within the last 10 lines

Code: Select all

tail -n 10 /home/pi/armagetronad/servers/4600/var/ladderlog.txt | grep -i 'shutdown'
Image Image Image Image
User avatar
Galaxip
Core Dumper
Posts: 120
Joined: Wed Aug 24, 2016 10:49 pm
Contact:

Re: how to check that the server is shutdown in bash?

Post by Galaxip »

I managed to check if the output of ladderlog contains 'SHUTDOWN' but after looking at ladderlog I see that it can be anywhere near the end depending on how many players so I need to find another way

possibly use GAME_END

148860 ONLINE_PLAYERS_COUNT 1 0 1 0 0 0
148861 GAME_TIME 234
148862 ONLINE_PLAYERS_COUNT 1 0 1 0 0 0
148863 GAME_TIME 235
148864 ONLINE_PLAYERS_COUNT 1 0 1 0 0 0
148865 SHUTDOWN 2021-01-30 00:58:05 GMT
148866 CYCLE_DESTROYED lovebug 426.333 511.629 1 0 lovebug 235.715 RAGEQUIT
148867 ROUND_SCORE 0 lovebug lovebug
148868 PLAYER_LEFT lovebug 192.168.0.1
148869 TEAM_PLAYER_REMOVED lovebug lovebug
148870 ROUND_SCORE_TEAM 0 lovebug
148871 TEAM_DESTROYED lovebug
148872 PLAYER_RENAMED lovebug LoveBug@forums 192.168.0.1 1 LoveBug
148873 ROUND_SCORE 0 LoveBug@forums
148874 GAME_END 2021-01-30 00:58:05 GMT
148875 ENCODING latin1
Image Image Image Image
User avatar
Galaxip
Core Dumper
Posts: 120
Joined: Wed Aug 24, 2016 10:49 pm
Contact:

Re: how to check that the server is shutdown in bash?

Post by Galaxip »

ah something is wrong I just realised that I have a loop for restarting servers and thats probably messing things up too
Image Image Image Image
Post Reply