You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Koen Vingerhoets <ko...@ubench.com> on 2002/07/22 19:05:01 UTC

IBM HTTP - Win 2000 - http alive?

Hi,

I was wondering how I could check whether the HTTP server is still running
under Windows 2000.
I only know how to do it in Linux, and now I have this weird machine in my
hands... I really have no clue how to check and restart the HTTP server when
needed.
All help is much appreciated :)

Thanks!!


Koen Vingerhoets

***** UBench nv *****
http://www.ubench.com
____________________________________________
The information contained in this electronic mail message is privileged and
confidential,
and is intended only for use of the addressee. If you are not the intended
recipient, you
are hereby notified that any disclosure,reproduction, distribution or other
use of this
communication is strictly prohibited.

If you have received this communication in error, please notify the sender
by reply
transmission and delete the message without copying or disclosing it.



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: IBM HTTP - Win 2000 - http alive?

Posted by Jeff White <jl...@earthlink.net>.
Nice job!

> A few things I didn't understand but (like all the values and return
values
> and such from WMI)

> I now have 2 days newbie experience
> with VB)

VBS (VBScript) not Visual Basic (VB)!

They are close though.   :)

> or to give comments.

Talking about comments,
where are they in the script?   :)

>
> objService.StartService()
>

Using a method here, does it
return a value or change a "stored"
value somewhere?

Dim returnValue

returnValue = objService.StartService()

Values 0 - 24 are returned.

0 = The request was accepted.
6 = The service has not been started.
10 = The service is already running.
And so on.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisd
k/wmi/startservice_method_in_class_win32_service.asp

> For each obj2Service in col2ListOfServices

By values here, I mean Win32_Service ( and most
WMI classes) return a bunch of properties, try

wscript.echo "Caption: " & obj2Service.Caption

wscript.echo "Will the service allow stopping? "
if (obj2Service.AcceptStop)
  wscript.echo "Yes"
else
  wscript.echo "No"
end if

wscript.echo "Display Name: " & obj2Service.DisplayName
wscript.echo "Service Path: " & obj2Service.PathName

There are two Apache web servers running, but one is dead - what is
this one's process ID ( PID ), so later - what ever?

wscript.echo "This web server is process ID number:  " &
obj2Service.ProcessID

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisd
k/wmi/win32_service.asp

> obj2Service.StopService()

Using a method here.

returnValue = obj2Service.StopService()

0 = stopped
anything else is an error, but what error?

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisd
k/wmi/stopservice_method_in_class_win32_service.asp

> End If
>

End if - for which if?

End If   ' End if test for accept stop.

Play around with the WMI class properties
and methods, you never know what tomorrow
you'll need to do!   :)

Jeff










---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


RE: IBM HTTP - Win 2000 - http alive?

Posted by Koen Vingerhoets <ko...@ubench.com>.
Hi!

Thanks for the tips!!

I modified the script a little lol... went 4x in size :)

A few things I didn't understand but (like all the values and return values
and such from WMI) it performs what it needs to do now.  Here it is again...
feel free to use it (not recommended: I now have 2 days newbie experience
with VB) or to give comments.  Very big thanks to Jeff White for sending the
usefull links :)

*********************************************************************
Option Explicit
On Error Resume Next
'catch errors

Dim
objWMIService,colListOfServices,objService,objEmail,Stopper,MailM,URLC,HTTPS
tat,Passer,MailS,SiteStat,i
URLC= "http://localhost/index.html"
Stopper		= 0
HTTPStat 	= 0
SiteStat	= 0
i 		= 0
Passer		= 0

