Official Soldat Forums

Soldat Fans => Fan Apps => Topic started by: Shoozza on March 31, 2007, 01:22:49 pm

Title: SARS (Soldatserver Auto Restart Script)
Post by: Shoozza on March 31, 2007, 01:22:49 pm
SARS v0.2 - Soldatserver restart (on crash perl) script

About:
------

SARS is a Perl script that (kills and) restarts soldatserver when it crashed.
It checks the modification time of /logs/gamestate.txt and if has not been modified for some time it kills the soldatserver and runs it again.

There four scripts: 2 for Windows and 2 for Linux.
The script for windows works on windows server 2003.

Setup:
------

Before u run a script u need to edit the perl script:
change the $soldatserver_path and $soldatserver_args (arguments) and $soldatserver_count (when ur using SARS v0.2m)
and remove the line:
exit # remove this line!
Note that you need 2 slashes (\\) for windows

winSARS_m.pl and winSARS_s.pl are for Windows Server 2003/ Windows XP Pro and Home / Windows Vista
linSARS_m.pl and linSARS_s.pl are for Linux

*_m.pl can manage one or more servers
*_s.pl can manage one server only

You need to have perl install to run the scripts.
Get it at www.activestate.com (Windows)
or install it with the packet manager (Linux).

SARS needs the server to have logging enabled in the Soldat.ini.
If you don't want to use logging use the script to make SARS work.
Then you need to have scripting enabled.
DON'T use the script when you have logging enabled!

When you run Windows XP Home or want to kill the server with -9 (Linux) you need to enable the alternative mode.
Just change the value from 0 to 1.

If you don't want to see the actions that SARS does you need to change sowactions to
$showactions=0;

When you dont want to start the Soldatserver minimized you need to edit the runserver variable (Windows).

It's possible to change the delay when changeing mins_to_wait variable but it's not recommended.
Default delay is 3 min.

Once you setup SARS correctly you can run the perlscript.
It doesn't need to be in the soldatfolder since you use relative paths (line you can see in the script).

FOR *NIX
Run the script with "./linSARS_s.pl &" or start it in a screen.
Don't run it with "> /dev/null" since that can cause problems better just set showactions to 0 instad.

FOR WINDOWS
Double click on the perlfile or run it in cmd.exe/command.com.


Changelog:
---------
v0.2
fixed missing bracket causes syntax error when starting in linSARS_m and winSARS_m.pl
fixed starting SARS before soldatserver will quit SARS and not run the soldatserver
fixed formating errors
fixed reading of gamestats.txt when file doesn't exist
added alternative mode
added better status messages
added showactions option to hide status messages
added more detailed logmessages
added runserv option to change starting command
added SARS soldatserverscript for servers without logging enabled
changed output of dot's in a line for multiple servers


Credits:
--------
Seastorm - asking me to code that script, for testing and help
Chrisgbk - help
Everyone who uses SARS and gave me feedback.
Title: Re: SARS (soldatserver restart script)
Post by: FliesLikeABrick on March 31, 2007, 01:52:22 pm
Is there anything (aside from the need for more work) that would allow you to combine all 4 scripts into one that could meet the needs of all 4 situations?
Title: Re: SARS (soldatserver restart script)
Post by: SeaStorm on March 31, 2007, 02:04:39 pm
many thanks for this script !

Just a hint: The multi-version normally doesnt start the servers immediatley. It needs the file to be 3 minutes old, so it can take this time till it starts the servers
Title: Re: SARS (soldatserver restart script)
Post by: Shoozza on April 01, 2007, 07:00:56 am
@FliesLikeABrick
i could make a file for all 4 situations.
@SeaStorm
ill try to fix that
Title: Re: SARS (soldatserver restart script)
Post by: Thomas on April 11, 2007, 06:49:44 am
The windows script will work on XP pro but not on XP home
it uses taskkill /PID <PID> which is not available on XP home.
on windows XP home edition you can use tskill <PID> instead
Title: Re: SARS (Soldatserver Auto Restart Script)
Post by: integrii on August 17, 2008, 12:33:56 am
Thanks!

I was able to modify the linux one to take variables and run in a screen.  My automated system runs both a monitor and a server in two screens.

Thank you!!!

-Eric
SoldatHost.com
Title: Re: SARS (Soldatserver Auto Restart Script) v0.2
Post by: Shoozza on September 30, 2008, 10:19:24 am
Ok I've updated SARS. It still has different files for linux windows and single and multiple servers maybe ill merge them in the next release.

Don't hesitate to give feedback.
Title: Re: SARS (Soldatserver Auto Restart Script)
Post by: beenman123 on March 19, 2010, 12:44:14 am
Nice post. This is a great work.
Title: Re: SARS (Soldatserver Auto Restart Script)
Post by: duz on January 03, 2011, 11:11:52 am
This is the better solution for anticrash?
Title: Re: SARS (Soldatserver Auto Restart Script)
Post by: Falcon` on January 03, 2011, 06:01:01 pm
There is nothing you can do to prevent crashes. This tool just automatically restarts your server after the crash.
Title: Re: SARS (Soldatserver Auto Restart Script)
Post by: Shoozza on January 03, 2011, 06:51:25 pm
There are different ways to check for soldatserver crashes.
This tool only uses the frist two:
* check gamestat.txt for last modification time
* generate a gamestat.txt after certain time with serverscripting when logging is disabled (so that it can be checked)
* connect via tcp like admin clients do and check if it works
* soldatserver ping messages
* check if soldatserver is still running
* connect as soldatserver client

The last one isn't possible (or isn't easy to do at least) without knowing the netcode and it's going to get out of date once a new soldat version comes out.
The other solutions however could be implemented.

SARS doesn't do anything else then checking the gamestat.txt so it's not really reliable, sorry.
However it was good enough the guy I made it for.

If you want something different you can try using SRB or other restarters:
http://forums.soldat.pl/index.php?topic=35875.0
It's a bit faster in restarting the server and I made it for linux only.
Its actually only for restarting the server when it was shutdowned or in case it had a clean crash and isn't hanging etc.
So it's not really reliable either.

But maybe other scripts do a better job.
Hopefully such crash detection scripts will not be necessary in the future.

Meh I write too much. Have fun.