Server auto restart using AutoIT (Windows only)

redconfusion

New Member
Jul 29, 2019
4
0
0
I haven't had much luck finding a program to auto restart a Minecraft Server for me so designed my own.
Created this with free program AutoIT v3 at http://www.autoitscript.com/site/autoit/

Thought I'd share this with anyone else that would want it.



Just change the value of $start to the location of your start file.

What this does:
- Once a day checks the date. Every 3rd day triggers the program.
- Gives a warning 1 hour before server is shut down
- Saves world
- Restarts the server then turns off Creeper block damage

If you don't feel like installing the AutoIT program I have the compiled EXE program here:
http://www.mediafire.com/?um4z31lximxxq5l

In the EXE I changed $start to ask for the file location
- $start = FileOpenDialog("Select *.bat file for your FTB Server",@DesktopDir,"Batch (*.bat)", 1 + 4)

Code to copy and paste into AutoIT
--------------------------------------------------------------------------------------------------------------------
; Script Start - Add your code below here
$start = "C:\Users\Gamer\Desktop\FTBBetaAServer\ServerStart.bat"
While 1=1
Switch (@MDAY)
Case 3,6,9,12,15,18,21,24,27,30
resetServer()
EndSwitch
Sleep(1000 * 60 * 60 * 24) ;wait 24 hours
WEnd

Func resetServer()
WinActivate("Minecraft server") ;switch to minecraft server
Sleep(200)
WinActivate("Minecraft server")
Send("/say Server restart in 1 hour.{ENTER}")
Sleep(1000 * 60 * 15) ;wait 15 minutes
WinActivate("Minecraft server")
Send("/say Server restart in 45 minutes.{ENTER}")
Sleep(1000 * 60 * 15) ;wait 15 minutes
WinActivate("Minecraft server")
Send("/say Server restart in 30 minutes.{ENTER}")
Sleep(1000 * 60 * 15) ;wait 15 minutes
WinActivate("Minecraft server")
Send("/say Server restart in 15 minutes.{ENTER}")
Sleep(1000 * 60 * 5) ;wait 5 minutes
WinActivate("Minecraft server")
Send("/say Server restart in 5 minutes.{ENTER}")
Sleep(1000 * 60 * 4) ;wait 4 minutes
WinActivate("Minecraft server")
Send("/say Server restart in 1 minute.{ENTER}")
Send("/say Saving world...{ENTER}")
Send("/save-all{ENTER}")
Sleep(1000 * 60 * 1) ;wait 1 minute
WinActivate("Minecraft server")
Send("/stop{ENTER}")
Sleep(1000 * 60 * 1)
Run($start)
Sleep(1000 * 60 * 1)
WinActivate("Minecraft Server")
Send("/gamerule mobGriefing false{ENTER}")
EndFunc
--------------------------------------------------------------------------------------------------------------------
 

__Miguel_

Active Member
Jul 29, 2019
10
0
26
Hi there. I'm digging up the thread, but I figured it might be my best bet.

I'm trying to set up my own server at home. Right now I already have a NAS running WHS2011 (with an i7 860 and 8GB of RAM in there, which means there's plenty of headroom), so I'd like to add the Minecraft server role to it, as a service/daemon. I've tried MyMCAdmin, but it actually bogs the whole machine down (odd thing, it constantly clings to 100% of a single core, even when Java sits at 0% load), so I'l going to get rid of it. Most of the other offerings don't seem to be much better, either :(

In all honesty, I'd only need something that 1) could be handled as a service (because WHS runs without a client being logged in); 2) automatically handled backups; 3) automatically restarts the server and adds sets mob griefing to false.

This script handles 3) and 4) OK (though I'd probably add the gamerule action to the start of the script too, so mob griefing would be disabled right away), though I wonder: does this require an active console window being displayed? Also, how would one effectively backup the world? I know you need to make the server read-only for a bit, but I haven't figured out how...

Any hints? It could become a rather powerful script if it worked correctly :)

Thanks in advace!
 

redconfusion

New Member
Jul 29, 2019
4
0
0
I have tried turning my script into a service before without much luck.
I was able to turn this into service but wouldn't actually do anything until login to Windows.

Think WinActive() function will only work if your logged in.
 

__Miguel_

Active Member
Jul 29, 2019
10
0
26
Hmm, just as I suspected, unfortunately. I might be wrong, but I think "WinActivate()" actually works a window switcher (as in "activate window 'X'), which is probably the reason why that script couldn't be turned into a service reliably.

Bummer, it seems almost impossible to run a Minecraft server in Windows and having extended functionality without going through some rather MAJOR hoops... Say, since we're at this, do you think a MineOS Crux Ultimate server based on an ION platform (Atom 330 with 3GB of RAM) might do the trick for a couple of people mas (also, sorry for OTing)?

Thanks for the reply, by the way!
 

xBTx

New Member
Jul 29, 2019
42
0
0
I have tried turning my script into a service before without much luck.
I was able to turn this into service but wouldn't actually do anything until login to Windows.

Think WinActive() function will only work if your logged in.

I must have missed this post somehow, but this is correct. I'm pretty sure the login window is seen as the "active window". Out of curiosity, why not leave it logged in?
 

__Miguel_

Active Member
Jul 29, 2019
10
0
26
I can try to work something out in a bit. No promises though.
Ooo, that would be great!

Out of curiosity, why not leave it logged in?
Well, pure servers shouldn't need to have a logged in account in the first place (best practice is actually something around the lines of "access remotely from the LAN, preferably a dedicated VLAN, and never open a desktop session unless absolutely necessary"; that's why most Linux servers don't even have X installed, and Windows ones have a ton of MMC snap-ins to facilitate remote management).

Plus, actually logging in an account removes a bunch of RAM from the available pool without actually being too productive, RAM which could otherwise be made available to (in this case) the Minecraft server.
 

gosuckanelf

New Member
Jul 29, 2019
3
0
0
how could i change this to restart every 2 hours? with a 15 min countdown? and why have the creeper block thing?
 

redconfusion

New Member
Jul 29, 2019
4
0
0
There is 4 15 min delays in an hour.

Bottom code would go between these 2 lines of code.
WinActivate("Minecraft server")
Send("/say Server restart in 1 hour.{ENTER}")

Send("/say Server restart in 2 hour.{ENTER}")
Sleep(1000 * 60 * 15) ;wait 15 minutes
Send("/say Server restart in 1 hour 45 minutes.{ENTER}")
Sleep(1000 * 60 * 15) ;wait 15 minutes
Ect..

I didn't want block damage on my server I used to run. Why I had that last line.