Const strComputer 	= "."
Const Sleeper 		= 10000
Const Waiter 		= 20000
Const Trials		= 6

Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\"
& strComputer & "\root\cimv2")
Set colListOfServices = objWMIService.ExecQuery ("Select * from
Win32_Service Where Name = 'IBMHTTPServer'")
'grab the data from the service

For each objService in colListOfServices

If (objService.State <> "Running") Then

	MailS = "**** UBench02 HTTP error report. ****"

	objService.StartService()

	Stopper = Stopper+1

	Wscript.Sleep Sleeper

	Do While Stopper < Trials

    		Do While Passer = 0

    			Set col2ListOfServices = objWMIService.ExecQuery ("Select * from
Win32_Service Where Name = 'IBMHTTPServer'")

			For each obj2Service in col2ListOfServices

			If (obj2Service.State = "Running") Then

				MailM = "The HTTP Server crashed!! However, I noticed that on " &Now& "
and restarted it after " &Stopper& " trials!"
				MailSender MailS,MailM
				Stopper = Trials
				HTTPStat = 1
				Passer = 1

			Else

				If Stopper = Trials-1 Then

					MailM = "I tried " &Stopper& " times but I can't restart the HTTP
Service, I suggest you take a look. I tried until " &Now& ". I give up."
					MailSender MailS,MailM

				Else
					obj2Service.StopService()
					Wscript.Sleep Waiter
					obj2Service.StartService()

				End If

				Stopper = Stopper+1

			End If

			Wscript.Sleep Sleeper

			Next
		Loop
	Loop
Else

	HTTPStat = 1

End If

If HTTPStat = 1 Then

	Set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")
	xmlhttp.open "GET", URLC, false
	xmlhttp.send ""

	If InStr(xmlhttp.responseText,"Error") > 0 Then

		MailS = "**** UBench02 error: can't reach site. ****"
      		MailM = "The HTTP service runs but I can't access the site! I'll
stop the service  at " &Now& ", restart in 15 minutes!"
      		MailSender MailS,MailM
      		objService.StopService()

	Else 	If xmlhttp.status <> 200 Then

			MailS = "**** UBench02 error: can't reach site. ****"
      			MailM = "The HTTP service runs but I can't access the site! I'll
stop the service  at " &Now& ", restart in 15 minutes!"
      			MailSender MailS,MailM
      			objService.StopService()
      		Else

     			SiteStat = 1

         	End If
         End If
End If

If HTTPStat = 1 Then

	If SiteStat = 1 Then

		i=2
		MailS = "UBench02 OK."
		MailM = "Server checked: " &Now& "."
		MailSender MailS,MailM

	End If
End If

Next

Sub MailSender(MailS,MailM)

	Dim MailA(2)
	MailA(2) = "koen.vingerhoets@ubench.com"
	MailA(1) = "serge.verborgh@ubench.com"
	MailA(0) = "marc.lens@ubench.com"

	Do While i < 3
		Set objEmail = CreateObject("CDO.Message")
		objEmail.From = "info@ubench.com"
		objEmail.To = MailA(i)
		objEmail.Subject = MailS
		objEmail.Textbody = MailM
		objEmail.Configuration.Fields.Item
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
		objEmail.Configuration.Fields.Item
("http://schemas.microsoft.com/cdo/configuration/smtpserver") =
"mail-out.pandora.be"
		objEmail.Configuration.Fields.Item
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
		objEmail.Configuration.Fields.Update
		objEmail.Send
		Set objEmail = nothing
		i=i+1
	Loop

	i=0

End Sub

***************************************************************************

Thanks for the help,

Koen


-----Original Message-----
From: Jeff White [mailto:jlwpc1@earthlink.net]
Sent: 24 July 2002 03:24
To: users@httpd.apache.org
Subject: Re: IBM HTTP - Win 2000 - http alive?




> Hi!
>
> Thanks for all the help!
> After some reading in the WSH links today
>

Here are some more ideas.

Is IBMHTTPServer the "name" _you_ started the service with?

Then check the WMI docs for the values and return values for all the
service properties and methods that you are using.

Scripting in WMI
http://msdn.microsoft.com/library/en-us/wmisdk/wmi/scripting_in_wmi.as
p

WMI Scripting: The Missing Manual, Part 1
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dncli
nic/html/scripting06112002.asp

For Windows 2000 and Windows XP
Windows Management Instrumentation Tutorial
http://www.microsoft.com/downloads/release.asp?releaseid=12570

Win32_Service
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisd
k/wmi/win32_service.asp

http://groups.google.com/groups?q=service+start+WMI+group:*scripting

Check Clarence's web site for examples.
http://cwashington.netreach.net

This script controls a NT service, attempts to restart the service if
it is found not running and logs these events. If the service restart
fails, a message is mailed through CDONTS.NewMail.

http://cwashington.netreach.net/depo/view.asp?Index=602&ScriptType=vbs
cript

>    Set objEmail = CreateObject("CDO.Message")

You seem to know how do mail now, lucky you didn't send a ton of mail!
:)

Also just because a HTTP service "started" does not mean the web
server is working correctly.  :)

