Restarting server

CarNagE1CarNagE1 Poland Join Date: 2003-05-14 Member: 16298Members, NS2 Playtester, Reinforced - Shadow, WC 2013 - Supporter, Subnautica Playtester
I have a nice windows machine set up for our server. It does crash. So I manually connect and restart the process. Is there any good tool to do it automatically? When restarting the server I just close and load the process again. Should I restart the machine (hard reset) not just the process?

Comments

  • SupaFredSupaFred Join Date: 2013-03-03 Member: 183652Members, NS2 Playtester, Squad Five Blue, NS2 Map Tester, Reinforced - Supporter, Reinforced - Silver, Reinforced - Shadow, WC 2013 - Silver
    @CarNagE1‌ The process is enough. I use EzUGCC to monitor and restart my servers on crash but it's probably possible to do it with a script or something. @ATF‌?
  • ATFATF Join Date: 2014-05-09 Member: 195944Members
    edited October 2014
    Quoting myself from another thread with better formatting:
    Below is a simple batch script that will start / restart your server while copying timestamped logs into the specified folder. It runs independantly from your server, meaning nothing will break if you start / exit the script while your server is running. It can also perform automatic restarts if the server exceeds a specified memory usage.

    Here's how to use it:
    - Paste the script into a file and name it restartscript.cmd (make sure file extensions aren't hidden on your system)
    - Create a .lnk file with the server.exe as the target and add the command line options
    - Open the .cmd (with notepad++ for example) and edit the variables to your liking.
    @ECHO off
    ::
    :: DO NOT edit this file while the script is running!
    ::
    SET serverpath=C:\Users\Obraxis\Desktop& REM Path of the .lnk to server.exe, which carries the commandline attributes
    SET serverlnk=Startns2server.lnk& REM Name of the .lnk (avoid spaces)
    SET serverexe=server.exe 
    SET monitoringdelay=30& REM Check every n seconds if server.exe is an existing process. 
                             REM Can be no more than 59 sec for the daily leakcheck to work.
    SET logarchivepath=D:\ns2ds-log-archive\& REM Path to archive log before starting/restarting.
    SET dailyrestartenabled=true& REM Define whether you want the script to check for memleaks and restart if necessary.
    SET dailyrestartat=10:30& REM Time of day to check for memleaks.
    SET memleakthreshold=1750000& REM If server.exe uses more than n kbytes of memory, force a restart.
    :: Variables below this line should not be modified.
    SET initialserverstart=true
    title NS2DS Restartscript 
    ECHO Settings: %monitoringdelay%s interval, leakcheck at %dailyrestartat%am, threshold at %memleakthreshold%kbyte.
    ECHO[ 
    :BATCHSTART
    TASKLIST /nh /fi "imagename eq %serverexe%" | FIND /i "%serverexe%" > NUL && (
      ECHO %date% %time% NS2DS found, starting monitoring.
      SET initialserverstart=false
      GOTO STATUSCHECK
      ) || ( GOTO COPYLOG  
      )
    :CONTINUEINIT
    TIMEOUT 15
    START /D "%serverpath%" %serverlnk% 2> NUL && (
      ECHO %date% %time% Initial start. Logging: %logging%
      ) || (
      ECHO %date% %time% Cannot start NS2DS. Exiting. Logging: %logging% 
      GOTO ENDROUTINE
      )
    ECHO[
    SET initialserverstart=false
    TIMEOUT %monitoringdelay% > NUL
    GOTO STATUSCHECK
    
    :STATUSCHECK
    TASKLIST /nh /fi "imagename eq %serverexe%" | FIND /i "%serverexe%" > NUL && (
      rem
      ) || GOTO STARTSERVER
    IF %dailyrestartenabled%==true TIME /t | FIND /i "%dailyrestartat%" > NUL && (
      GOTO DAILYRESTART
      )
    TIMEOUT %monitoringdelay% > NUL
    GOTO STATUSCHECK
    
    :STARTSERVER
    GOTO COPYLOG
    :CONTINUESTART
    START /D "%serverpath%" %serverlnk% 2> NUL && (
      ECHO %date% %time% NS2DS restarted. Logging: %logging%
      ) || (
      ECHO %date% %time% Cannot restart NS2DS. Exiting. Logging: %logging%
      GOTO ENDROUTINE
      )
    TIMEOUT %monitoringdelay% > NUL
    GOTO STATUSCHECK
    
    :DAILYRESTART
    TASKLIST /fi "memusage GT %memleakthreshold%" | FIND /i "server.exe" > NUL && (
      ECHO %date% %time% NS2DS leaks above threshold. Terminating.
      TASKKILL /IM %serverexe%
      ) || ( 
      TIMEOUT 60 /NOBREAK > NUL
      GOTO STATUSCHECK
      )
    TIMEOUT 8 /NOBREAK > NUL 
    TASKLIST /nh /fi "imagename eq %serverexe%" | FIND /i "%serverexe%" > NUL && (
      ECHO %date% %time% NS2DS unresponsive. Killing process.
      TASKKILL /F /IM %serverexe%
      TIMEOUT 15 /NOBREAK > NUL
      ) 
    TASKLIST /nh /fi "imagename eq %serverexe%" | FIND /i "%serverexe%" > NUL && (
      ECHO %date% %time% Cannot kill process. Exiting.
      GOTO ENDROUTINE 
      )
    TIMEOUT 60 /NOBREAK > NUL
    GOTO STATUSCHECK
    
    :COPYLOG
    FOR /F "tokens=1,2,3 delims=." %%x IN ("%date%") DO SET LogDate=%%z%%y%%x
    FOR /F "tokens=1,2 delims=:," %%v IN ("%time%") DO SET LogTime=%%v%%w
    COPY /Y "%appdata%\Natural Selection 2\log-Server.txt" "%logarchivepath%%Logdate%-%LogTime%.txt" >NUL && ( SET logging=OK 
      ) || SET logging=FAILED!
    IF %initialserverstart%==true GOTO CONTINUEINIT
    IF %initialserverstart%==false GOTO CONTINUESTART
    
    
    
    :ENDROUTINE
    TIMEOUT /T -1 /NOBREAK > NUL
    :: prevents closing of window in case something goes wrong
    

    Let me know if you need assistance.

    There is no need to restart the box itself.
Sign In or Register to comment.