Running a Cygwin compiled app as an NT service
Moderator: Supporters
Running a Cygwin compiled app as an NT service
How do you do it?
What I'm trying to do is create a Win32 installer for IRC Services. Now, I'd like to put in the option to run IRC Services as an NT service (sort of like the Win32 installer for UnrealIRCd 3.2.1). Obviously, I need to know how to run Services as a service (pardon the pun) - if I know that, I'm pretty sure that I can figure out what to do with the installer.
What I'm trying to do is create a Win32 installer for IRC Services. Now, I'd like to put in the option to run IRC Services as an NT service (sort of like the Win32 installer for UnrealIRCd 3.2.1). Obviously, I need to know how to run Services as a service (pardon the pun) - if I know that, I'm pretty sure that I can figure out what to do with the installer.
Re: Running a Cygwin compiled app as an NT service
I think the full Cygwin installation has a tool to install it as a service, and even do things like SIGTERM on SCM Stop or Shutdown notifications. I think it's cygrunsrv.exe but I can't be 100% sure on this :/ .Ron2K wrote:How do you do it?
What I'm trying to do is create a Win32 installer for IRC Services. Now, I'd like to put in the option to run IRC Services as an NT service (sort of like the Win32 installer for UnrealIRCd 3.2.1). Obviously, I need to know how to run Services as a service (pardon the pun) - if I know that, I'm pretty sure that I can figure out what to do with the installer.
-
- Former UnrealIRCd head coder
- Posts: 811
- Joined: Sat Mar 06, 2004 8:47 pm
- Location: United States
- Contact:
You would need to use something like firedaemon. To make something run as a service, you have to add quite a bit of code to the exe to make it support running as a service. It has to register itself, it has to start itself, it has to return status control query results, etc. If you want an example, look at src/win32/service.c. You can't simply run any app as a service, it must be designed to run as a service.
-- codemastr
ok. I uploaded firedeamon for you if you dont have it yet.
DOWNLOAD HERE (http://vegetasan.zidev.com/firedaemon.zip)
I only know how to install a service with a batch file.
you want to install.. UnrealIRCD as a service and you install UnrealIRC in "C:\Unreal3.2" and firedeamon is also in that same directory and service name is "IRCD" . then...
DOWNLOAD HERE (http://vegetasan.zidev.com/firedaemon.zip)
I only know how to install a service with a batch file.
for example:with batch file .... wrote:@echo off
c:\yourdir\firedaemon.exe -i Servicename "c:\yourappdirectory\linux" "c:\yourappdirectory\linux\app.extention" "" Y 0 0 0 Y
net start Servicename
you want to install.. UnrealIRCD as a service and you install UnrealIRC in "C:\Unreal3.2" and firedeamon is also in that same directory and service name is "IRCD" . then...
With batch file .. example UnrealIRCD wrote:@echo off
c:\Unreal3.2\firedaemon.exe -i IRCD "c:\UnrealIRCD" "c:\UnrealIRCD\wircd.exe" "" Y 0 0 0 Y
net start IRCD
Hm... well another option (you might still need to support NT Service stuff):
WinXP (dunno about other OSs) has a commandline application to control services called sc.exe.
To create a service:
sc create <service name> binPath=<binary path> start=auto DisplayName=<displayname>
Of course, you could just invoke the WinAPI calls in the installer :/ .
As a suggestion, if this ever becomes reality, put an option to make the IRCservices NT Service dependant on another service, such as the Unreal IRCd NT Service. This ensures that the IRCd will be started and ready before the services are started, and that the services are stopped before the IRCd is stopped (at least it does so when you go through the Services Control Panel, dunno about invoking SCM directly).
WinXP (dunno about other OSs) has a commandline application to control services called sc.exe.
To create a service:
sc create <service name> binPath=<binary path> start=auto DisplayName=<displayname>
Of course, you could just invoke the WinAPI calls in the installer :/ .
As a suggestion, if this ever becomes reality, put an option to make the IRCservices NT Service dependant on another service, such as the Unreal IRCd NT Service. This ensures that the IRCd will be started and ready before the services are started, and that the services are stopped before the IRCd is stopped (at least it does so when you go through the Services Control Panel, dunno about invoking SCM directly).
-
- Former UnrealIRCd head coder
- Posts: 811
- Joined: Sat Mar 06, 2004 8:47 pm
- Location: United States
- Contact:
Once again, it still requires it to be a service! How can the SCM control something that doesn't tell it how to control it? A service exe knows to stop because it receives the STOP query from the SCM. At this point it sends back the STOPPING reply. After completing its cleanup, it then returns STOPPED. Now the SCM stops the process. A ServiceCtrlHandler function is required to deal with such processing.
An NT service isn't even run like a normal exe. A console app has a main() function, a Windows GUI app has WinMain(), and a service has ServiceMain(). When you try to tell sc to run the service, it won't find ServiceMain and it will fail.
Other than using a go between such as firedaemon, there is NO way to make a normal exe run as a service. And even when using firedaemon, it still isn't truly a service since it has no direct contact with the SCM. The SCM can not inform it of user requests (pauses, stops, etc.) and the exe can not respond to any queries.
An NT service isn't even run like a normal exe. A console app has a main() function, a Windows GUI app has WinMain(), and a service has ServiceMain(). When you try to tell sc to run the service, it won't find ServiceMain and it will fail.
Other than using a go between such as firedaemon, there is NO way to make a normal exe run as a service. And even when using firedaemon, it still isn't truly a service since it has no direct contact with the SCM. The SCM can not inform it of user requests (pauses, stops, etc.) and the exe can not respond to any queries.
-- codemastr
Question: How can Unreal run either as a service or a GUI app?
-ChatSpike IRC Network [http://www.chatspike.net]
-Denora Stats [http://denora.nomadirc.net]
-Omerta [http://www.barafranca.com]
-Denora Stats [http://denora.nomadirc.net]
-Omerta [http://www.barafranca.com]
Configuration - https://www.unrealircd.org/docs/Configuration
FAQ - https://www.unrealircd.org/docs/FAQ
FAQ - https://www.unrealircd.org/docs/FAQ