Restarting the Jaguar Service with VBScript

Written By: Kevin Jordan

- 23 Mar 2006 -
















Description: This is a tool that will test to see if there are any current connections to an EAServer and then restart the jaguar service. Extra functionality was included such as a time limit on the vbscript and the ability to send email notifications.

  1. Ensure There Are No Connections
  2. Performing the Script Actions

Restarting the Jaguar Service with VBScript

This is a tool that I created that would test to see if there were any current connections to an EAServer and then restart the jaguar service. Extra functionality was included such as a time limit on the vbscript of two hours and the ability to send email notifications. We run this each night during non-peak hours using Task Scheduler.

Back in the old days all of our code was written in PowerBuilder. Well those days have come on gone with the creation of the .NET framework and these days all our new code is written in C#. Luckily Sybase created a little program called Enterprise Application Server (EAServer), so our developers didn’t have to rewrite all their old PowerBuilder code. Unfortunately, it seems to be the least stable application in our whole environment. Every time a PowerBuilder error occurs, a segment of our memory is left unavailable unless the service it runs under (jaguar) is restarted.

Ensure there are No Connections

Before restarting the jaguar service, there cannot be any current connections. To verify this, we used the built in jagtool for EA Server, by issuing the following command:

C:\Progra~1\Sybase\EAServer\bin\jagtool.bat getmonitorstats conncache

Click Here To View A Screenshot

A similar output should be returned. Connections active will need to be equal to 0 before the jaguar service can be restarted. In order for the script to retrieve the value for Connections Active while ignoring the other data, the following function is executed.

Function GetConnCache()
        Dim WShell, objFSO, fileTemp, ts, data, n, parts
 
        Set WShell = CreateObject("WScript.Shell")
        Set objFSO = CreateObject("Scripting.FileSystemObject")
 
        fileTemp = objFSO.GetTempName
        WShell.Run "C:\Progra~1\Sybase\EAServer\bin\" & _
        "jagtool.bat getmonitorstats conncache > " fileTemp,0,true
 
        Set ts = objFSO.OpenTextFile(fileTemp)
        data = split(ts.readall, vbCr)
        ts.close
        objFSO.DeleteFile fileTemp
 
        If instr(data(2),"Connections Active") Then
                parts = trim(Right(data(2), 3))
        Else
                parts = 100
        End If
 
        Set WShell = NOTHING
        Set objFSO = NOTHING
        Set ts = NOTHING
 
        GetConnCache = parts
End Function ' GetConnCache 

Let’s take this on piece by piece. First thing after variable declaration is we need to create our objects. WShell is used to run executables similar to the way we would from a command line. objFSO is used for file handling. We’re going to execute the same jagtool command that we did above, but this time save the output to a temporary file. The temporary file is then read into a string and split up into an array every time there is a new line. The file is then closed and deleted.

By looking at the output from the jagtool, Connections Active is the third line (which has an index of 2 in our array since it counts from 0). After verifying that line contains the string "Connections Active" by using instr(), the right() function looks at the last three characters on that line. All extra spaces to in front of and trailing the number are removed with trim(), leaving only the number of active connections. This function should be able to return the number of active connections up to 999.

Triple Checking the Connections

The script ensures that the server isn’t experiencing any activity by checking the number of connections multiple times before restarting the service.

' Check activeConnections every 15 seconds, if
' activeConnections = 0 three times in a row then
' restart the jaguar service
For i = 1 to 3
        If activeConnections = 0 Then
                If i = 3 ThenEnd If
 
        ' If there are current connections wait
        ' 5 minutes before retesting
        Else
                i = 0
                Wait(300)
        End If
 
        Wait(15)
Next

The counter, i, is used to keep track of the number of times, in a row, that there were not any active connections to the EA server. When the counter reaches 3, a number of other actions will take place such as copying any logs and restarting the service. If the counter’s value is less than 3, the script will wait 15 seconds before checking again (I’ll explain wait in just a second). If there are active connections to the server, the counter is set back to 0 and the script waits five minutes (300 seconds) before performing another check.

' // * Loops for a provided period of time * //
Sub Wait(intWaitTime)
        Dim currentTime, doneTime
 
        doneTime = DateAdd("s", intWaitTime, Now)
        Do
                currentTime = Now
        Loop Until currentTime >= doneTime
 
End Sub ' Wait 

The script calls the Wait subroutine before retesting the number of active connections. Wait works by taking the current date and time, Now, and adding the specified number of seconds with the built in DateAdd function. A loop compares the new doneTime to the current time over and over again until currentTime exceeds our specified doneTime.

Next >>