Hello all,
I've created a license server program that runs in both Linux and Windows. I need it to run as a deamon/service. In Linux, that means an additional 8 lines of code, but in Windows, as you know, it's a bit more difficult. My program runs fine from the command line in Windows, but I need a bit of help getting it running as a service.
I've done a bit of research and can install/remove the service, but getting it running as a service is proving to be a bit more difficult. If I open up the service manager, I see my service listed, but if I try to start it (by opening the properties for my service and clicking "start") I get:
Error 1053: The service did not respond to the start or control request in a timely fashion.
I suppose this is because I haven't written any code that tells the SCM how to start/stop it. Is there a *simple* way of doing this? Keep in mind I already have a main(), and, if at all possible would like to keep everything the way it is so it's easy to switch between windows and Linux (in other words, I don't mind adding to main, but I'd like to not completly remove it and replace it with a DWORD WINAPI main). FYI: my main:
Code:
int main(int argc, char *argv[])
{
while ((c = getopt(argc, argv, "c:l: p:vhirs")) != EOF){
switch (c) {
// bunch of switch stuff for command line arguments
}
}
if (ioption) { // windows install
InstallService(license_file, log_file);
return 0;
}
#ifndef WIN32
init_daemon(); // set this up as a daemon
#endif
oldMain(port, license_file, log_file, verbose); // the actual stuff
return (0);
}
so "oldMain" is what would actually be called by something that wants to start this service (if you need to specify a function). Also, The way this thing is designed is that it just sits there and "non-blockingly" waits - forever. It doesn't need to be restarted every so often (which is something that stumped me about some of the examples I came across online).
I can post my install/remove srevice code if it helps, but it seems those are pretty standard.