ManipulateServer.csp


<%@ Language=JavaScript%>

<%

// This file is called from ShowServerStatus.csp and provides functions

// to start, stop, restart, enable, and disable a server.  It performs one

// of these actions on the server that was chosen in ChooseServer.csp.

%>

<!-- #include file="RetrieveIStore.csp" -->

<!-- #include file=helper_js.csp -->

<html>

<body>

<%


// Constants for the ManageServer method.    

var ceServerStart = 1;

var ceServerStop = 2;

var ceServerRestart = 3;


function StopServer(IStore, ServerId)

// Stops a server when given that server's ID.  Be careful when using this

// function to stop the WCS or APS.

{

    // Query for the server.

    var ServerInfoObject = IStore.Query

    ("SELECT SI_NAME, SI_SERVER_IS_ALIVE, SI_DISABLED, SI_SERVER_KIND "

    + "FROM CI_SYSTEMOBJECTS WHERE SI_ID="+ServerId).Item(1);

    // Get the actual Server object.

    var ServerObj = ServerInfoObject.PluginInterface("");

    if ((ServerObj.ServerKind=='aps')||(ServerObj.ServerKind=='wcs'))

    {

        Response.Write("This example does not stop the APS server or WCS server.");

        return 0;

    }

    else

    {

        // Stop the server.To run on Unix, ManageServer requires values for the parameters

        //TimeoutSeconds, UserName, and Password.

        try

        {

            ServerObj.ManageServer(ceServerStop);

            Response.Write ("Stopped");    

        }

        catch(e)

        {

            Response.Write("Unable to stop the server.")

        };

    }

}


function StartServer(IStore, ServerId)

// Starts a server when given that server's Id. To run on Unix, ManageServer requires values for the parameters

//TimeoutSeconds, UserName, and Password.

{

    // Query for the server.

    var ServerInfoObject = IStore.Query

    ("SELECT SI_NAME, SI_SERVER_IS_ALIVE, SI_DISABLED FROM CI_SYSTEMOBJECTS WHERE SI_ID="+ServerId).Item(1);

    // Get the actual Server object.

    var ServerObj = ServerInfoObject.PluginInterface("");

    // Start the server.

    try

    {

        ServerObj.ManageServer(ceServerStart);

        Response.Write ("Started");

    }

    catch(e)

    {

        Response.Write("Unable to start the server.")

    };

}


function RestartServer(IStore, ServerId)

// Restart a server when given that server's ID. If you restart the

// WCS, you will lose your session.To run on Unix, ManageServer requires values for the parameters

//TimeoutSeconds, UserName, and Password.

{

    // Query for the server.

    var ServerInfoObject = IStore.Query("SELECT SI_NAME, SI_SERVER_IS_ALIVE, SI_DISABLED FROM CI_SYSTEMOBJECTS WHERE SI_ID="+ServerId).Item(1);

    // Get the actual Server object.

    var ServerObj = ServerInfoObject.PluginInterface("");

    // Restart the server.

    try

    {

        ServerObj.ManageServer(ceServerReStart);

        Response.Write ("Restarted");

    }

    catch(e)

    {

        Response.Write("Unable to restart the server.")

    };

}


function EnableServer(IStore, ServerId)

// Enables a server when given that server's ID.

{

    // Query for the Server.

    var Servers = IStore.Query("SELECT SI_NAME, SI_SERVER_IS_ALIVE, SI_DISABLED FROM CI_SYSTEMOBJECTS WHERE SI_ID="+ServerId);

    var ServerInfoObject = Servers.Item(1);

    // Get the actual Server object.

    var ServerObj = ServerInfoObject.PluginInterface("");

    // Set Disabled to false. This tells the APS that you want to enable the server.

    ServerObj.Disabled=false;

    // Save the changes to the APS. This will enable the server.

    IStore.Commit(Servers);

    Response.Write ("Enabled");

}


function DisableServer(IStore, ServerId)

// Disables a server when given that server's ID.

// If you disable all APSs and all WCSs, you will not be able

// to query the APS or run any scripts on the WCS.

{

    //Query for the server.

    var Servers = IStore.Query("SELECT SI_NAME, SI_SERVER_IS_ALIVE, SI_DISABLED FROM CI_SYSTEMOBJECTS WHERE SI_ID="+ServerId);

    var ServerInfoObject = Servers.Item(1);

    // Get the actual server object.

    var ServerObj = ServerInfoObject.PluginInterface("");

    // Set Disabled to true to tell the APS to disable the server.

    ServerObj.Disabled=true;

    // Save the changes to the APS. This will disable the server.

    IStore.Commit(Servers);

    Response.Write ("Disabled");

}


function Main()

{

    IStore = RetrieveIStore();

    if (IStore == null)

    {

        Response.Redirect ("Start.csp");

        return;

    }

    ServerId = Request.QueryString.Item("ServerId");

    // Check to see which button was pushed and perform the appropriate

    // action on the server.

    if (Request.Form.Item("Stop") == "Stop") StopServer(IStore,ServerId);

    if (Request.Form.Item("Start") == "Start") StartServer(IStore,ServerId);

    if (Request.Form.Item("Disable") == "Disable") DisableServer(IStore, ServerId);

    if (Request.Form.Item("Enable") == "Enable") EnableServer(IStore,ServerId);

    if (Request.Form.Item("Restart") == "Restart") RestartServer(IStore,ServerId);

}


Main();

    

%>

</body>

</html>




Crystal Decisions, Inc.
http://www.crystaldecisions.com
Support services:
http://support.crystaldecisions.com