ganeti
Safe HaskellNone

Ganeti.Daemon

Description

Implementation of the generic daemon functionality.

Synopsis

Constants

devNull :: FilePath Source #

/dev/null path.

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.

Constructors

DaemonOptions 

Fields

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

oPort :: Int -> 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.

defaultBindAddr Source #

Arguments

:: Int

The port we want

-> Result Family

The cluster IP family

-> IO (Result (Family, SockAddr)) 

Computes the default bind address for a given family.

parseAddress Source #

Arguments

:: 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.

getFQDN' :: Maybe AddrInfo -> IO String Source #

Get the real full qualified host name.

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.

getFQDN :: IO String Source #

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

isMaster :: IO Bool Source #

Returns if the current node is the master node.

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).

genericMain Source #

Arguments

:: 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 Source #

Arguments

:: 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.

innerMain Source #

Arguments

:: 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.