[AWS] AWS as a service on a Win2000 server

David Marceau davidmarceau@sympatico.ca
Mon, 19 Jan 2004 08:54:37 -0500


anders.wirzenius@wartsila.com wrote:
> It runs without any problems when started by a local user on the server.
> I want to have it started automatically as a service.
> 
> I succeeded to register it as a service in Windows, but when I try to
> start the service, I got error messages.
> When starting using Computer Management:
> "Error 1053: The service did not respond to the start or control request
> in a timely fashion."
> When starting from a DOS prompt:
> "The service is not responding to the control function."

The weird thing about nt services is that if you create a dll with too much
housekeeping at the load time, the dll will not return immediately and as a
result your dll will give the appearance that it failed to load and you end up
with an hour glass Icon.

nt service success trick #1
----------------------------
Don't do any initialization at load time.  Have some timer actually
initialize your application after 5 seconds.  That will give windows the chance
to behave properly and return success for DLL_INIT...  In fact the ideal is that
you just return success in the DLL_INIT part right away. There should be about
three lines. 
1)load dll but don't do any init. 
2)set a timer with a callback that in 5 seconds it will init and start aws 
3)return success.

NT service success trick #2
----------------------------
> I have tried both with
> AWS.Server.Wait (AWS.Server.Q_Key_Pressed);
Don't use the Q_Key_Pressed.

AWS.Server.Wait (AWS.Server.Forever);
This is the right approach.


NT service success trick #3
---------------------------
In linux, to ensure the runme continues to run even after you logout, you have
to do the following at the bash shell:
nohup runme &
The "nohup" means don't hangup this process even if I logout, and yes usually
you want to run a daemon/ntservice in the background process.  At the nt command
shell you can run "start /b runme" to launch it as background.  As to the nt
"nohup" equivalent, it stops the service as soon as you logout if I remember
correctly.

This brings me to 
-INSTSRV
-SRVANY 
These may already exist on your machine but maybe they are found in the NT
Resource Kit.
If you follow the suggestions int trick #1 and #2 above, you should be
successful in a day or two.

There are couple of articles about how to run a vb/c/C++ application as an nt
service on www.msdn.com.
msdn search for the keywords "ntservice vb C++ application" and you will find
what you need.

Cheers.