Local Library Apache Web Server for windows
|Reported by:||ak19||Owned by:||ak19|
There was already the server.exe local library server on Windows. But to bring the Windows version of GS2 to the same state as the Linux/Mac versions, there is now an Apache web server included in the GS2 Windows.
To compile, use makegs2.bat and choose compilation option 4. This essentially runs: nmake /f win32.mak APACHE_HTTPD=1 (see also the makegs2.bat note further below)
The Apache web server is compiled up into the apache-httpd folder, just on Linux.
The server can be run in two ways:
- The server can be run manually, by first running "gsicontrol.bat <command>" where command includes such options like web-start, web-stop and web-restart. Other commands include configure-admin which allows the user to change the administration password, configure-cgi which generates the custom gsdlsite.cfg file from gsdlsite.cfg.in, and configure-web which allows one to change the port and other settings.
NOTE: The configure-admin command uses the now-precompiled getpw.exe executable in the bin\windows folder. It has been pre-compiled since adding compilation lines for it in the makefiles causes errors when Greenstone2 is compiled with Visual Studio Express (as is required when compiling with the DEBUG=1 flag on).
- The server can be run through the Greenstone Server Interface (GSI), which can be launched by running gs2-server.bat. This bat file is the new Windows version of the gs2-server.sh. The GSI dialog will pop up and the user can press Enter Library to start up the local Apache web server.
Files that were changed or newly added:
- Httpd-2.2.11 apache web server source code that has been customised for Greenstone is contained in the tar.gz file located at:
It is the same source code as for the *Linux* version, but with the Windows make files--from apache's windows source code release--added into it. This means that now the same source release tar file can be compiled up on Windows and Linux.
- windows-httpd.conf.in (new) is the apache httpd template configuration file we use on Windows machines. It could not be merged with the Linux template httpd configuration file (httpd.conf.in) since the two require different modules.
- makegs2.bat - This has been changed to compile up the local Apache web server. If compiling GS2 manually (whether with Apache web server or not), will now FIRST need to run SetEnv.cmd from the Microsoft Platform SDK and THEN run vcvars.bat. That's because in Visual Studio 8 and later, there is no windows.h file anymore, which is to be found in the MS Platform SDK instead. This order of setting the development environment is now the same as when using Visual Studio Express to compile Greenstone 2 with the debugging flag on (DEBUG=1).
- Dr Bainbridge had already prepared the two makefiles (in the runtime-src folder and in runtime-src\packages\apache-httpd) to compile up Windows apache web server code. These makefiles could just be reused on the version of the apache server source code in runtime-src\packages\apache-httpd\httpd-2.2.11-gs.tar.gz
- gsicontrol.bat (new)
- gs2-server.bat (new)
- LocalLibraryServer.java (of GLI)
- Server2.java of Greenstone 3's core code (in the org.greenstone.server package)
- Three c++ files compiled up into starthttpd.exe, starthttpdchild.exe, stophttpd.exe (in bin\windows). The source code lives in runtime-src\src\w32apachectl
This code simulates the operation of the Linux apachectl binary. This is necessary because in general, on Windows, unless the Apache web server is installed as a windows service, starting and stopping the apache server requires a Ctrl-C command to be sent to the DOS console running the server. But we cannot ensure administration rights on every machine where GS2 will be installed, so we have to run the apache server (httpd) as a normal executable and hence have to stop it by sending it a Ctrl-C signal. The matter is complicated by the fact that there are two instances of httpd.exe launched each time the apache web server is run. Manually terminating one instance always replicates itself (re-spawning another httpd); while manually terminating the other instance of httpd.exe will terminate both instances. Therefore the solution is to simulate the termination behaviour when Ctrl-C is sent to the DOS console running the apache web server. This is done by sending the termination signal (Ctrl-C) via the stophttpd.exe C++ program to the Apache web server running in its own cmd console (launched via a START command).
It works as follows:
- The threaded starthttpd.exe launches the starthttpdchild.exe (which starts the apache server) and also monitors for a named Windows event. (The name of this Windows event is to be provided as a parameter to starthttpd.exe). starthttpd.exe is on the lookout for and will respond to the Windows event.
- When the server needs to be stopped, the stophttpd.exe program is called and given the same named signal (named Windows event) as parameter. It emits the Windows Event and exits.
- This signal/event is intercepted by the listening starthttpd.exe program which then sends the Ctrl-C event to starthttpd.exe process which had launched the apache server application. This ends both starthttpdchild.exe and the apache web server. After which the starthttpd.exe also exits.
The way to invoke the starthttpd.exe and stophttpd.exe can be seen in top-level gsicontrol.bat which invokes both to start and stop the apache web server, respectively.