2014-03-30 241 views
2

我编写了一个程序Windows Server 2008使用GHC 7.6.332-bit。我试图在启动时通过Windows内的服务运行它(并理想地保持它)。要使用下面的命令这样做,我创建了一个服务成功运行GHC创建的Windows可执行文件作为服务

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

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

当我双击它时,可执行文件运行良好。所以不知道为什么Windows不允许该服务运行。我不认为这是一个问题w/GHC。我假设GHC编译为本地代码而不是MSIL

那么,为什么我不能运行我的可执行文件作为服务的任何想法?

enter image description here

+0

第一行支持问题,你知道一个Windows服务与应用程序不一样吗? – Jonke

+0

您需要调用ServiceService中的StartServiceCtrlDispatcher,RegisterServiceCtrlHandler,SetServiceStatus(至少)和SERVICE_TABLE_ENTRY – Jonke

+0

我没有试过(因为在我需要时它不存在),但是http://hackage.haskell.org/包/ Win32的服务 – Jonke

回答

4

正如评论所说,你需要真正实现你的程序的行为作为Windows服务的Win32服务API,你可以使用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使用它的一个真实的例子。

相关问题