Restart script

Discussion in 'Systems Administration' started by Mithrandir, Feb 27, 2020.

  1. Hi. I've been using this restart script for all my servers for years now. It includes the execution of an external, and some other countdown functions on another script.

    The script itself can simply start and stop a server on a tmux window. Feel free to use something similar for your own needs! (allthough I admit the script parts are not all included in this case):

    Code (Text):

    . /home/network/SCRIPTS/
    echo "deteniendo servidor $serverName..."
    tmux send-keys -t network:0 'send Survival Hub' C-m
    tmux send-keys -t network:$window 'stop' C-m
    sleep 30
    tmux send-keys -t network:$window 'bash' C-m
    echo "iniciando servidor $serverName..."
    exit 0

    The issue with this one is that sometimes the server can take more than 30s delay to stop, thus if the delay is shorter than the actual time it takes for the server to stop, the server will never start. This makes the script imperfect, since it can sometimes not fully restart.

    It beats me why sometimes it would take so long to stop, but I really don't consider it a pressing issue right now, and it doesn't always happen.

    What I would need is for some way of knowing with certainty when the server went off (like the script getting notified?), and then continue the execution of the script, this way avoiding the times where the server just stays off until we notice it didn't restart properly. Any ideas?

    Alternatively I could just increase the delay, but the need above would be much cleaner.
  2. that's really weird problem you have here, I have absolutely no problem with screen:

    sleep 1
    while true; do
    sleep 5
    java -Xms2G -Xmx2G -XX:+UseG1GC -XX:+UnlockExperimentalVMOptions -XX:MaxGCPauseMillis=100 -XX:+DisableExplicitGC -XX:TargetSurvivorRatio=90 -XX:G1NewSizePercent=50 -XX:G1MaxNewSizePercent=80 -XX:G1MixedGCLiveThresholdPercent=35 -XX:+AlwaysPreTouch -XX:+ParallelRefProcEnabled -XX:+UseLargePagesInMetaspace -Dpaper.playerconnection.keepalive=120 -XX:ThreadStackSize=320K -XX:+PrintGCDetails -Xloggc:gc.log -javaagent:slimeworldmanager-classmodifier-2.1.0.jar -jar custom.jar --world-dir worlds

    and the script executing it:

    sleep 1
    screen -S GL -d -m sh
  3. Phoenix616

    Resource Staff

    Yeah there are only really two good solutions there: Either use a loop like Govindas suggested or use some way to detect whether or not the server is still online (e.g. via punging the port/query)

    I personally use a combination of both methods a loop for normal restarts (but with a check for a value in a stop file in the server directory in there so that I can stop it instead of restarting) and nc to query the server port to see when the server is back online to send players back to it again.
  4. Interesting ideas, thanks :)