Mini Servers: Start Stop design notes
This Page Is Currently Under Construction And Will Be Available Shortly, Please Visit Reserve Copy Page
<span id="top"></span> <div style="padding:0;margin:0; border-bottom:3px inset #000000">
Mini Servers Start and Stop batch file design notes
Mini Server design notes.
Mini-Server Design notes
One of the most difficult things to appreciate is design philosophy behind working code the mini-server start and stop files are no exception. To address this I have produced a flow diagram for each file these were transcribe from my original scribbles and include side comments along with potential risks.
Design goal was to produce two batch files capable of starting and stopping Apache and MySQL servers. The architecture would support multi-instances of both applications and be totally portable across XP and Vista platforms.
Architecture problem areas
The two batch files are separate entities a user can choose to run them in any order or as many times as they like. This would produce at best some interesting error message worst case locking up the PC. Added to this it is not guaranteed the batch files will be run during the same PC session. A user may forget to run stop.bat and just switch the PC off this has the same effect as a power failure. A consequence of this it may prevent the servers starting or a wrong process being terminated. In addition ports may be occupied preventing the servers starting.
The architecture must be robust and address the above.
Implementation problem areas
A flow diagram should not contain implementation detail however to keep important information together I tend to add these during and after coding.
Real problems occur when coding in particular what instruction are cross operating system compliant. Finding this information can be difficult if not impossible the following are examples:
Query process “qprocess” works OK across XP range however fails only on Vista Home Premium, which renders it useless for a real design.
The above is resolvable using pslist from Sysinternals (Microsoft) apart from the extra baggage a user must now agree to a ULA and promptly rewarded with an entry in the registry. Ace program but rendered none portable by adding dross to the registry.
Solution is to use netstat -anp tcp
Port detection is easy, local addresses are unique for example 0.0.0.0:445 hence easy port detection.
A PID on its own for example “1108” is not unique this number can occur anywhere however this PID is unique “ 1108” ignore the quotes it’s the space at the beginning that is of importance.
Required information port and PID are easily accessible. It is possible to use batch file “tokens” this really is overkill hence use a pipe with find, makes the code a little easier to read for example: <pre> rem ## It exists is it running SET /P pid=<udrive\usr\local\apache2\logs\httpd.pid netstat -anop tcp | FIND /I " %pid%" >NUL IF ERRORLEVEL 1 goto :NOTRUNNING IF ERRORLEVEL 0 goto :RUNNING </pre> Top
Similarly killing a process by PID use “taskkill /PID” fine for Vista and XP! Well unless its XP-home, alternative is to use pskill from SysInternals. Again ace program but rendered none portable by adding dross to the registry.
Uniform Server has a perfectly adequate “pskill” utility however you must use a process name it will not kill a process using its PID. US pskill is small 44K while SysInternals is large 182K.
When running multi-servers you must rename Apache’s executable to something unique and change the associated batch files accordingly.
To obtain a delay I have previously used ping however this can fail if the IP address is in use. An alternative is to use “choice” and set user time out delay, fine apart from it was removed from XP strange when its been reintroduced in Vista. Solution created a small delay utility you can find the source code unidelay.c in the docs’ folder of each mini-server. Compiled using lcc_win32.
Interestingly I have not covered potential risks. After the mini-servers were released I was looking at the architecture with the intention of implementing this on Uniform Server. Although minor for mini-servers the notes were added because this would become a major issue on a full server.
Setting a nonexistent drive would produce an error message annoying and inconvenient but not a serious problem.
Likewise the infinite loop if a server fails to start gives you a chance to make a coffee again annoying and inconvenient but not a serious issue.
The above is not true for a full server because a user needs informing of the problem. Preferably with real information e.g. failed to find a free drive, unable to start MySQL because Apache failed to start.
An example of a safety loop can be found on this page Apanel not displayed.
The above is intended to explain side notes added to the flow diagrams. Interestingly the flow diagrams have not changed from the originals however implementation (coding) has changed significantly due to cross OS incompatibilities.
The above is not intended to be a complete design guide, more to provide useful snippets of information.
Of real importance are OS incompatibilities, which limit the choice of batch file commands you can use.
Never assume a design is cross OS compliant always test.