Way of making a Teamspeak server auto start on crash?

John Connor

Lifer
Nov 30, 2012
22,757
618
121
So I was trying a batch file I found on the Internet that supposedly made applications that crashed restart, but it didn't work. I also tried three auto start applications to restart an app if it crashes. One app I tired which seemed promising because it allowed you to add a parameter to the start up the application (which is what I need for my Teamspeak server), but it would start and stop the server constantly. I could never seem to get it to work right.

Is there a program or a specific batch file that can monitor the Teamspeak server and when there is a crash it will auto start the server again? I couldn't find anything on the Internet relating to batch files and Teamspeak.

The app that seemed promising is called Knas restarter. I need a specific parameter that launches the server. Right now in the server's shortcut on the desktop in the target area I have a parameter to launch with specifics given from an .INI file that tells the server what ports to use as I don't use the default ports.
 

Ken g6

Programming Moderator, Elite Member
Moderator
Dec 11, 1999
16,620
4,537
75
Usually this should be a very simple batch file, e.g.:

Code:
:restart
[code to start teamspeak here]
goto restart

If that doesn't work - usually because it starts multiple instances or tries to - you might need something more complicated.

If it tries to start multiple instances but that has no effect you might stick a timeout in there too.
 

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
14
81
www.markbetz.net
Usually this should be a very simple batch file, e.g.:

Code:
:restart
[code to start teamspeak here]
goto restart
If that doesn't work - usually because it starts multiple instances or tries to - you might need something more complicated.

If it tries to start multiple instances but that has no effect you might stick a timeout in there too.

Will that wait on the process by default? Been awhile since I played in the windows command shell.
 

Ken g6

Programming Moderator, Elite Member
Moderator
Dec 11, 1999
16,620
4,537
75
That's the question. It won't if you use "start". If you don't use start it might or might not. If it doesn't wait on the process, but doesn't start a second process, add that timeout and it might still work.
 

sm625

Diamond Member
May 6, 2011
8,172
137
106
Code:
:restart
start /wait teasmpeak.exe -myparams
goto restart

The problem is, what happens if it crashes and there is some stupid little box you have to click in order for the exe to go away? What you really want is to either

a) be able to issue a remote reset command for your server, which simply kills the process and/or any associated processes.
b) have it detect that a crash has occured even though the exe is still running, then kill the process so the batch file can start it again.
 
Last edited:

TheRyuu

Diamond Member
Dec 3, 2005
5,479
14
81
You could create a task (on Windows) or a cron job (on linux) to check that the Teamspeak process is running. Just set that to run every five minutes (or whatever interval you want) and have it start another instance if it isn't running.

A better question I have is why is Teamspeak crashing? I think you're asking how to solve the wrong problem here.
 

John Connor

Lifer
Nov 30, 2012
22,757
618
121
Teamspeak isn't crashing, I just want to prevent a shut down just incase it does crash. I had a batch file to auto restart a GTA San Andreas server so that's where I got the idea.
 

Spungo

Diamond Member
Jul 22, 2012
3,217
2
81
Ken g6 has the easiest and probably best solution.

A more complicated one would use the "tasklist" command to get a list of running programs. You can check your programs against the list to see which ones need to be started.

written in Perl, testing for notepad.exe:
Code:
use warnings;
use strict;

while (1) {
	my @tasks = `tasklist /fi "imagename eq notepad.exe"`; 	#get task list for notepad.exe

	my $failed = 1;				
	foreach (@tasks) {
		if (/notepad\.exe/i) { 	#looking for notepad.exe, case insensitive
			$failed = 0;  		#found it! 
		} 
	}
	if ($failed) {
		system('start "" notepad.exe'); 	#restart notepad.exe
	}
	sleep 10; 					#sleep for 10 seconds
}


I'm thinking you should have some kind of logging system when doing this so you know if your server is crashing a lot.

Code:
:restart
"c:\program files\teamspeak\teamspeak.exe"
echo "Server crashed %date% %time%" >> "C:\teamspeaklogs\log.txt"
goto restart
 

bzb_Elder

Member
May 25, 2011
86
13
71
I asked about Windows and access to the box because I'm thinking along the lines of the old SrvAny -- run as service method. I've set up several applications over the years to run as a Windows service (most recently MagicJack) and it has always worked well for me. For a Teamspeak server this seems like a viable option.

I haven't used this specific tutorial, but it seems decent enough:
http://www.howtogeek.com/50786/using-srvstart-to-run-any-application-as-a-windows-service/
 

John Connor

Lifer
Nov 30, 2012
22,757
618
121
It's on Windows. I need to start the server with an argument (parameter). Will Srvstart do that?
 

bzb_Elder

