Enabling 'Auto-start' on a Windows Host running Apache2.
One of the more nagging requirements of running DekiWiki on a Windows host is the necessity to login and start the "mindtouch.host.bat" process. I've come up with a solution to this problem. One might think that it would be simple just to set that batch file to run at startup, but if you do that, it doesn't wait for apache to be running, which makes things a little difficult. As a result, I've devised a relatively simple solution to the problem.
I've segmented the 'kicker' process into 3 pieces.
The first is a batch file I call "c:\wiki.bat" (I put this in it's own file so the working directory gets set properly by the cd command within it.)
cd C:\deki-hayes\web\bin mindtouch.host.bat
The second is a vbscript that will use WMI to query the status of the Apache2 service, and sleep until it's started, finally kicking off the host process.
This file I've saved as "C:\wikiKicker.vbs":
set oWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
doneYet = false
while not doneYet
if apacheIsStarted then
set oShell = CreateObject("WScript.Shell")
oShell.Run "cmd.exe /k c:\wiki.bat",0, false
doneYet = true
else
Wscript.Sleep 10000
end if
wend
function apacheIsStarted
set oSvcs = oWMI.ExecQuery("SELECT * From Win32_Service where Name = 'Apache2'")
for each oSvc in oSvcs
apacheIsStarted = oSvc.Started
next
end function Finally, I've created a user on the local host called wikiDude, and added him as a local admin. I created a Scheduled Task using the control panel to run the following command at System Startup, with the identity of HOSTNAME\wikiDude:
c:\windows\system32\cscript.exe c:\wikiKicker.vbs
If you reboot the machine, you'll magically see the DekiWiki host process is started in the context of wikiDude. Hooray!
Now, if the service dies, and you need to restart the thing, you can remotely connect to the Scheduled Tasks manager of the host server and just run the scheduled task, and it's almost as good as having it run as a real 'system service.'