Jump to content

Start/Stop/Restart


swish

Recommended Posts

Luis,

 

Coming to you for help.

 

I am trying to Start/Stop/Restart using php or curl

 

What would be the proper commands to send to tcadmin to allow this?

 

Everything I have tried has restricted it due to asp.net permissions

 

Thanks in advance :)

Link to comment
Share on other sites

You need to create a page in asp.net and execute it from php with curl.

 

start.aspx:

<%
Dim service As New TCAdminSDK.Objects.Service
service.ServiceID = Request.QueryString("serviceid")
If service.Find() Then
 If service.Start() Then
   Response.Write("Success!")
 End If
End If
%>

 

start.php:

<?php
$start = curl_init("http://xxx.xxx.xxx.xxx/start.aspx?serviceid=TCXXXXXXXXXX");
curl_exec($start);
curl_close($start);
?> 

 

In IIS you can restrict access to start.aspx only for local ips or your other web server's ip.

Link to comment
Share on other sites

  • 3 months later...

Currently I have made this, named it stop.aspx and placed in a subfolder on the TCAdmin Web folder in the Webserver front-end, restricted IP access for security, but it doesn't work.

 

Contents stop.aspx:

 

 

<%

           Dim serviceid As String = Request.QueryString("serviceid")
           Dim service As New TCAdminSDK.Objects.Service
           service.ServiceID = serviceid
           If service.Find Then 
             service.Stop()
               If service.CurrentStatus = TCAdminSDK.Objects.ServiceStatus.Running Then
                       Response.Write("ERROR - Server niet gestopt!<br />")
                       Response.Flush()
               End If
               If service.CurrentStatus = TCAdminSDK.Objects.ServiceStatus.Stopped Then
                 Response.Write("Server gestopt.<br />")
                 Response.Flush()
               End If
            End If
%>

 

The address I am trying this with is:

stop.aspx?serviceid=TC64341511732211400735560

 

Which is an existing service. Also, when putting in a non-existing serviceid it gives an empty page. When I give this one, it results the message saying it is still running:

ERROR - Server niet gestopt!

 

Dutch for 'ERROR - Server is not stopped!'.

 

It is meant to stop the service, but doesn't seem to.

 

Is there anything I miss at the top part of stop.aspx or did I make an error somewhere?

Please help!

Link to comment
Share on other sites

I read your support ticket. You can find the SDK documentation in your C:\Program Files\TCAdmin Game Control Panel directory on your master server. The filename is SDK.CHM

 

However, we cannot write code for you. If your devs can read the documentation and create a working system that is great.

Link to comment
Share on other sites

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, sprintf("http://YOURADDRESS/customcommands.aspx?cmd=restart&id=%s", $_GET['id'] ));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec ($ch);
curl_close ($ch);

 

Then create a customcommands.aspx page in your tcadmin/web install folder...

 

Put the following:

 

**You need to edit the code to include your ADMINUSER and ADMINPASS in the place I put those two.

 

You will also need to include your USERID

 

<%@ Import Namespace="TCAdminSDK"  %>
<%@ Import Namespace="Web.billingapi"  %>

<%
   Dim cmds As ArrayList = New ArrayList(New String() {"status", "start", "stop", "restart", "suspend", "unsuspend", "user"})
   
   Dim cmd As String = Request.QueryString("cmd")
   Dim service_id As String = Request.QueryString("id")
   
   If cmd = Nothing OrElse cmds.Contains(cmd) = False OrElse service_id = Nothing Then
       Response.Write("invalid id or cmd")
       Exit Sub
   End If
   
   
   Dim Session As TCAdminSDK.Web.Session = New TCAdminSDK.Web.Session()
   Session.LogOn("ADMINNAME", "ADMINPASSWORD")
   If cmd = "user" Then
       Dim u As New TCAdminSDK.Objects.User
       u.UserID = "USERID"
       If u.Find() Then
           For Each service As TCAdminSDK.Objects.Service In u.Services
               Response.Write(service.ServerIP & ":" & service.ServerPort & "<br/>")
           Next
       End If
   End If
   
   Dim svc As New TCAdminSDK.Objects.Service()
   svc.ServiceID = service_id
   
   If svc.Find Then
       If cmd = "status" Then
           Response.Write(svc.CurrentStatus.ToString.ToLower)
       ElseIf cmd = "suspend" Then
           If svc.StartupType = Objects.ServiceStartup.Disabled Then
               Response.Write("server is already suspended")
           Else
               Try
                   svc.Suspend(False)
                   Response.Write("service suspended")
               Catch ex As Exception
                   Response.Write("could not suspend server: " & svc.GetLastError.Source & "<br/>" & svc.GetLastError.Message)
               End Try
           End If
       ElseIf cmd = "unsuspend" Then
           If svc.StartupType <> Objects.ServiceStartup.Disabled Then
               Response.Write("server is not suspended")
           Else
               Try
                   svc.Enable(False)
                   Response.Write("service unsuspended")
               Catch ex As Exception
                   Response.Write("could not unsuspend server: " & svc.GetLastError.Source & "<br/>" & svc.GetLastError.Message)
               End Try
           End If
       ElseIf cmd = "start" Then
           If svc.CurrentStatus = Objects.ServiceStatus.Running Or svc.CurrentStatus = Objects.ServiceStatus.StartPending Then
               Response.Write("service is already started or starting")
           ElseIf svc.Start() Then
               Response.Write("service started")
           Else
               Dim ex As Exception = svc.GetLastError
               Response.Write(svc.GetLastError.Source & "<br/>" & svc.GetLastError.Message)
           End If
       ElseIf cmd = "stop" Then
           If svc.CurrentStatus = Objects.ServiceStatus.Stopped Or svc.CurrentStatus = Objects.ServiceStatus.StopPending Then
               Response.Write("service is already started or starting")
           ElseIf svc.Stop() Then
               Response.Write("service stopped")
           Else
               Response.Write(svc.GetLastError.Source & "<br/>" & svc.GetLastError.Message)
           End If
       ElseIf cmd = "restart" Then
           If svc.Stop() AndAlso svc.Start() Then
               Response.Write("service restarted")
           Else
               Response.Write(svc.GetLastError.Source & "<br/>" & svc.GetLastError.Message)
           End If
       End If
   End If
%>

 

You can love me later ;)

Link to comment
Share on other sites

You need to create a session. For example:

       Dim sess As New TCAdminSDK.Web.Session
       Try

           If Not sess.LogOn("admin", "password") Then
               Response.Write("Could not log in!")
               Response.End()
           End If

           ...
           ...your code here
           ...

       Finally
           sess.LogOff()
       End Try

Link to comment
Share on other sites

Archived

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

  • Who's Online   0 Members, 0 Anonymous, 4 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