Safe HaskellSafe-Infered




Implementation of the generic daemon functionality.



devNull :: FilePathSource

daemonStartupErr :: String -> StringSource

Data types

data DaemonOptions Source

Command line options structure.




optShowHelp :: Bool

Just show the help

optShowVer :: Bool

Just show the program version

optShowComp :: Bool

Just show the completion info

optDaemonize :: Bool

Whether to daemonize or not

optPort :: Maybe Word16

Override for the network port

optDebug :: Bool

Enable debug messages

optNoUserChecks :: Bool

Ignore user checks

optBindAddress :: Maybe String

Override for the bind address

optSyslogUsage :: Maybe SyslogUsage

Override for Syslog usage

defaultOptions :: DaemonOptionsSource

Default values for the command line options.

type OptType = GenericOptType DaemonOptionsSource

Abrreviation for the option type.

type CheckFn a = DaemonOptions -> IO (Either ExitCode a)Source

Check function type.

type PrepFn a b = DaemonOptions -> a -> IO bSource

Prepare function type.

type MainFn a b = DaemonOptions -> a -> b -> IO ()Source

Main execution function type.

Command line options

ioErrorToResult :: String -> IOError -> IO (Result a)Source

parseArgs :: String -> [OptType] -> IO (DaemonOptions, [String])Source

Small wrapper over getArgs and parseOpts.

Daemon-related functions

pidFileMode :: FileModeSource

pidFileFlags :: OpenFileFlagsSource

writePidFile :: FilePath -> IO FdSource

cleanupSocket :: FilePath -> IO ()Source

Helper function to ensure a socket doesn't exist. Should only be called once we have locked the pid file successfully.

setupDaemonEnv :: FilePath -> FileMode -> IO ()Source

finalCleanup :: FilePath -> IO ()Source

handleSigTerm :: ThreadId -> IO ()Source

handleSigHup :: FilePath -> IO ()Source

setupDaemonFDs :: Maybe FilePath -> IO ()Source

defaultBindAddr :: Int -> Family -> Result (Family, SockAddr)Source



:: DaemonOptions

Command line options

-> Int

Default port for this daemon

-> IO (Result (Family, SockAddr)) 

Based on the options, compute the socket address to use for the daemon.

getFQDN' :: Maybe AddrInfo -> IO StringSource

getFQDNwithHints :: Maybe AddrInfo -> IO StringSource

getFQDN :: IO StringSource

Return the full qualified host name, honoring the vcluster setup.

isMaster :: IO BoolSource

describeError :: String -> Maybe Handle -> Maybe FilePath -> IO a -> IO aSource

Run an I/O action that might throw an I/O error, under a handler that will simply annotate and re-throw the exception.

daemonize :: FilePath -> (Maybe Fd -> IO ()) -> IO ()Source



:: GanetiDaemon

The daemon we're running

-> [OptType]

The available options

-> CheckFn a

Check function

-> PrepFn a b

Prepare function

-> MainFn a b

Execution function

-> IO () 

Generic daemon startup.

fullPrep :: GanetiDaemon -> DaemonOptions -> SyslogUsage -> a -> PrepFn a b -> IO (FilePath, b)Source

innerMain :: GanetiDaemon -> DaemonOptions -> SyslogUsage -> a -> PrepFn a b -> MainFn a b -> Maybe Fd -> IO ()Source

handlePrepErr :: Bool -> Maybe Fd -> IOError -> IO aSource

maybeCloseFd :: Maybe Fd -> IO ()Source