[COI]Naaaath

Windows Server Restarter (PowerShell Script)

5 posts in this topic

Hello!

I've come here to share my method of closing and restarting my server, For some odd reason I was having issues with .bat scripts and I remembered PowerShell is also an option and i've had no issues with it since.

 

Powershell script -> Save as Restarter.ps1 - Change the ArguementList accordingly and the process affinity.

Get-Process | Where-Object { $_.Name -eq "arma3server" } | Select-Object -First 1 | Stop-Process
Start-Sleep -s 5
Start-Process arma3server.exe -ArgumentList "-mod=@exile;@mas;@NATO_Rus_Vehicle; -servermod=@ExileServer;@infiSTAR_Exile;@a3_dms;@a3_custom;@A3XAI; -config=@ExileServer\config.cfg -port=2310 -profiles=Config\log -cfg=@ExileServer\basic.cfg -name=Exile -autoinit -enableHT -malloc=tbbmalloc2 -high -maxMem=8192"
Start-Sleep -s 2

$instances = Get-Process arma3server
foreach ($i in $instances) {
    $i.ProcessorAffinity=255
}

 

Affinity Explanation

        If you have 4 Cores you would do -> 1+2+4+8 = 15, so you would change $i.ProcessorAffinity=255 to $i.ProcessorAffinity=15


        # Set Processor Affinity by adding the number together. For cores 1 – 4 its 15 for example.
        # 1 (CPU 1)
        # 2 (CPU 2)
        # 4 (CPU 3)
        # 8 (CPU 4)
        # 16 (CPU 5)
        # 32 (CPU 6)
        # 64 (CPU 7)
        #128 (CPU 8 )

Task Scheduler ----------

First setup your Task Scheduler to the correct time and then go to the Actions tab and select "New"

 

Program/script

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

Add arguments

C:\Arma\Altis\Restarter.ps1 (Script location)

Start in

C:\Arma\Altis\      (Folder where the script is)

Edited by [COI]Naaaath

Share this post


Link to post
Share on other sites

holy shit this looks complex for such a small task.

 

I tried to make it myself as easy as possible:

 

arma3server_start.bat

D:\a3master1\arma3server.exe -serverMod=@ExileServer;@zbe_cache; -mod=@Exile;@Ryanzombies; -ip=YOURIP -port=YOURPORT -malloc=tbb4malloc_bi -profiles=config -config=config\server.cfg -cfg=config\basic.cfg -name=arma3 -autoinit -enableHT
timeout /T 5
exit

 

arma3server_stop.bat

taskkill /f /im arma3server.exe

 

just add those with your favourite timings to microsofts task management system , config your exile with these timings - go

 

for portability/multi server use , rename the arma3server.exe to for example arma3server_dev.exe , so you can taskkill it without closing all instances

Edited by hieve

Share this post


Link to post
Share on other sites
Advertisement

holy shit this looks complex for such a small task.

 

I tried to make it myself as easy as possible:

 

arma3server_start.bat

Hidden Content

 

arma3server_stop.bat

Hidden Content

 

just add those with your favourite timings to microsofts task management system , config your exile with these timings - go

 

for portability/multi server use , rename the arma3server.exe to for example arma3server_dev.exe , so you can taskkill it without closing all instances

I was having problems with task kill saying "Out of Memory" , it looks complicated but does exactly the same thing :D It's still a case of copy + paste and setup task scheduler.

Share this post


Link to post
Share on other sites

Nice share. 

Powershell is way better than batch. 

There is different opinions about it, however I'm still using batch, but I've also spent several hours making my batch, actually working on a actual application to take care of all this business. (I may release it even, when I get everything sorted out (It's based on a global configuration file from which you define all paths, mods etc etc.)) 

But a good tip for everyone: 

I've had several occasions where my server all of a sudden got into hung state / not responding, and were inaccessible until I manually force closed the application. 

So do yourself a favor and make checks for if application is not responding etc, it's a lifesaver B|  

Share this post


Link to post
Share on other sites

Batch is great for very simple tasks, but if you want any significant control flow it will be simpler in powershell. Powershell also seems a lot more expressive and does not rely on that huge amount of external applications as a batch script does if you want to control stuff other than "start something with these arguments".

For my server I wrote a few scripts, that lints over my mods sources, "pboizes" the necessary files, puts together a server environment folder, updates, starts, stops and monitors the server. Once I have them in a presentable state, I'd be happy to share them.

My point is that, when a script gets bigger, more functional, the complexity increases a lot faster in batch, than it does in powershell.

Share this post


Link to post
Share on other sites
Advertisement

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.