簡體   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