Auto Restart

    Joined
    Jun 22, 2013
    Messages
    1
    Reaction score
    0
    • Legacy Citizen 2
    • Legacy Citizen
    I run a server on my home linux box, anyone know a good sh script to hourly reboot the server?
     
    Joined
    Jun 21, 2013
    Messages
    91
    Reaction score
    0
    This would be an extremely useful script and I\'ve been asking around myself.
     
    Joined
    Jun 19, 2013
    Messages
    34
    Reaction score
    0
    Yes, this is a must need if there are any.

    My server tends to crash after a few hours due to unknown reasons and it would be great if they had some way for it to automaticly start itself back up. Hope something like this gets released in the near future.
     
    Joined
    Apr 25, 2013
    Messages
    53
    Reaction score
    0
    This might be what you are looking for:

    http://askubuntu.com/questions/243546/how-to-restart-every-30-minutes-automatically
     
    Joined
    Jun 23, 2013
    Messages
    295
    Reaction score
    0
    • Legacy Citizen 2
    • Legacy Citizen
    I\'m not sure this will reboot the server.. because it\'s purely for Ubuntu itself, but the logic is there.

    Moving on.
    Well making a timer or timed script isn\'t very hard or heavy, so we\'ll skip that.

    I would have the script print out into chat a warning saying \"the server has just been saved, will reboot in 2 minutes, and that any progress during those two minutes may be lost.\", then run the /shutdown command with a parameter of 120.

    The only thing I can\'t really give you is the actual command to launch the server back up.
    I don\'t have the files with me right now (at work), but starmade doesn\'t have a dedicated_server_launcher.jar or something, right? With the way you start and host a server right now (and it\'s great) you\'d just have to run that program at after the shutdown and voilà.

    I haven\'t looked into or know right now how to give the 2 first commands as an in-game admin, but I\'m sure that can be worked around. Worst case scenario would be no warning and then just close the server from the outside like you\'d kill any program. This could frustrate the server users, so I\'d advise a welcome message that specify either the hours of reboot or a warning that it happens hourly.

    Hope this helps.
     
    Joined
    Jun 21, 2013
    Messages
    91
    Reaction score
    0
    My Host has made a Restart Script whenever the server is COMPLETELY down/crashed. I don\'t know for sure if this is the right one, but I took it from the FTP. I\'ll ask him later if he uses this one currently. But this is a \'launcher.bat\' located within the StarMade folder and looks like this:



    @echo off
    title FH - StarMade Server Launcher

    :launch
    echo Launching server...
    call java -Xms1024m -Xmx2048m -Xincgc -Xshare:eek:ff -jar StarMade.jar -server
    goto launch
     
    Joined
    Jun 19, 2013
    Messages
    34
    Reaction score
    0
    Going to try this out, thank you very much for sharing.
     
    Joined
    Jun 26, 2013
    Messages
    28
    Reaction score
    2
    So originally I wanted to do something nice and simple, that makes use of some of the native functions of Linux for just such situations as this. A simple 4 line script.

    until StarMade-dedicated-server-linux.sh; do
    echo \"StarMade crashed with exit code $?. Respawning..\" >&2
    sleep 1
    done

    However from what I can gather, when StarMade crashes, it doesn\'t *really* crash. At least not as the OS sees it. See, StarMade crashes gracefully (at least every time I\'ve seen) and actually saves its state and shuts down properly. This means that it sends a termination code of 0, and thus this script does not run. It looks at the shutdown and says \"Oh, no, you meant to do that. Guess I don\'t need to do anything.\" So while I am glad that StarMade even manages to crash reasonably gracefully, it does cause a problem here. That script does not work.

    After some minor frustrations that are typical of toying with scripting languages you don\'t use much, I got the below script put together and working. It checks for instances of StarMade.jar in the processes list and starts the server if they\'re not located. This does have to be put into crontab, unless you have another way to make the thing keep checking. Mine is set to check every 5 minutes, I figure that\'s probably fine. Hopefully this helps people some.

    EDIT: I found a better way to set the script up that doesn\'t require cron. In hindsight, I feel silly for not realizing this previously but oh well. I\'ve been running this script for a few days now and it seems to work well. You can change the sleep time to whatever you want it to be.

    #!/bin/bash

    while :

    do
    if [ \"$(pgrep -f StarMade.jar)\" ]

    then
    echo “$(date “+%m%d%y %T”) : StarMade is running already”

    else
    echo “$(date “+%m%d%y %T”) : StarMade not running, launching…”
    cd “$(dirname “$0?)”
    /opt/java/bin/java -Xms512m -Xmx4G -jar StarMade.jar -server
    fi
    sleep 2m
    done