-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Systemd facilities (Socket activation, Notify) -- -- A module for Systemd facilities. @package systemd @version 2.3.0 -- | This module implements all functions from System.Systemd.Daemon -- that require or return Sockets purely using Fds. This is -- especially useful if you have to do low level IO using file -- descriptors or use a different socket library than network. -- -- The API is exactly the same as System.Systemd.Daemon except -- that Sockets have been replaced by Fds (actually -- System.Systemd.Daemon uses this module internally). This also -- means that System.Systemd.Daemon.Fd and -- System.Systemd.Daemon expose conflicting functions. You either -- have to import System.Systemd.Daemon.Fd qualified or -- like so: -- --
-- import System.Systemd.Daemon hiding ( notifyWithFD, storeFd -- , storeFdWithName -- , getActivatedSockets -- , getActivatedSocketsWithNames ) -- import System.Systemd.Daemon.Fd ---- -- The functions in System.Systemd.Daemon that are not implemented -- in this module are 100% compatible with -- System.Systemd.Daemon.Fd. module System.Systemd.Daemon.Fd -- | Same as notify, but send along a Fd. Note that the -- caller must set the message, i. e. send FDSTORE=1 to actually -- store the file descriptor. In most cases it is probably best to use -- storeFd or the notify-functions from -- System.Systemd.Daemon. -- -- Equivalent to standard notifyWithFD. notifyWithFD :: Bool -> String -> Fd -> IO (Maybe ()) -- | Notify Systemd to store a file descriptor for us. This together with -- getActivatedSockets allows for zero downtime restarts and -- socket activation. -- -- Equivalent to standard storeFd storeFd :: Fd -> IO (Maybe ()) -- | Like storeFd, but associate the file descriptor with a name. -- Best used along with getActivatedSocketsWithNames. -- -- Equivalent to standard storeFdWithName storeFdWithName :: Fd -> String -> IO (Maybe ()) -- | Return Just a list of file descriptors if the current process -- has been activated with one or more socket by systemd, Nothing -- otherwise. -- -- The file descriptors are in the same order as the sockets in the -- associated .socket file. The sockets will have their family, -- type, and status set according to the .socket file. -- -- Equivalent to standard getActivatedSockets getActivatedSockets :: IO (Maybe [Fd]) -- | Like getActivatedSockets, but also return the associated names. -- If a file descriptor has no associated name, it will be a generic one -- set by systemd. -- -- Equivalent to standard getActivatedSocketsWithNames getActivatedSocketsWithNames :: IO (Maybe [(Fd, String)]) -- | Implementation of Systemd facilities to create and manage daemons. -- -- All socket-related actions in this module, work with the -- Network.Socket module from network. If you want to use -- a different socket library or work directly with file descriptors, see -- System.Systemd.Daemon.Fd. -- -- This module contains socket activation and notify tools. See -- --
-- import Control.Monad(forever) -- import System.Systemd.Daemon(notifyWatchdog) -- -- main :: IO () -- main = forever $ do -- functionThatMayHang -- notifyWatchdog ---- -- If you use the service described as below, Systemd will restart your -- program each time the watchdog fail to notify itself under 60 sec. -- --
-- [Unit] -- Description=MyDaemon -- -- [Service] -- Type=simple -- TimeoutStartSec=0 -- ExecStart=AbsolutePathToMyExecutable -- WatchdogSec=60 -- Restart=on-failure -- -- [Install] -- WantedBy=multi-user.target --module System.Systemd.Daemon -- | Notify systemd about an event -- -- After notifying systemd the Bool parameter specify if the -- environnement shall be unset (Further call to notify will fail) -- -- The String is the event to pass -- -- Returns Nothing if the program was not started with systemd or -- that the environnement was previously unset notify :: Bool -> String -> IO (Maybe ()) -- | Same as notify but send along a socket to be stored -- -- It is up to the caller to properly set the message (i.e: do not forget -- to set FDSTORE=1) notifyWithFD :: Bool -> String -> Socket -> IO (Maybe ()) -- | Notify systemd to store a socket for us. -- -- To be used along getActivatedSockets during a restart -- -- Usefull for zero downtime restart storeFd :: Socket -> IO (Maybe ()) -- | Notify systemd to store a socket for us and specify a name. -- -- To be used along getActivatedSocketsWithNames during a restart -- -- Usefull for zero downtime restart storeFdWithName :: Socket -> String -> IO (Maybe ()) -- | Notify the watchdog that the program is still alive notifyWatchdog :: IO (Maybe ()) -- | Notify the systemd that the program is ready notifyReady :: IO (Maybe ()) -- | Notify systemd of the PID of the program (for after a fork) notifyPID :: CPid -> IO (Maybe ()) -- | Notify systemd of an Errno error notifyErrno :: Errno -> IO (Maybe ()) -- | Notify systemd of the status of the program. -- -- An arbitrary String can be passed notifyStatus :: String -> IO (Maybe ()) -- | Notify systemd of a DBUS error like. -- -- Correct formatting of the String is left to the caller notifyBusError :: String -> IO (Maybe ()) -- | Notify systemd that the service is reloading its configuration notifyReloading :: IO (Maybe ()) -- | Notify systemd that the service is beginning its shutdown notifyStopping :: IO (Maybe ()) -- | Return a list of activated sockets, if the program was started with -- socket activation. -- -- The sockets are in the same order as in the associated -- .socket file. The sockets will have their family, type, and -- status set appropriately. -- -- Returns Nothing in systems without socket activation (or when -- the program was not socket activated). getActivatedSockets :: IO (Maybe [Socket]) -- | Same as getActivatedSockets but return also the names -- associated with those sockets if storeFdWithName was used or -- specified in the .socket file. -- -- IF storeFd was used to transmit the socket to systemd, the name -- will be a generic one (i.e: usally "stored") getActivatedSocketsWithNames :: IO (Maybe [(Socket, String)]) -- | Unset all environnement variable related to Systemd. -- -- Calls to functions like notify and getActivatedSockets -- will return Nothing after that. unsetEnvironnement :: IO ()