ufairiya / mongoose

Automatically exported from code.google.com/p/mongoose
MIT License
0 stars 0 forks source link

Eliminate separate Mongoose as Windows service #60

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I suggest that the current special "Service Install" version of Mongoose be
eliminated. Instead, add the -service command line option.

Then user code can call the Windows Service Manager to create and start
Mongoose as a server, either in compiled source code, or by an explicit
windows command file, as follows:

InstallMongooseAsService.cmd:

sc create Mongoose binPath= "C:\Progra~1\Mongoose\Mongoose.exe -service"
    start= auto displayname= "Mongoose Web Server Service"
sc description Mongoose "Runs the Mongoose Web server on port 80."
sc start Mongoose
REM During testing:
pause

UninstallMongooseAsService.cmd:

sc stop Mongoose
sc delete Mongoose
REM During testing:
pause

Note: I've tested this with Apache, and it appears to work perfectly.

David Spector

Original issue reported on code.google.com by googl...@springtimesoftware.com on 22 Jun 2009 at 9:15

GoogleCodeExporter commented 9 years ago
Are you suggesting getting rid of the installer?

Please note that there is no special Mongoose executable exists that is 
specific to
Windows Service. If you take a look at windows installer script, it does almost
exactly what you have suggested:
http://code.google.com/p/mongoose/source/browse/trunk/win32/installer.nsi

An installer could be useful for some people because it has:
 1. SSL libraries
 2. Config file
 3. Service setup

Original comment by valenok on 22 Jun 2009 at 10:10

GoogleCodeExporter commented 9 years ago
I agree that the Windows installer is a good thing.

My only question is: what is srvany.exe? It seems to be different from 
mongoose.exe
-service. Whhy have a separate executable?

Original comment by googl...@springtimesoftware.com on 22 Jun 2009 at 10:31

GoogleCodeExporter commented 9 years ago
srvany is a microsoft tool that allows to create a windows service out from any
executable. I threw out all service-specific code from Mongoose and use srvany.

Original comment by valenok on 22 Jun 2009 at 10:34

GoogleCodeExporter commented 9 years ago
The reason I used the SC command above is that it is available on all Windows
systems. The Srvany command is not. So perhaps SC would be a simpler route.

Here is my CMD file for installing the Apache service:

sc create Apache2 binPath= "C:\Progra~1\Apache\bin\httpd.exe -k runservice -D 
Local"
start= auto displayname= "Apache Web Server Service"
sc description Apache2 "Runs an Apache Local Web Server on port 80."
sc start Apache2
pause

Here is my CMD file for removing the Apache service:

sc stop Apache2
sc delete Apache2
pause

Note: the "pause" is just there for debugging. Also, you can start the CMD file 
with
"@echo no" to hide the commands from the output. You can also start a CMD file
invisibly (with no console).

The current released version of Mongoose does not seem to run as a service when
installed this way.

Original comment by googl...@springtimesoftware.com on 23 Jun 2009 at 8:04

GoogleCodeExporter commented 9 years ago
To use SC command, an executable must conform to the Windows Service 
requirements
(have certain functions implemented).
If srvany is used, then *any* executable can be made into a service.

I have removed Windows Service specific code from Mongoose and using srvany 
instead.
The reason is to have as less platform-specific code in the source as possible.

Original comment by valenok on 23 Jun 2009 at 8:16

GoogleCodeExporter commented 9 years ago
Ah, I had forgotten that. Yes, that makes sense.

Is 2.7 ready to replace 2.6 as the standard download, or is it waiting for the 
error
handling feature? (I don't think 2.6 works as a service, and it starts very 
slowly
when run standalone.)

You can close this "defect", which is really just messaging with you.

Thanks for all your great work on this amazing little server!

Original comment by googl...@springtimesoftware.com on 23 Jun 2009 at 10:01

GoogleCodeExporter commented 9 years ago
I plan to investigate, reproduce and fix a crash-causing bug reported in the 
mailing
list, and then release 2.7.

Thanks!

Original comment by valenok on 24 Jun 2009 at 7:29

GoogleCodeExporter commented 9 years ago
It would be good to add CMD files to create, start, stop, and remove the 
Mongoose
Service on Windows. It is not obvious how to use srvany, and it is awkward to
reinstall Mongoose or uninstall it to create or remove the Service.

It would also be good to add this information to the manual.

The more that is explicitly documented, the better engineers will like this 
tool once
they discover it.

Thank you for doing a such a great job on release 2.7, especially with its fast 
speed
and tiny size on Windows!

Original comment by googl...@springtimesoftware.com on 7 Jul 2009 at 11:05

GoogleCodeExporter commented 9 years ago
Right, I'll add the info to the manual.
With srvany, one has to modify the registry entries, I am not sure if this is
possible to script.

Original comment by valenok on 8 Jul 2009 at 9:24

GoogleCodeExporter commented 9 years ago
Yes, it is easy. You just have to be willing to use two files instead of one.

Simple file to create Mongoose service:

sc create Mongoose binpath= "D:\\Program Files\\Mongoose\\srvany.exe" start= 
auto
depend= Tcpip
REM may need to wait here for several seconds, not sure
sc description Mongoose "Web server"
regedit.exe /s a653.reg
sc start Mongoose
pause

Helper file a653.reg:

REGEDIT4

[HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Mongoose\Parameters]
"Application"="D:\\Program Files\\DevPal\\mongoose.exe"
"AppDirectory"="D:\\Program Files\\DevPal"

Cmd file to restart Mongoose to read conf file:

sc stop DevPal
wait.exe 5
sc start DevPal
REM pause

Cmd file to remove Mongoose service:

sc stop Mongoose
sc delete Mongoose
pause

Original comment by googl...@springtimesoftware.com on 8 Jul 2009 at 9:44

GoogleCodeExporter commented 9 years ago
I'm not sure if wait.exe is needed. If so, it's just a tiny program. Let me 
know if
you need source code for Windows in C.

Original comment by googl...@springtimesoftware.com on 8 Jul 2009 at 9:50