unix
UNIX daemon implementation
Classes:
-
UNIXDaemon–UNIX daemon
UNIXDaemon
UNIXDaemon(name: str = '', pidfile: Pidfile | None = None, working_directory: str = '/', umask: int = 0, dlogger: Logger | None = None, stop_daemon_signal: int = SIGTERM, *args, **kwargs)
Bases: Daemon
UNIX daemon
Base class to define a valid daemon logic to be run on UNIX distributions
To define a UNIX daemon, you must override UNIXDaemon.run(...) abstract method
Daemon constructor function
Parameters:
-
(namestr, default:'') –Daemon name
-
(pidfilePidfile | None, default:None) –PID file
-
(working_directorystr, default:'/') –Working directory for daemon
-
(umaskint, default:0) –umask
-
(dloggerLogger | None, default:None) –Daemon logger
-
(argsTuple[Any, ...], default:()) –Positional arguments
-
(kwargsDict[str, Any], default:{}) –Keyword arguments
-
Documentation
Daemonizer
Samples
writers
-
Documentation
Daemonizer
Core
Handlers
base_handlerhandler
Methods:
-
args–Function to access positional arguments (defined at daemon definition)
-
get_arguments–Function to get arguments
-
kwargs–Function to access keyword arguments (defined at daemon definition)
-
restart–Function to restart the daemon (it stops then starts the process)
-
run–Method to run the daemon.
-
set_lock–Function to set lock for PID file writes
-
start–Function to start the daemon
-
status–Function to get status of the current daemon
-
stop–Function to stop the daemon.
args
Function to access positional arguments (defined at daemon definition)
from daemon's body
Returns:
-
Tuple[Any, ...]–Positional arguments
get_arguments
Function to get arguments
This method can be called in the custom daemon logic
Returns:
-
Dict[str, Tuple[Any, ...] | Dict[str, Any]]–Dict of both positional and keyword arguments
kwargs
Function to access keyword arguments (defined at daemon definition)
from daemon's body
Returns:
-
Dict[str, Any]–Keyword arguments
restart
restart() -> None
Function to restart the daemon (it stops then starts the process)
Once restarted, daemon has a new PID (new process)
Returns:
-
None–Nothing
run
run() -> None
Method to run the daemon.
This method must be overridden by the child class.
Returns:
-
None–Nothing
set_lock
set_lock(lock: Lock | None) -> None
Function to set lock for PID file writes
Parameters:
-
(lockLock | None) –Multiprocessing lock to protect PID file on-disk writes
Returns:
-
None–Nothing
start
start() -> None
Function to start the daemon
Returns:
-
None–Nothing
status
status()
Function to get status of the current daemon
Returns:
-
None–Nothing
stop
stop() -> None
Function to stop the daemon.
- If the PID file is on the disk (same name as current daemon), we read the PID in the file
- If process (identified by PID) is still active, we kill it with specified signal (self.stop_daemon_signal)
- If process is not active anymore (it may have been terminated by natural cause (core logic) or external
signal sent by the user), we are removing PID file (not needed anymore)
- If the PID file is not on the disk, we cannot stop the daemon.
This is why it is important to avoid manipulating PID files as their management is handled automatically by the
library.
Returns:
-
None–Nothing