Copyright | (c) Romain Gérard 2014 David Fisher 2013 |
---|---|
License | BSD3 |
Maintainer | romain.gerard@erebe.eu |
Stability | stable |
Portability | Require Systemd or will fail otherwise |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
System.Systemd.Daemon
Description
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
- http://0pointer.de/blog/projects/socket-activation.html
- http://www.freedesktop.org/software/systemd/man/systemd.socket.html
- http://www.freedesktop.org/software/systemd/man/systemd.service.html
Example:
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
Synopsis
- notify :: Bool -> String -> IO (Maybe ())
- notifyWithFD :: Bool -> String -> Socket -> IO (Maybe ())
- storeFd :: Socket -> IO (Maybe ())
- storeFdWithName :: Socket -> String -> IO (Maybe ())
- notifyWatchdog :: IO (Maybe ())
- notifyReady :: IO (Maybe ())
- notifyPID :: CPid -> IO (Maybe ())
- notifyErrno :: Errno -> IO (Maybe ())
- notifyStatus :: String -> IO (Maybe ())
- notifyBusError :: String -> IO (Maybe ())
- notifyReloading :: IO (Maybe ())
- notifyStopping :: IO (Maybe ())
- getActivatedSockets :: IO (Maybe [Socket])
- getActivatedSocketsWithNames :: IO (Maybe [(Socket, String)])
- unsetEnvironnement :: IO ()
Notify functions
notifyWithFD :: Bool -> String -> Socket -> IO (Maybe ()) Source #
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)
storeFd :: Socket -> IO (Maybe ()) Source #
Notify systemd to store a socket for us.
To be used along getActivatedSockets
during a restart
Usefull for zero downtime restart
storeFdWithName :: Socket -> String -> IO (Maybe ()) Source #
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
notifyWatchdog :: IO (Maybe ()) Source #
Notify the watchdog that the program is still alive
notifyReady :: IO (Maybe ()) Source #
Notify the systemd that the program is ready
notifyPID :: CPid -> IO (Maybe ()) Source #
Notify systemd of the PID of the program (for after a fork)
notifyStatus :: String -> IO (Maybe ()) Source #
Notify systemd of the status of the program.
An arbitrary String
can be passed
notifyBusError :: String -> IO (Maybe ()) Source #
Notify systemd of a DBUS error like.
Correct formatting of the String
is left to the caller
notifyReloading :: IO (Maybe ()) Source #
Notify systemd that the service is reloading its configuration
notifyStopping :: IO (Maybe ()) Source #
Notify systemd that the service is beginning its shutdown
Socket activation functions
getActivatedSockets :: IO (Maybe [Socket]) Source #
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).
getActivatedSocketsWithNames :: IO (Maybe [(Socket, String)]) Source #
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")
Utils
unsetEnvironnement :: IO () Source #
Unset all environnement variable related to Systemd.
Calls to functions like notify
and
getActivatedSockets
will return
Nothing
after that.