[an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] 24x7 Script Archive


Monitor Windows NT/2000 services

This example monitors Microsoft SQL Server service and automatically starts it if it is not running.

ServiceGetStatus "MSSQLServer"

// verify that the service is running or starting
Dim status, string
Dim running, boolean
ServiceGetStatus "MSSQLServer", status

IsEqual status, "RUNNING", running
IfThen running, DONE

IsEqual status, ""START PENDING", running
IfThen running, DONE

START_SERVICE:
ServiceStart "MSSQLServer"

// verify that the service is running or starting
ServiceGetStatus "MSSQLServer", status

IsEqual status, "RUNNING", running
If running, NOTIFY_OK, NOTIFY_FAIL

NOTIFY_OK:
MailSend "SMTP", "myname", "myspassword", "sysadmin@mycompany", &
      "SQL-Server Restarted", "24x7 Scheduler detected that SQL-Server was not running and successfully restarted it"
exit

NOTIFY_FAIL:
MailSend "SMTP", "myname", "myspassword", "sysadmin@mycompany", &
      "SQL-Server Restart Failed", "24x7 Scheduler detected that SQL-Server was not running, but was not able to restart it"

DONE:
// Done
Exit