繁体   English   中英

运行GHC创建的Windows可执行文件即服务

[英]Running a GHC created windows executable as a service

我已使用GHC 7.6.3 32-bitWindows Server 2008上编译了一个程序。 我试图在启动时通过Windows内的服务运行它(最好保持运行状态)。 为此,我已成功使用以下命令创建了服务

sc create stworker binPath= "C:\\Users\\vagrant\\Desktop\\worker.exe"

我遇到的问题是,当我尝试启动服务时收到以下错误(请参见下图)。

双击该可执行文件即可正常运行。 所以不确定为什么Windows不允许运行该服务。

我不认为这与GHC 我假设GHC编译为本地代码,而不是MSIL

那么,为什么不能将可执行文件作为服务运行?

在此处输入图片说明

如注释中所述,您需要为程序真正实现Win32服务API,使其表现为Windows服务,并且可以使用Win32-services包来实现。

我还写了一个包装程序包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 -> ...
        }

darcsden有一个使用它的真实示例。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM