Automatic Steam / ARK Server Updates & Start Up using PowerShell

In this post we are going to look at automating a Steam server’s maintenance using STEAMcmd and Powershell. The game servers highlighted in the below article will be a collection of Ark game servers.

Slightly different than the usual enterprise IT content one would be familiar with on this blog. However, as of right now I have been running multiple ARK Steam servers for around a year with very minimal downtime. I attribute this long period of time to the fact that the maintenance is all automated using STEAMcmd in combination with PowerShell, thus resulting in very little attention from myself (months apart).

I figure if it’s working well for me, it could also work well for someone else who may be looking to automate their Steam server maintenance without the hassle of configuring ASM (ARK server software) or using some other form of third party software.

Before we get started, please bare in mind this will be focusing on the ARK game server, however if your Steam server uses STEAMCmd for installation, configuration and start-up, this process can be tweaked for the same functionality.

Firstly –

On your server/desktop create a folder on your C: drive, call it anything you want. In my case I called it ‘Startup’ – this is going to be the location for your future start-up scripts / batch files.

Start-up folder

After creating the folder locate the SteamCMD folder in your game server (Ark Server) files. In my case the filepath is ‘C:\ArkServer\Engine\Binaries\ThirdParty\SteamCMD\Win64’

Once located create a txt file in the folder location – (I named the file ‘ark1’) and put the following contents inside of it.

@ShutdownOnFailedCommand 1
@NoPromptForPassword 1
logon anonymous
force_install_dir C:\ArkServer
app_update 376030 validate
quit

**Make sure to change the install directory (force_install_dir) to the file location of your gaming server
**Also make sure the app_update number is the correct number for your particular gaming server, 376030 is Arks dedicated installation/update number.

Ark text file

In short this text file contains the SteamCMD commands required to initiate a server update check, and if found the server update itself.

Next step involves creating a Batch file in your ‘Start up’ folder – I named the batch file ‘UpdateServer.bat’ – This batch file will be used by the soon to be created PowerShell script to force SteamCMD to run using the commands we laid out in the ‘ark1’ txt file.

The contents of the batch file should be –

steamcmd +runscript ark1.txt
exit

** To save the contents of a new page in notepad as a batch file you need to make sure ‘All Files’ is selected on the ‘Saves as types drop down’ and ‘.bat’ is used at the end of the file name’

As shown in the image below –

Batch file

After that you are going to want to put your server start-up batch files inside this folder location – as shown in the image above my game servers are Abber, Rag, Rag-PVP, TheCenter and TheIsland.

Just for clarification, an example of the contents of one of these server start-up batch files is –

start ShooterGameServer.exe Aberration_P?SessionName=PVE-NoWipes-Gath6x/Bre6x/Tam3x/Exp10x/S+/Stacking[Clustered]?Port=50025?AltSaveDirectoryName=AbberSaved?
QueryPort=50026?MaxPlayers=100?RCONEnabled=True?RCONPort=32335?
ServerAdminPassword=Helloboss?OverrideOfficialDifficulty=5.0 -clusterid=Arkserver1 -automanagedmods -AutoDestroyStructures -OverrideOfficialDifficulty=5.0 -ForceRespawnDinos

Now you have moved your server startup files into the ‘Start-up’ folder location – you can proceed onto the second to last step of creating the PowerShell script using Windows PowerShell ISE.  – I named the script ‘ServerScheduledRestart.ps1’

The contents should include some thing similar to the contents of mine shown below –

**Make sure to change the variables to match the file-paths/names of your server start-up batch files.
**Remove anything that is un-needed, in my case I’m running three servers so my script includes these three.

$ErrorActionPreference = 'SilentlyContinue' #If an error occurs continue the script

$runpathUpdate = "C:\Startup\UpdateServer" 
$runpathRag = "C:\Startup\Rag" 
$runpathAbber = "C:\Startup\Abber" 
$runpathTheIsland = "C:\Startup\TheIsland" 


Start-Process -FilePath $runpathUpdate #Runs server update batch file

Start-Sleep -s 700 #Waits 700 seconds before continuing, as to give SteamCMD time to check/update the server files

#Ends all the ARK Server processes
Stop-Process -processname ShooterGame
Stop-Process -processname ShooterGame
Stop-Process -processname ShooterGame
Stop-Process -processname ShooterGameServer
Stop-Process -processname ShooterGameServer
Stop-Process -processname ShooterGameServer

Start-Sleep -s 10

Start-Process -FilePath $runpathAbber #Runs the Abberations server start-up batch file

Start-Sleep -s 300

Start-Process -FilePath $runpathRag #Runs the Ragnorak server start-up batch file

Start-Sleep -s 350

Start-Process -FilePath $runpathTheIsland #Runs TheIsland server start-up batch file

Start-Sleep -s 30

Incase you’re unfamiliar with PowerShell ISE – please see the image below, this is what your script should look like inside the program, once copied and tweaked you can go to File on the top left and save the ps1 to your ‘Startup’ folder.

PowerShell iSE

Once your script is created and in the right location – it’s time to move onto the final step, which involves setting up a scheduled task to run the ‘ServerScheduledRestart.ps1’ PowerShell script every night or early morning.

Firstly navigate to ‘Task Scheduler’ in your Windows OS

Task Scheduler

Then click on ‘Create a Basic Task’ on the top right. From here just go through the easy wizard.

Give the scheduled task a name –

New task

Then select the start date and time –

Task Time

Next select the ‘start a program’ radio button, followed by inputting the following text, including the filepath of your PowerShell script –

Task start a program file ps1

After that click Next and Finish.

If done successfully you should see your scheduled task with the following actions as shown in the image below –
Task completed


Thats it! All the steps are now completed. Your Steam server(s) should now update and restart everyday at the time you chose for the foreseeable future.

Concerning ARK servers, to make sure your mods auto-update on start-up, add ‘-automanagedmods‘ to your start-up batch file.

 

 

Thanks for reading – feel free to follow and stay updated 🙂 View sysadminguides’s profile on Facebook View GuidesSysadmin’s profile on Twitter View 115372466162675927272’s profile on Google+

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s