Frage

I've been working on a pixel server built using Haskell Warp and have been struggling to work out how to run it in daemonized mode.

Warp works great - I can use run from Network.Wai.Handler.Warp to serve HTTP, runTLS from Network.Wai.Handler.WarpTLS to serve HTTPS, and I can run both by spawning a new thread:

startBoth :: Config -> IO ()
startBoth config = do
  _ <- forkIO $ startHTTPS config
  startHTTP config

My problem is figuring out how to use detachDaemon from MissingH (System.Daemon) to get my server detached and running in the background on Ubuntu.

In my Main.hs I've tried adding a detachDaemon action like so:

main :: IO ()
main =
  detachDaemon >> cmdArgs options >>= getConfig . optionsConfig >>= start

but the program then just silently exits without error, and without anything showing up when I run ps -ef | grep snowhuskyd.

How should I be using detachDaemon - is it even possible with Warp? I can't find a single example of using detachDaemon on the Web - any help would be gratefully received!

War es hilfreich?

Lösung

I've done some more digging and found this thread, where a Yesod user (Yesod is the web framework built on top of Warp) asks how to daemonize Yesod using hdaemonize (another daemonization lib), and the Yesod/Warp head honcho Michael Snoyman says:

As an aside, I disagree with the notion that daemonizing is the right way to run a process, and think that Upstart (or daemontools, or angel, or...) is the correct approach. But I know others have different opinions on this.

In other words: I don't think it's something we can fix, and in this particular case, I don't think it's worth fixing.

Angel from the Bump team looks particularly nice, and it's written in Haskell, so perhaps I should go with that, rather than trying to shoehorn daemonization into my own app.

I'll leave this question open though for now in case people have other ideas!

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top