Restarting a crashed server

Discussion in 'Systems Administration' started by Alstroemeria, May 15, 2015.

  1. Hi, I've been poking around with the start.sh for our server recently, and found that while it does allow for the use of /restart or /stop to restart the server, I can't seem to find a way to make the server restart when it is crashed.

    For example, if the server freezes and crashes, and it (apparently) tries to reboot the server with start.sh, it seems to not be able to, because java is still running, even after the crash. The port is still being used by java, and therefore the server cannot reboot properly. The solution that I believed would work was to put pkill -9 java in the start.sh, but it had no effect. Is there a way to make java kill itself when the server crashes, or kill it from the startup script?

    Here is what I am using currently, a server.sh, which continually starts the server, and a .start.sh, which opens the server.sh in a screen, and (doesn't work) uses pkill to kill java.
    Code (startsh (Unknown Language)):
    screen -S server -d -m sh server.sh
    Code (serversh (Unknown Language)):
     # /bin/sh
    while true
    do
    java -Xmx16G -server -XX:+UseConcMarkSweepGC -jar spigot-*.jar
    echo Its off..sleeping for 5
    sleep 5
    done
     
    Any help would be greatly appreciated. Thanks!
     
  2. Try running a kill on the process right before sleep.
     
  3. When I used that, it constantly ran the pkill command every 5 seconds, killing the server before it could even startup. Is there a way to make it so that it only executes the command when ./start.sh is used? When I try putting it in start.sh, it doesn't seem to work.

    Also, I think this is a problem with the ./start.sh not properly being executed on a server crash, as using ./start.sh works fine (not executed by spigot) if the pkill -9 java is in start.sh.