Member
May 25, 2011
86
13
71
John, I tried Srvstart tonight and didn't have any success. I did however have success using the Windows SC command to create a service. I whipped up a little .exe that accepts a parameter and created the service using the following command:

sc create MyService binpath= "d:\temp2\WindowsApplication1.exe MyParameter" type= share start= auto

The .exe simply created a text file containing the parameter that I passed in (MyParameter). I would presume at this point that this should be all you need to get Teamspeak running as a service. I'm on Windows 7 for what it's worth.

Here's the technet article I found / used for SC. https://technet.microsoft.com/en-us/library/cc990289.aspx

If you try this method, do take note of the spaces after the equals signs in the create command. The spaces are required.

HTH
 

Merad

Platinum Member
May 31, 2010
2,586
19
81
You could create a task (on Windows) or a cron job (on linux) to check that the Teamspeak process is running. Just set that to run every five minutes (or whatever interval you want) and have it start another instance if it isn't running.

IIRC Windows tasks can't run more than once a day. This would be fairly trivial on *nix with a cron job. Hell if this is a significant issue I'd probably just run the server in a Linux VM before I messed with jumping through all the hoops describe in previous posts. :)
 

sm625

Diamond Member
May 6, 2011
8,172
137
106
Windows tasks can run once a minute if you want. I have one that does exactly that.
 

John Connor

Lifer
Nov 30, 2012
22,757
618
121
John, I tried Srvstart tonight and didn't have any success. I did however have success using the Windows SC command to create a service. I whipped up a little .exe that accepts a parameter and created the service using the following command:

sc create MyService binpath= "d:\temp2\WindowsApplication1.exe MyParameter" type= share start= auto

The .exe simply created a text file containing the parameter that I passed in (MyParameter). I would presume at this point that this should be all you need to get Teamspeak running as a service. I'm on Windows 7 for what it's worth.

Here's the technet article I found / used for SC. https://technet.microsoft.com/en-us/library/cc990289.aspx

If you try this method, do take note of the spaces after the equals signs in the create command. The spaces are required.

HTH


Well crap. I'm using XP on this netbook that I use for the TS server.
 

bzb_Elder

Member
May 25, 2011
86
13
71
Well crap. I'm using XP on this netbook that I use for the TS server.
I'd probably stop using XP sooner than later, especially for a machine that is accepting inbound connections from the internet. But that's another topic...

According to Microsoft, the SC command I referenced works on XP.
 

John Connor

Lifer
Nov 30, 2012
22,757
618
121
It's a netbook! LOL I'm a little stuck with XP, but I use peerblock and block a lot of rouge countries and have ant-virus and a firewall. I changed the ports to something well above 20000.

Edit- My Teamspeak server starts with an argument (parameter). This argument when the .EXE is lauched starts an .INI file. This .INI file is what Teamspeak uses to know what ports to use. How do I start Teamspeak.exe with a parameter as a service? I don't see an argument in the description on the MS site.
 
Last edited:

Scarpozzi

Lifer
Jun 13, 2000
26,391
1,780
126
I would probably attack it the way Spungo suggested. In linux, it's pretty easy to get a list of running processes and pipe that into grep for a specific named daemon.

You can do the same thing in Windows if you have powershell installed by using "Get-Process" and piping the results into a search. On

Sort of like this:
$var = (Get-Process | Select-Object name,id|Where {$_.name -eq "NAMEOFPROCESS"})
If ($var.id) {echo "$var.name is running}
Else { Start-Process -FilePath C:\teamspeak\teapspeak.exe } #Google start-process powershell for syntax...I'm just riffing on possibilities. You could also just do a "invoke-expression ". c:\teamspeak\yada..."
 

cabri

Diamond Member
Nov 3, 2012
3,616
1
81
Back in '03, I wrote a small monitoring app and then used a similar type wrapper to turn it into a service on that would run on XP servers for a cable company supporting VOD
 

TheRyuu

Diamond Member
Dec 3, 2005
5,479
14
81
It's a netbook! LOL I'm a little stuck with XP, but I use peerblock and block a lot of rouge countries and have ant-virus and a firewall. I changed the ports to something well above 20000.

Edit- My Teamspeak server starts with an argument (parameter). This argument when the .EXE is lauched starts an .INI file. This .INI file is what Teamspeak uses to know what ports to use. How do I start Teamspeak.exe with a parameter as a service? I don't see an argument in the description on the MS site.

That's what we call security through obscurity[1] aka it's not actually a security practice.

Nothing is going to change the fact that Windows XP lacks mitigation techniques like ASLR and is an all around bad idea regardless of any precautions you might have taken. EMET can be useful on XP but it still doesn't change the fact that XP sucks for security.

[1] https://en.wikipedia.org/wiki/Security_through_obscurity