|
|
Tech Note: Automatic SLIP or PPP and HTTP restart under Windows NT
I run a web server under Windows NT over a SLIP connection and my phone line
occasionally drops during the day. I have worked out a way to get my server to restart
unattended. This was harder than I thought! I ran across several stumbling blocks:
- The Remote Access service will redial automatically but, if you are using SLIP, won't login
without waiting for me to press a Done button. Answer: use the RASDIAL command line
program.
- The RASDIAL program doesn't redial when the line drops. Answer: write a batch
file which checks the connection every so often and redials if it is down.
- Couldn't find a way to check the connection from a batch file, e.g. Ping
hangs up if RAS is up but the connection is down. Answer: write a simple program
called RASUP which does this.
- Even if the connection is re-established, the EMWACS HTTPS
server doesn't start responding again. This causes a problem even if you are
using the auto-redial feature of PPP under RAS. Answer: use the net command to
stop and restart the service.
Here's how it works. I leave this batch file running in a command
prompt window. Every 60 seconds it checks to see if my RAS connection
is active. If there is no connection, it redials and then restarts
the HTTP server.
NETCHECK.BAT
:top
rasup
if errorlevel 1 goto done
rasdial TIAC
net stop "Http server"
sleep 5
net start "Http server"
:done
sleep 60
goto top
Notes:
- TIAC is the name of my login script.
- I found the sleep program with the posix utilities in the
NT 3.5 resource kit (available from Microsoft's FTP site).
- I had to insert a short pause between stopping and starting the HTTP service
Here's the source to the rasup program I wrote. I'm a rusty coder,
don't be harsh! The RAS.H include file comes with the Win32 SDK from Microsoft.
/* rasup.c
Command line utility to see if any Remote Access Service
connections are active.
Exit status=1 if any are active, otherwise 0.
*/
#include <windows.h>
#include <stdio.h>
#include <ras.h>
VOID main()
{
RASCONN rasconnbuf;
DWORD cb = sizeof(RASCONN);
DWORD ret;
DWORD numConn;
/*
Required to provide buffer size
*/
rasconnbuf.dwSize = sizeof(rasconnbuf);
/*
Retrieve info about first active connection (I only have one - change this if you have more)
*/
ret = RasEnumConnections(&rasconnbuf,&cb, &numConn);
if ((numConn == 0) | ret) {
printf("No connection, status 0");
exit(0);
}
else {
printf("Active connection, status 1");
exit(1);
}
}
If you want this program, here it is, as-is with no guarantees. I have only used this on NT 3.5 and NT 3.51 for Intel. If you improve it (ideas: remove the batch file and implement the whole thing as a service) or if you have a simpler way to keep an NT HTTPS server up and running, please email me!
P.S. A thank-you to Robert Reconnu, webmaster@postapage.com, for
giving me the net command syntax (I previously used the SC utility from MS VC++), and for verifying that this technique works with a PPP.
Reed Sturtevant <reed@sturtevant.com>
Last update: December 28, 1995
Sturtevant Technotes
|