David Douglas - 2003-06-12

I posted the following under the GUI forum by mistake. Since then I have found a workaround, see script further down page.

I'd like to use openload to check my GIS websites are running and able to generate maps (if they're not I have a script to restart the processes). I use openload -t first with a URL that generates a map, and then openload -t again on the cache directory (IIS been set to allow directory browsing). I can then count the characters and see if any cache files have been generated in that directory.
I'm currently testing it on our intranet development server, so:
openload -t http://webhotel3/ie_flis/showmap.aspx_Min=-219411&y_Min=193302&x_Max=217194&y_Max=196067
and then
openload -t http://webhotel3/Gwmcache
The problem is, if IIS has been stopped, openload keeps running, using 100% of CPU (on Windows 2000 and NT4) until I hit return. The same applies to calls with a specified maximum number of seconds - if IIS isn't running, openload doesn't terminate. if on the other hand, the DNS can't find the host, an error is promptly returned.
I'm running openload on different PCs than the web server.
As I'm planning on using this from a Perl script called every half-hour, this process hanging is a problem.
Any chance of a bug fix in the near future?
best wishes,
David Douglas,
Denmark

# Testwebmap.pl  v. 1.0
# Author: David Douglas, Naturgas Midt-Nord, Viborg, Denmark
# dsd@midtnord.dk
# 11 June 2003
#
# Tested on Windows 2000 Server SP3 with ActivePerl 5.8.0, also on NT 4.0 SP6 (with kill instead of tskill)
#
# Testwebmap.pl uses openload.exe ( http://openload.sourceforge.net ) to test Intergraph's GeoMedia WebMap.
# Want to test website, not only to see if IIS is running, but also that WebMap server processes are running
# correctly on the target server. It first generates a few map queries, generating maps at specified coordinates,
# then lists contents of server cache to see if CGM files have been generated there.
# If WebMap or IIS has failed, but there are still files remaining in cache, no error will be detected, but on the
# next run of this script, these files should have been deleted from the cache, and the script will then report the error.
#
# Openload 0.1.2-Win32 hangs, and consumes 100% CPU time if DNS finds URL, but webserver is not running. This script
# therefore calls openload in child processes and kills them if they go on too long.
# (Requires Resource Kit + Terminal Services)
#
# I call this script every 30 minutes; if the web server is not running correctly, it creates a file on the target server
# and a script running there restarts the web server processes (IIS and WebMap). It logs the error, and sends an email
# to the administrator - uses mailto.exe, which you can find on the Net. mailto.exe requires a SMTP host running on your
# test host server.
# Bat script calling this is:
#
#:start
#perl d:\Inetscripts\Testwebmap.pl
#sleep 1800
#goto start
#
# You probably shouldn't run Testwebmap.pl on your target server, as it will affect performance there
# (if the target is your development server, it doesn't matter so much).
# Choose, if you can, as a host for running this test another machine on the same network as the target
# server, one which is always running, and from which you can write files to the target server.
# If you're not on the same network (eg. there's a firewall between you, you could in theory use FTP
# to write the file, but if your web server's not running, then FTP may not be either.

local( $returned, $targetserver, $targetdir, $testhost, $bytes, $minimumbytes, $killer);

{
local( *IGNORE, *READTEST, $pid, $seconds, $openload );

$returned = 0;
$bytes = 0; # number bytes actually received from cache directory

$minimumbytes = 680; # check this - development and production servers may differ. Less than this means failure.
                       # 680 on production server, 420 on development server
$killer = "kill";  # check availability of kill or tskill command on your system
$SIG{'ALRM'} = 'my_alarm_handler';

$targetserver = "http://130.228.237.195"; # "http://130.228.237.195" for production server, "http://webhotel3"
                                            # for development server
$targetdir =  "\\\\ngmnweb1";  # "\\\\ngmnweb1" for production server, "\\\\webhotel3" for development server
$testhost = "\\\\ngmnweb"; # "\\\\ngmnweb" for production server "\\\\webhotel3" for development server (it tests itself)
$openload = "D:\\Inetscripts\\openload";   # assuming production and development servers have same drives, directories.
$seconds = 35;  # max time to wait before killing child process

alarm($seconds);  # if first openload hasn't returned in $seconds seconds, kill it, report error and don't do 2nd test
unless ( fork() )
  {
   exec( "$openload -l 1 $targetserver/ie_flis/showmap.asp?x_Min=-219411&y_Min=193302&x_Max=-217194&y_Max=196067 1");
   # child process performs a one-second test of site with one simulated user, generates a few map files in server cache
}

  wait;
  alarm($seconds);  # if second openload hasn't returned in $seconds seconds, kill it, report error
  $returned = 1; # first openload returned ok

# now create child process that lists contents of server cache (IIS must allow browsing of directory )
# parent reads output from child
     if (not defined($pid = open(READTEST, "-|","$openload -t -l 1 $targetserver/gwmcache"))) # returns html, 1 query only
     {
      &reporterror( "can't fork");
       }
    $pid || exit 0;   # child exits

 

    while ( <READTEST> )
   {

     alarm(0);  # now that we're reading, assume will not hang now, so cancel countdown
     $bytes += length( $_);   # num chars in html doc - listing of files in cache

   }

print "$bytes bytes received from cache directory\n";

if ( $bytes < $minimumbytes )    # less than this means directory is empty; in the first openload we should have generated
            # several, ergo map generation is not working
  {
    &reporterror("Cache empty - WebMap not running, $bytes bytes");
  }
else
  { print "\nTEST SUCCEEDED\n"; }

 
}

sub reporterror
{
local( $actions, $restartfile, $logfile, *OUT,$sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst);

$restartfile = "$targetdir\\Inetpub\\restart.now";
$logfile = "D:\\Inetpub\\restart.log";
$actions = "";
if ( ! open( OUT, ">$restartfile" ) ) { $actions = "Can't write $restartfile -i.e can't request restart"; } # a script running on $targetserver checks every 2 minutes for this file. If
                       # present, it deletes it and restarts IIS and WebMap processes.

   
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);
if ( ! ((open( OUT, ">>$logfile" ) && printf OUT "Restart - $actions %4d-%02d-%02d %02d:%02d:%02d\n",$year+1900,$mon+1,$mday,$hour,$min,$sec)
     ))
  {  $actions += "Can't log to $logfile"; }
if ( $actions eq "" ) {$actions = "Requested restart"; }

# can't have newlines in arguments here.

print "$actions\n";
exec("cmd /c D:\\Inetscripts\\mailto.exe -M \&quot;WebMap on $targetserver not running, tested by $testhost $_[0] $actions\&quot; -U dsd\@midtnord.dk -H inet.uni2.dk -D dsd\@midtnord.dk -S \&quot;$targetserver WebMap failed\&quot;");
  # this requires SMTP running on $testhost
}

sub my_alarm_handler
{

# tskill on Windows 2000 requires installing Resource Kit and Terminal Services windows component, and that
# Terminal Services service is running

!system("$killer openload ") || &reporterror("$killer failed");
if ( $returned != 1 )
  {
    &reporterror("Openload didn't run");
  }
elsif ( $bytes < $minimumbytes )
  {
    &reporterror("Timeout, cache empty - WebMap not running, $bytes bytes");
  }
exit 0;
}