
Tired of that unknown mod crashing your server while in raid? Well say no more! This PowerShell script will automatically restart the server to save your raid!
***WORKS WITH ALL VERSIONS OF SPT***
SPT-Server-Monitor
=================
Launches, monitors, relaunches if crashed, and restarts your server on any time zone you want. Please keep in mind that you will have to edit the script a bit and having some experience with scripting/coding is necessary. I highly recommend Visual Studio or NotePad++.
DOES NOT display what mod crashed your server.
Huge shoutout to Ekuland and Shynd for helping me out with minor problems! Much appreciated!
Also, please note that this PowerShell script is completely open source, and I will NOT ask you why you want to know something about the script. Although very simple I do believe in the actual meaning behind open source. Although you may be asked questions on why you want to know something about an open-source project elsewhere *cough* I will not question you in your motives as this is mine and I make the rules for whatever I make. Enjoy a COMPLETELY OPEN-SOURCE script free of charge and without question. Some people need to understand the true definition of open-source software. Being selfish over something you claim to be open-source makes it not open-source. All I ask is that if you make any changes and publish them, please give me credit as I spent two painful hours trying to get PowerShell to do what I wanted.
=================================================================
Instructions on how to use the script are on my github.
=================================================================
What It Does:
===========
- Launches the server in High Priority mode
- Monitors to see if the server is open or not
- Relaunches the server if the server has crashed
- Restarts the server daily at 12 AM EST
Reason for Script:
Some mods have the habit of crashing the server randomly, especially during a raid, so this is a safeguard to prevent the server from completely dying during your raid. It will allow you to extract, save your gear, then figure out what mod is crashing your server.
The automated restart is for those who like to keep the server open.
Notes from Revin:
This script is still under development, and I am open to any suggestions that you all may have, and I will consider each and every one one of them if they’re possible. I will be adding new things to it in the future, and I really hope that this mod helps you all out! Thank you for the support and may you all have a wonderful and blessed day.
Currently working on:
Turning this into an executable, like SVM, that can be ran without the need of the script. I am also adding cool little features to it.
2.0K Downloads
v1.01.2 Changes:
- “Log-CrashTime” function now accepts a reason parameter, which includes the reason for the crash.
- The “Monitor-Program” function captures any errors when trying to retrieve the process and logs those errors if the process is not found. This way, the log file will include both the timestamp and the reason for each crash. This, however, will not tell you what mod potentially crashed your server. It will explain other reasonings as to why it crashed.
433 Downloads
v1.01.1 Changes:
Changes and Fixes:
- Corrected Priority Setting Ensured the priority is set to High using [System.Diagnostics.ProcessPriorityClass]::High.
- Improved Time Zone Handling. Used a try-catch block to handle invalid time zone IDs gracefully.
- Monitoring in a Separate Session:
- Corrected the arguments for Start-Process to ensure the monitoring script starts correctly in a new PowerShell window.
- Ensured the Main Script Exits If Program Already Running. Checked for existing instances of the program and exited if found, to avoid multiple instances running simultaneously.
- Fixed Time Zone Conversion and Restart Logic. Simplified and corrected the logic to restart the program at the specified time.
214 Downloads
- Added the ability to change the time zone
- Set the script to run in High Priority (was set to Realtime)
- Changed the text to display “High Priority” instead of “Realtime”
Details
-
GUID
Not Available
-
License
-
Latest Version VirusTotal Result
Turns out to get it to work for me was adding this line
$startInfo.WorkingDirectory = “F:\SPT SERVER” so it Became
function Start-Program { $process = Get-Process -Name $ProgramName -ErrorAction SilentlyContinue if (-not $process) { Write-Output “Starting $ProgramName with high priority…” $startInfo = New-Object System.Diagnostics.ProcessStartInfo $startInfo.FileName = $ProgramPath $startInfo.Arguments = “” $startInfo.UseShellExecute = $true $startInfo.CreateNoWindow = $false $startInfo.WorkingDirectory = “YOUR_SERVER_LOCATION” # <- ADD THIS LINE $process = [System.Diagnostics.Process]::Start($startInfo) Start-Sleep -Seconds 5 if ($process) { $process.PriorityClass = [System.Diagnostics.ProcessPriorityClass]::High Write-Output “$ProgramName started and set to high priority.” } else { Write-Output “Failed to start $ProgramName.” } } else { Write-Output “$ProgramName is already running.” } return $process } Added line 10
Otherwise great script
Forgot to update the tag. Apologies all.
- Relaunches the server if the server has crashed
Is it the same if I.. lets say close server window by accident? Will it restart server instantly?
Will game while in raid or in hideout crash when server window is closed manually?
I am curious how this works.
Just a heads up. I had an issue where powershell would instantly close after running. I had to unblock the file to get it working. If this is an issue you might have, you should be getting a terminal output letting you know to unblock the file, together with a security input.
MS page to the unblockfile cmdlet. Just do Example 1 with the path to where the file is located on your PC. (Powershell has cyclic autocomplete when pressing tab btw to save you a few secs)
Hiya!
I’m hosting my own server and am going to be using this as a failsafe for when it crashes.
Just to make sure, the final result of the launch should only be the Powershell window with the process ID and the server console from SPT.server right? Nothing else should be up?
Update: if no connection attempt is made to the SPT server for an hour or so, the server will freeze and does not accept any connection attempts unless restarted.
Hey there. I really like this plugin, and was wondering if you could give me some tips: I’ve got it working great normally, but I have been attempting to get it to run through task scheduler via powershell, and have had zero success. It simply will not run for me via task scheduler, but it works fine normally opening it with powershell.
Any tips?
perhaps you should make video on how to do this… I followed the steps and whenever I ran the script with powershell as administrator it starts up for 1 second and then closes. I tried using the advice given on one of the comments and still to no avail.
If I wanted to change the server restart to 5:30am instead of 12am would I just change this line?
if ($currentTime.Hour -eq 0 -and $currentTime.Minute -eq 0
to
if ($currentTime.Hour -eq 5 -and $currentTime.Minute -eq 30
Thank you for this script!
do i just put
[string]$TimeZoneId=“Central European Time”
in timezone id? if im CET?