Welcome to Keen Software House Forums! Log in or Sign up to interact with the KSH community.
  1. You are currently browsing our forum as a guest. Create your own forum account to access all forum functionality.

Simple auto-restart+backup script

Discussion in 'Groups & Dedicated Servers' started by Neotician, Sep 21, 2014.

Thread Status:
This last post in this thread was made more than 31 days old.
  1. Neotician Apprentice Engineer

    So, i've had issues with increasing RAM usage over time and welders etc. stopping working, so i made this little script to restart the server.
    Basically, it:
    • Starts the server and tells you so.
    • Checks if the server started and tells you if it is.
    • waits for 28800 seconds (8 hours)
    • Tells the server to shut down and waits for 30 seconds
    • Makes a backup of the same folder
    • Checks if the server is down, if it is, it goes back to the beginning, if it is not it waits another 30 sec.
    • If the server is still not down after the additional 30 sec, it will tell you so and halt
    How to use:
    1. Copy the code to a text file and save it as .bat, in the same folder as the server app.
    2. rename your SpaceEngineersDedicated.exe to seds.exe
    3. run the .bat file to start the server.
    If you want to restart the server manually, just select the cmd window and press a key, it'll skip the wait time.
    If you want to shut the server down, just select the cmd window and press a key, then close the cmd window.
    You can manually change the Timeout intervals, to change how much time passes between restarts, and how long it should give the server to shut down
    Added a line for automatically backing up the /saves folder on each restart.
    The backup will go into %appdata%/SpaceEngineersDedicated/backup/(Date)(Hour)/
    For example, if the server is restarting at 9 in the morning on september 22nd, the backup folder will be named "22-09-2014 9" or "09-22-2014 9" depending on your date system.
    @echo off
    ECHO Starting server...
    START "seds.exe"  "seds.exe" -noconsole
    tasklist /FI "IMAGENAME eq seds.exe" /NH | find /I /N "seds.exe" > NUL
    IF %ERRORLEVEL%==0 ECHO Server Running
    IF %ERRORLEVEL%==1 ECHO Server Not Running
    Timeout 28800
    Echo Restarting Server..
    taskkill /IM seds.exe
    Timeout 30
    xcopy "%appdata%\SpaceEngineersDedicated\Saves" "%appdata%\SpaceEngineersDedicated\Backup\%date%%time:~0,2%\" /E
    tasklist /FI "IMAGENAME eq seds.exe" /NH | find /I /N "seds.exe" > NUL
    IF %ERRORLEVEL%==0 timeout 30
    IF %ERRORLEVEL%==1 goto loop
    tasklist /FI "IMAGENAME eq seds.exe" /NH | find /I /N "seds.exe" > NUL
    IF %ERRORLEVEL%==0 echo Server not responding, halting!
    IF %ERRORLEVEL%==1 goto loop
  2. MarekW Trainee Engineer

    Great little script, good job!
    However this might get more visibility in the 'Modding' section.
  3. Neotician Apprentice Engineer

    Thanks, and yes you're probably right, i'll move it there :)
  4. chi27870 Trainee Engineer

    Will this still work? Im looking for an auto restart for torch if possible
  5. bigbangnet Apprentice Engineer

    idiot question, can you change seds for the original name ? why seds.exe. Also can you change the 28800 for another number like 12 hours without any problems ? imo it shouldn't be a problem but since you did it... I wondered if you had problems or hiccups

    not complaining here but I hope KH is working on those kinds of task in the dedicated server app they already have. things like that would be great if it was already integrated. I assume they are; priorities I guess.
  6. WilliamJamesJ Trainee Engineer

    Hey i have been looking for his for a pretty long time but I would like to know what happens if you have multiple instances. Which instance does it select?
Thread Status:
This last post in this thread was made more than 31 days old.