Best way to test a web server is by "getting" something.

Windows Scripts for getting a web page or web header.

In a VBScript or JScript scripts, for client scripts testing a web
server - change all

set xmlhttp = server.CreateObject("Microsoft.XMLHTTP")

to

set xmlhttp = CreateObject("Microsoft.XMLHTTP")

Without the word server before CreateObject.  If you want to run this
stuff in Apache via the server talking to another server, not a client
talking to a server, search for WinHttp instead of XMLHTTP.

So for all the below reading, try dropping the word server before
CreateObject for your "test" the web server scripts.

http://groups.google.com/groups?q=xmlhttp+check+server+group:*scriptin
g


http://groups.google.com/groups?q=xmlhttp+status+response+group:*scrip
ting

Also replace all response.write with wscript.echo

response.write AllThisStoredText

to

wscript.echo  AllThisStoredText

Hope this gives you some more ideas.
Jeff








---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org





---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: IBM HTTP - Win 2000 - http alive?

Posted by Jeff White <jl...@earthlink.net>.

> Hi!
>
> Thanks for all the help!
> After some reading in the WSH links today
>

Here are some more ideas.

Is IBMHTTPServer the "name" _you_ started the service with?

Then check the WMI docs for the values and return values for all the
service properties and methods that you are using.

Scripting in WMI
http://msdn.microsoft.com/library/en-us/wmisdk/wmi/scripting_in_wmi.as
p

WMI Scripting: The Missing Manual, Part 1
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dncli
nic/html/scripting06112002.asp

For Windows 2000 and Windows XP
Windows Management Instrumentation Tutorial
http://www.microsoft.com/downloads/release.asp?releaseid=12570

Win32_Service
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisd
k/wmi/win32_service.asp

http://groups.google.com/groups?q=service+start+WMI+group:*scripting

Check Clarence's web site for examples.
http://cwashington.netreach.net

This script controls a NT service, attempts to restart the service if
it is found not running and logs these events. If the service restart
fails, a message is mailed through CDONTS.NewMail.

http://cwashington.netreach.net/depo/view.asp?Index=602&ScriptType=vbs
cript

>    Set objEmail = CreateObject("CDO.Message")

You seem to know how do mail now, lucky you didn't send a ton of mail!
:)

Also just because a HTTP service "started" does not mean the web
server is working correctly.  :)

Best way to test a web server is by "getting" something.

Windows Scripts for getting a web page or web header.

In a VBScript or JScript scripts, for client scripts testing a web
server - change all

set xmlhttp = server.CreateObject("Microsoft.XMLHTTP")

to

set xmlhttp = CreateObject("Microsoft.XMLHTTP")

Without the word server before CreateObject.  If you want to run this
stuff in Apache via the server talking to another server, not a client
talking to a server, search for WinHttp instead of XMLHTTP.

So for all the below reading, try dropping the word server before
CreateObject for your "test" the web server scripts.

http://groups.google.com/groups?q=xmlhttp+check+server+group:*scriptin
g


http://groups.google.com/groups?q=xmlhttp+status+response+group:*scrip
ting

Also replace all response.write with wscript.echo

response.write AllThisStoredText

to

wscript.echo  AllThisStoredText

Hope this gives you some more ideas.
Jeff








