gawkinet: PANIC
1
1 3.1 PANIC: An Emergency Web Server
1 ==================================
1
11 At first glance, the '"Hello, world"' example in ⇒A Primitive Web
Service Primitive Service, seems useless. By adding just a few lines,
1 we can turn it into something useful.
1
1 The PANIC program tells everyone who connects that the local site is
1 not working. When a web server breaks down, it makes a difference if
1 customers get a strange "network unreachable" message, or a short
1 message telling them that the server has a problem. In such an
1 emergency, the hard disk and everything on it (including the regular web
1 service) may be unavailable. Rebooting the web server off a diskette
1 makes sense in this setting.
1
1 To use the PANIC program as an emergency web server, all you need are
1 the 'gawk' executable and the program below on a diskette. By default,
1 it connects to port 8080. A different value may be supplied on the
1 command line:
1
1 BEGIN {
1 RS = ORS = "\r\n"
1 if (MyPort == 0) MyPort = 8080
1 HttpService = "/inet/tcp/" MyPort "/0/0"
1 Hello = "<HTML><HEAD><TITLE>Out Of Service</TITLE>" \
1 "</HEAD><BODY><H1>" \
1 "This site is temporarily out of service." \
1 "</H1></BODY></HTML>"
1 Len = length(Hello) + length(ORS)
1 while ("awk" != "complex") {
1 print "HTTP/1.0 200 OK" |& HttpService
1 print "Content-Length: " Len ORS |& HttpService
1 print Hello |& HttpService
1 while ((HttpService |& getline) > 0)
1 continue;
1 close(HttpService)
1 }
1 }
1