-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | utilities for UNIX daemon writing -- -- Provides two functions that help writing better UNIX daemons, -- daemonize and serviced: daemonize does what a daemon should do -- (forking and closing descriptors), while serviced does that and more -- (syslog interface, PID file writing, start-stop-restart command line -- handling, dropping privileges). @package hdaemonize @version 0.2 module System.Posix.Daemonize -- | The simplest possible interface to syslog. type Logger = String -> IO () -- | A program is any IO computation. It also accepts a syslog handle. type Program = Logger -> IO () -- | Daemonizes a given IO computation by forking twice, closing standard -- file descriptors, blocking sigHUP, setting file creation mask, -- starting a new session, and changing the working directory to root. daemonize :: IO () -> IO () -- | Turns a program into a UNIX daemon (system service) ready to be -- deployed to etcrc.d or similar startup folder. The resulting -- program handles command-line arguments (start, stop, or restart). -- -- With start option it writes out a PID to varrun/$name.pid where -- $name is the executable name. If PID already exists, it refuses to -- start, guaranteeing there is only one live instance. -- -- With stop option it reads the PID from varrun/$name.pid and -- terminates the corresponding process (first a soft kill, SIGTERM, then -- a hard kill, SIGKILL). -- -- Another addition over the daemonize function is dropping privileges. -- If a system user and group with a name that matches the executable -- name exist, privileges are dropped to that user and group. Otherwise, -- they are dropped to the standard daemon user and group. -- -- Finally, exceptions in the program are caught, logged to syslog, and -- the program restarted. serviced :: Program -> IO ()