---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


RE: IBM HTTP - Win 2000 - http alive?

Posted by Koen Vingerhoets <ko...@ubench.com>.
Hi!

Thanks for all the help!
After some reading in the WSH links today I made this:

strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\"
& strComputer & "\root\cimv2")
Set colListOfServices = objWMIService.ExecQuery ("Select * from
Win32_Service Where Name = 'IBMHTTPServer'")
For Each objService in colListOfServices

	If (objService.State <> "Started") Then

    	objService.StartService()

   	 Set objEmail = CreateObject("CDO.Message")
         objEmail.From = "info@ubench.com"
         objEmail.To = "koen.vingerhoets@ubench.com"
         objEmail.Subject = "UBench02 error report"
         objEmail.Textbody = "Crap!! The HTTP Server crashed!! However, I
noticed that and most likely restarted it."
       objEmail.Configuration.Fields.Item
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
	 objEmail.Configuration.Fields.Item
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "my.smtp.be"
	 objEmail.Configuration.Fields.Item
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
	 objEmail.Configuration.Fields.Update
	 objEmail.Send
	 Set objEmail = nothing
	End If
Next


I tried to loop to make sure that it worked but all it did was sending 250
mail messages :s
If there are stupidities in it, let me know.  I have no VB knowledge :(

Met vriendelijke groet,

Koen Vingerhoets




-----Original Message-----
From: Jeff White [mailto:jlwpc1@earthlink.net]
Sent: 22 July 2002 23:13
To: users@httpd.apache.org
Subject: Re: IBM HTTP - Win 2000 - http alive?



> I was wondering how I could check
> whether the HTTP server is still running
> under Windows 2000.

Use built-in Windows Script

Windows Script
http://msdn.microsoft.com/scripting


Introduction to Windows Scripting
http://www.winguides.com/article.php?id=2

Scripting 101
A 4 part series on how to create and structure WSH scripts by Bob
Wells
http://www.winnetmag.com/Articles/Index.cfm?ArticleID=5410
http://www.winnetmag.com/Articles/Index.cfm?ArticleID=5505
http://www.winnetmag.com/Articles/Index.cfm?ArticleID=5683
http://www.winnetmag.com/Articles/Index.cfm?ArticleID=7112

VBScript Primer
http://www.microsoft.com/technet/prodtechnol/windows2000serv/maintain/
optimize/script/netvbscr.asp

System Administration Scripting Guide
http://www.microsoft.com/downloads/release.asp?ReleaseID=38942&area=se
arch&ordinal=2


Services
http://www.microsoft.com/technet/scriptcenter/services/default.asp

TechNet Script Center
http://www.microsoft.com/technet/scriptcenter/default.asp


Jeff






---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org





---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: IBM HTTP - Win 2000 - http alive?

Posted by Jeff White <jl...@earthlink.net>.
> I was wondering how I could check
> whether the HTTP server is still running
> under Windows 2000.

Use built-in Windows Script

Windows Script
http://msdn.microsoft.com/scripting


Introduction to Windows Scripting
http://www.winguides.com/article.php?id=2

Scripting 101
A 4 part series on how to create and structure WSH scripts by Bob
Wells
http://www.winnetmag.com/Articles/Index.cfm?ArticleID=5410
http://www.winnetmag.com/Articles/Index.cfm?ArticleID=5505
http://www.winnetmag.com/Articles/Index.cfm?ArticleID=5683
http://www.winnetmag.com/Articles/Index.cfm?ArticleID=7112

VBScript Primer
http://www.microsoft.com/technet/prodtechnol/windows2000serv/maintain/
optimize/script/netvbscr.asp

System Administration Scripting Guide
http://www.microsoft.com/downloads/release.asp?ReleaseID=38942&area=se
arch&ordinal=2


Services
http://www.microsoft.com/technet/scriptcenter/services/default.asp

TechNet Script Center
http://www.microsoft.com/technet/scriptcenter/default.asp


Jeff






---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org