On 2009 Jan 22, at 1:36, Belka wrote:
Could somebody please share some experience on how to implement daemon start
and stop directives. In theory I need something like this:
1. "my_daemon start" - starts my app with an infinite loop of serving
inside.
2. "my_daemon stop" - puts in some TVar a value signalizing, that stop is
given - infinite loop brakes.
3. ...it on Linux platform.

Thanks in advance!

If you want a normal daemon, you want to look at System.Posix.Process to create a proper daemon (forkProcess, createSession; don't forget to close stdOutput (and, errr, Haskell library types: stdin and stderr are where? not System.Posix.IO with stdOutput) and reopen them on / dev/null, at least if they're ttys as determined by System.Posix.Terminal.queryTerminal). You also want to write out a pidfile (/var/run/programname.pid) for use by startproc / killproc, and you want to install a handler for sigTERM (System.Posix.Signals.installHandler) which sets the exit flag (TVar, MVar, IORef, Chan, take your pick). Ideally you also catch sigHUP and reload your state.

--
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allb...@kf8nh.com
system administrator [openafs,heimdal,too many hats] allb...@ece.cmu.edu
electrical and computer engineering, carnegie mellon university    KF8NH


_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to