Safe Haskell | None |
---|
Implementation of the generic daemon functionality.
Synopsis
- devNull :: FilePath
- daemonStartupErr :: String -> String
- data DaemonOptions = DaemonOptions {
- optShowHelp :: Bool
- optShowVer :: Bool
- optShowComp :: Bool
- optDaemonize :: Bool
- optPort :: Maybe Word16
- optDebug :: Bool
- optNoUserChecks :: Bool
- optBindAddress :: Maybe String
- optSyslogUsage :: Maybe SyslogUsage
- optForceNode :: Bool
- optNoVoting :: Bool
- optYesDoIt :: Bool
- defaultOptions :: DaemonOptions
- type OptType = GenericOptType DaemonOptions
- type CheckFn a = DaemonOptions -> IO (Either ExitCode a)
- type PrepFn a b = DaemonOptions -> a -> IO b
- type MainFn a b = DaemonOptions -> a -> b -> IO ()
- oNoDaemonize :: OptType
- oDebug :: OptType
- oNoUserChecks :: OptType
- oPort :: Int -> OptType
- oBindAddress :: OptType
- oSyslogUsage :: OptType
- oForceNode :: OptType
- oNoVoting :: OptType
- oYesDoIt :: OptType
- genericOpts :: [OptType]
- ioErrorToResult :: String -> IOError -> IO (Result a)
- parseArgs :: String -> [OptType] -> IO (DaemonOptions, [String])
- pidFileMode :: FileMode
- pidFileFlags :: OpenFileFlags
- writePidFile :: FilePath -> IO Fd
- cleanupSocket :: FilePath -> IO ()
- setupDaemonEnv :: FilePath -> FileMode -> IO ()
- finalCleanup :: FilePath -> IO ()
- handleSigTerm :: ThreadId -> IO ()
- handleSigHup :: FilePath -> IO ()
- setupDaemonFDs :: Maybe FilePath -> IO ()
- defaultBindAddr :: Int -> Result Family -> IO (Result (Family, SockAddr))
- parseAddress :: DaemonOptions -> Int -> IO (Result (Family, SockAddr))
- vClusterHostNameEnvVar :: String
- getFQDN' :: Maybe AddrInfo -> IO String
- getFQDNwithHints :: Maybe AddrInfo -> IO String
- getFQDN :: IO String
- isMaster :: IO Bool
- ensureNode :: GanetiDaemon -> DaemonOptions -> IO ()
- describeError :: String -> Maybe Handle -> Maybe FilePath -> IO a -> IO a
- daemonize :: FilePath -> (Maybe Fd -> IO ()) -> IO ()
- genericMain :: GanetiDaemon -> [OptType] -> CheckFn a -> PrepFn a b -> MainFn a b -> IO ()
- fullPrep :: GanetiDaemon -> DaemonOptions -> SyslogUsage -> a -> PrepFn a b -> IO (FilePath, b)
- innerMain :: GanetiDaemon -> DaemonOptions -> SyslogUsage -> a -> PrepFn a b -> MainFn a b -> Maybe Fd -> IO ()
- handlePrepErr :: Bool -> Maybe Fd -> IOError -> IO a
- maybeCloseFd :: Maybe Fd -> IO ()
Constants
daemonStartupErr :: String -> String Source #
Error message prefix, used in two separate paths (when forking and when not).
Data types
data DaemonOptions Source #
Command line options structure.
DaemonOptions | |
|
Instances
StandardOptions DaemonOptions # | |
Defined in Ganeti.Daemon helpRequested :: DaemonOptions -> Bool Source # verRequested :: DaemonOptions -> Bool Source # compRequested :: DaemonOptions -> Bool Source # requestHelp :: DaemonOptions -> DaemonOptions Source # |
defaultOptions :: DaemonOptions Source #
Default values for the command line options.
type OptType = GenericOptType DaemonOptions Source #
Abrreviation for the option type.
type CheckFn a = DaemonOptions -> IO (Either ExitCode a) Source #
Check function type.
type PrepFn a b = DaemonOptions -> a -> IO b Source #
Prepare function type.
type MainFn a b = DaemonOptions -> a -> b -> IO () Source #
Main execution function type.
Command line options
oForceNode :: OptType Source #
genericOpts :: [OptType] Source #
Generic options.
ioErrorToResult :: String -> IOError -> IO (Result a) Source #
Annotates and transforms IOErrors into a Result type. This can be
used in the error handler argument to catch
, for example.
parseArgs :: String -> [OptType] -> IO (DaemonOptions, [String]) Source #
Small wrapper over getArgs and parseOpts
.
Daemon-related functions
pidFileMode :: FileMode Source #
PID file mode.
pidFileFlags :: OpenFileFlags Source #
PID file open flags.
writePidFile :: FilePath -> IO Fd Source #
Writes a PID file and locks it.
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 #
Sets up a daemon's environment.
finalCleanup :: FilePath -> IO () Source #
Cleanup function, performing all the operations that need to be done prior to shutting down a daemon.
handleSigTerm :: ThreadId -> IO () Source #
Signal handler for the termination signal.
handleSigHup :: FilePath -> IO () Source #
Signal handler for reopening log files.
setupDaemonFDs :: Maybe FilePath -> IO () Source #
Sets up a daemon's standard file descriptors.
Computes the default bind address for a given family.
:: 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.
vClusterHostNameEnvVar :: String Source #
Environment variable to override the assumed host name of the current node.
getFQDNwithHints :: Maybe AddrInfo -> IO String Source #
Return the full qualified host name, honoring the vcluster setup and hints on the preferred socket type or protocol.
ensureNode :: GanetiDaemon -> DaemonOptions -> IO () Source #
Ensures that the daemon runs on the right node (and exits gracefully if it doesnt)
describeError :: String -> Maybe Handle -> Maybe FilePath -> IO a -> IO a Source #
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 #
Run an I/O action as a daemon.
WARNING: this only works in single-threaded mode (either using the single-threaded runtime, or using the multi-threaded one but with only one OS thread, i.e. -N1).
:: 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.
:: GanetiDaemon | The daemon we're running |
-> DaemonOptions | The options structure, filled from the cmdline |
-> SyslogUsage | Syslog mode |
-> a | Check results |
-> PrepFn a b | Prepare function |
-> IO (FilePath, b) |
Full prepare function.
This is executed after daemonization, and sets up both the log files (a generic functionality) and the custom prepare function of the daemon.
:: GanetiDaemon | The daemon we're running |
-> DaemonOptions | The options structure, filled from the cmdline |
-> SyslogUsage | Syslog mode |
-> a | Check results |
-> PrepFn a b | Prepare function |
-> MainFn a b | Execution function |
-> Maybe Fd | Error reporting function |
-> IO () |
Inner daemon function.
This is executed after daemonization.
handlePrepErr :: Bool -> Maybe Fd -> IOError -> IO a Source #
Daemon prepare error handling function.
maybeCloseFd :: Maybe Fd -> IO () Source #
Close a file descriptor.