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