[英]Running a GHC created windows executable as a service
I have compiled a program on Windows Server 2008
using GHC 7.6.3
32-bit
. 我已使用GHC 7.6.3
32-bit
在Windows Server 2008
上编译了一个程序。 I'm attempting to run it via a service within windows on boot-up (and ideally keep it up). 我试图在启动时通过Windows内的服务运行它(最好保持运行状态)。 To do so I have created a service with the following command successfully 为此,我已成功使用以下命令创建了服务
sc create stworker binPath= "C:\\Users\\vagrant\\Desktop\\worker.exe"
The problem I'm having is that when I attempt to start the service I receive the following error (see image below). 我遇到的问题是,当我尝试启动服务时收到以下错误(请参见下图)。
The executable runs fine when I double click it. 双击该可执行文件即可正常运行。 So not sure why Windows wouldn't allow the service to be run. 所以不确定为什么Windows不允许运行该服务。
I don't think this is an issue w/ GHC
. 我不认为这与GHC
。 I'm under the assumption that GHC
compiles to native code and not MSIL
. 我假设GHC
编译为本地代码,而不是MSIL
。
So any ideas why I can't run my executable as a service? 那么,为什么不能将可执行文件作为服务运行?
As mentioned in the comments, you need to actually implement the Win32 service API for your program to behave as a Windows service, and you can do this using the Win32-services
package. 如注释中所述,您需要为程序真正实现Win32服务API,使其表现为Windows服务,并且可以使用Win32-services
包来实现。
There's also a wrapper package Win32-services-wrapper
that I wrote that aims to provide some of the boilerplate and handle logging, so that defining a service looks like this: 我还写了一个包装程序包Win32-services-wrapper
,该程序包旨在提供一些样板文件并处理日志记录,以便定义服务如下所示:
main =
defineService $
Service {
serviceName = "Service",
-- Start the service given a debug handle to write to.
-- Make sure not to use stdout or stderr as they don't exist.
-- Any state needed by serviceStop can be returned here -
-- the Service type takes the type of the state as a type parameter
serviceStart = \debugHandle -> ...,
-- Stop the service given the service state returned by serviceStart
serviceStop = \serviceState -> ...
}
There's a real example of using it in darcsden
. 在darcsden
有一个使用它的真实示例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.