简体   繁体   中英

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 . I'm attempting to run it via a service within windows on boot-up (and ideally keep it up). 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.

I don't think this is an issue w/ GHC . I'm under the assumption that GHC compiles to native code and not 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.

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:

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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