BAT File to Monitor Torch

From Torch Wiki
Jump to navigation Jump to search

First off the script was shared by N1Ran over on Discord. Thank him for the script.

Create Bat File

  1. Create a bat file named something like "TorchMonitor - <WorldName>.bat"
  2. Edit this file and fill it with the following code:
echo off
set Torch=Torch.Server.EXE Path
Call :KUT
goto :Run

:Run
Echo.
Echo INFO: Starting Torch Start Process
CALL :Check WorldName, '''World Instance Path'''
goto :eof

:KUT
Echo INFO: Terminating frozen Torch instances.
taskkill /f /fi "imagename eq Torch.Server.exe" /fi "memusage le 150000"
taskkill /f /im werfault.exe
taskkill /f /fi "status eq not responding" /fi "imagename eq Torch.Server.exe"
goto :eof

:Check
SETLOCAL
set world=%~1
set instancepath=%~2
Echo INFO: Checking if Server is currently running
tasklist /fi "imagename eq Torch.Server.exe" /v | find /I /N "%world%" 2>NUL
if "%ERRORLEVEL%" == "0" echo INFO: %world% is Running
if "%ERRORLEVEL%" == "1" echo ERROR: %world% is offline &&  Call :Restart %~1,%~2
ENDLOCAL
goto :eof

:Restart
SETLOCAL
set world=%~1
set instancepath=%~2
Echo INFO: Restarting %world%
Start /min %Torch% -autostart -instancepath "%instancepath%" -InstanceName "%world%" -restartoncrash
timeout 1 /nobreak
ENDLOCAL
goto :eof
  1. Update the following 2 lines:
    • set Torch=Torch.Server.EXE Path
      • So for my server I set it to:
        set Torch=C:\SEServers\SolSystem\Torch.Server.exe
    • CALL :Check WorldName, "World Instance Path"
      • Once again for my server I set it to:
        CALL :Check SolSystem, "C:\SEServers\SolSystem\Instance"

Test Bat File

Before setting up the scheduled task, I recommend running some tests and make sure this works for you and your server. Open a command prompt window to where the bat file is and run it manually.

I recommend testing it with the server running, with torch closed, and with torch running, but the server not started.

Setup Scheduled Task

  1. Open Task Scheduler
  2. On the left hand pane click Task Scheduler Library
  3. In the middle pane right click and select New Task
  4. A new window titled Create Task will open, enter the following:
    1. Name: Name your Task
    2. Select the Triggers tab
    3. Click New... and enter the following in the New Trigger window:
      1. Select Daily and chose Recur every: 1 days
      2. Set the Start: time to something like 12:10AM. This way its not checking if the server is up on even hours. So if you have an auto restart at mindnight, this would not run until 12:10. Which the server should be up by then.
      3. Select Repeat task every: and set it to repeat every 15 minutes for a duration of Indefinitely
      4. Click OK
    4. Select the Actions tab
    5. Click New... and enter the following in the New Action window:
      1. Action: Start a program
      2. Program/script: Enter the path the the bat file you created.
      3. Click OK
    6. Select the Settings tab
    7. Change Stop the task if it runs longer than: to 1 hour. There is no reason this task should run longer than a few seconds, so we put this at the shortest option.
    8. Click OK
  5. You now have a task running your bat file every 15 minutes checking if the server is up.


Notes

If you are doing work on your server and you don't want it running you will need to disable this task, otherwise it will start your server.