Script to check if SABnzbd is running when as a service and if not restart it.

Come up with a useful post-processing script? Share it here!
Post Reply
relman
Release Testers
Release Testers
Posts: 46
Joined: September 30th, 2008, 2:42 am

Script to check if SABnzbd is running when as a service and if not restart it.

Post by relman »

Hi all, I wrote this script due to having problems after following the wiki to make SABnzbd run as a windows service. I found although the service shows as "Started" the web site was unresponsive. This script checks if the website is alive , if not it will stop then start the service which resolves the problem. Just set it up as a windows scheduled job.

Code: Select all

' Script to check site is running and if not restart service

Dim objShell 
Dim strWebsite
Dim strIPaddress
Dim strPortnum

' ### Change to your IP address ###
strIPaddress = "192.168.0.120"

' ### Change to your Port number ###
strPortnum = "443"



strWebsite = strIPaddress & ":" & strPortnum & "/sabnzbd"

If PingSite( strWebsite ) Then

'
' ### Put this here to enable you to check script is running, just comment
' ### it out once its up and running.
   ' WScript.Echo "Web site " & strWebsite & " is up and running!"
Else

	set objShell = wscript.createObject("wscript.shell")
    	strTmp = "Net stop SABnzbd" 
	objShell.Run strTmp
	strTmp1 = "Net Start SABnzbd" 
	objShell.Run strTmp1
End If


Function PingSite( myWebsite )

    Dim intStatus, objHTTP

    Set objHTTP = CreateObject( "WinHttp.WinHttpRequest.5.1" )

    objHTTP.Open "GET", "http://" & myWebsite & "/", False
    objHTTP.SetRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MyApp 1.0; Windows NT 5.1)"

    On Error Resume Next

    objHTTP.Send
    intStatus = objHTTP.Status

    On Error Goto 0

    If intStatus = 200 Then
        PingSite = True
    Else
        PingSite = False
    End If

    Set objHTTP = Nothing
End Function

Post Reply