Jump to content

Restart game servers


LFA

Recommended Posts

Remember to set waitForUserAction to false if you run this as a scheduled task

 

 

 

These scripts should be run on the master server since they restart all the game servers on every machine.

 

 

 

Restart all game servers:

 

 

 

<tcascript> 
<language name="VB" /> 
<waitForUserAction value="true"/> 

<scriptCode><![CDATA[ 

Imports System 
Imports TCAdminSDK.Objects

Public Class RestartGameServers
  Public Shared Sub Main() 
     'Get a list of all services
     Dim services() As Service = Service.GetServices() 
     for each s as Service in services 
           If s.CurrentStatus = ServiceStatus.Running Then
               Console.WriteLine("Restarting " & s.ServiceID)
               s.Stop()
               Threading.Thread.CurrentThread.Sleep(1000)
               s.Start()
               'Wait a few seconds before restarting the 
               'next service to avoid high loads on server
               Threading.Thread.CurrentThread.Sleep(10000)
           End If
     next 

     Console.WriteLine("Done. Press any key to continue.") 
  End Sub 
End Class 

]]></scriptCode> 

</tcascript>

 

 

 

 

 

 

 

Restart all game servers that have a specific game id. Just replace TCXXXXXXXXX with the game id you want to restart

 

 

<tcascript> 
<language name="VB" /> 
<waitForUserAction value="true"/> 

<scriptCode><![CDATA[ 

Imports System 
Imports TCAdminSDK.Objects
Public Class RestartGameServers
  Public Shared Sub Main() 
     'Set the game id to restart
     dim GameID as string = "TCXXXXXXXXX"

     'Get a list of all services
     Dim services() As Service = Service.GetServices() 
     for each s as Service in services 
           If s.CurrentStatus = ServiceStatus.Running and s.GameId.Equals(GameID) Then
               Console.WriteLine("Restarting " & s.ServiceID)
               s.Stop()
               Threading.Thread.CurrentThread.Sleep(1000)
               s.Start()
               'Wait a few seconds before restarting the 
               'next service to avoid high loads on server
               Threading.Thread.CurrentThread.Sleep(10000)
           End If
     next 

     Console.WriteLine("Done. Press any key to continue.") 
  End Sub 
End Class 

]]></scriptCode> 

</tcascript>

Link to comment
Share on other sites

  • 2 weeks later...
  • Replies 50
  • Created
  • Last Reply

Stop only.

 

 

 

<tcascript> 
<language name="VB" /> 
<waitForUserAction value="true"/> 

<scriptCode><![CDATA[ 

Imports System 
Imports TCAdminSDK.Objects

Public Class RestartGameServers
  Public Shared Sub Main() 
     'Get a list of all services
     Dim services() As Service = Service.GetServices() 
     for each s as Service in services 
           If s.CurrentStatus = ServiceStatus.Running Then
               s.Stop()
           End If
     next 

     Console.WriteLine("Done. Press any key to continue.") 
  End Sub 
End Class 

]]></scriptCode> 

</tcascript>

 

 

 

 

 

Start only.

 

 

 

<tcascript> 
<language name="VB" /> 
<waitForUserAction value="true"/> 

<scriptCode><![CDATA[ 

Imports System 
Imports TCAdminSDK.Objects

Public Class RestartGameServers
  Public Shared Sub Main() 
     'Get a list of all services
     Dim services() As Service = Service.GetServices() 
     for each s as Service in services 
           If s.StartupType <> TCAdminSDK.Objects.ServiceStartup.Disabled Then
               s.Start()
               'next service to avoid high loads on server 
               Threading.Thread.CurrentThread.Sleep(10000)
           End If
     next 

     Console.WriteLine("Done. Press any key to continue.") 
  End Sub 
End Class 

]]></scriptCode> 

</tcascript>

Link to comment
Share on other sites

  • 2 weeks later...
  • 6 months later...
  • 3 weeks later...

Howdy

 

 

 

I am using the restart script but want to add more game id's

 

 

 

Public Shared Sub Main()

 

'Set the game id to restart

 

dim GameID as string = "TCXXXXXXXXX"

 

 

 

Do i just

 

Public Shared Sub Main()

 

'Set the game id to restart

 

dim GameID as string = "TCXXXXXXXXX; TCXXXXXXXXX; TCXXXXXXXXX"

 

 

 

or do I have to do a seperate script for each one?

Link to comment
Share on other sites

Setup a seperate script for each one would probably be the best way to do it. That way you can specify different times in the scheduled task as to avoid lagging your servers with a ton of games all resatrting at the same time.

 

 

Link to comment
Share on other sites

  • 5 months later...

I see all servers, and all servers on a specific game, but what could I do to just restart 1 specific server which keeps doing wierd things after being up for a long time.

 

 

 

Also where do I run this script from?

Link to comment
Share on other sites

Use the script and change this line:

 

Dim services() As Service = Service.GetServices()

 

 

 

To:

 

Dim services() As Service = Service.GetServicesByUserId("YourClientUserId")

 

 

 

Replace YourClientUserId with your client's id.

Link to comment
Share on other sites

  • 3 months later...

i cant seem to get this to run. I know im doing it wrong just dont know what. (first time looking at the scripts for TCAdmin and have no idea!!)

 

I am looking to get the script to start just the one server. and just have a schedueled task to run it / them.

 

Trouble is i have copied / pasted the code from the first post and changed the TCService ID, but it then just opens a console box and sais:

 

An exception occured while compiling the script

Object reference not set to an instance of an object.

 

IS there a specific place i need to run this from? any pointers?

 

Thanks

Link to comment
Share on other sites

ye s i know. thats already been edited to the TC game ID, i know it restarts game servers. thats what i want. i was physically sitting in the server at the time and it did not restart. Although i have tried both, the TCAdmin service ID that needs to be in there. should it be the longer or shorter one (shorter one being the one in the blocked out box when editing a server. Longer appearing just above that) and im assuming the script can be run from anywhere on the master server?

 

Thanks

Link to comment
Share on other sites

Find the service name for that server in the services list and create two batch files. One for start and one for stop.

 

Start one would look like this

 

net start <servicename>

 

 

Stop one will look like this

 

net stop <servicename>

 

Then you can set 2 windows scheduled tasks. 1 for start and 1 for stop at whatever times you would like.

Link to comment
Share on other sites

do you guys know a quicker method to get the status of all services? im using this code but its very sluggish with ~100 servers

 

	Dim services() As Service = Service.GetServices() 
		for each s as Service in services 
			If s.ServiceID.Equals( id ) Then
				return  s.CurrentStatus
			end if
		next 

Link to comment
Share on other sites

  • 5 months later...

Archived

This topic is now archived and is closed to further replies.

  • Who's Online   0 Members, 0 Anonymous, 21 Guests (See full list)

    • There are no registered users currently online

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Terms of Use