writers
Sample daemons to be used in scripts in examples/ folder
Classes:
-
SampleDaemon1–Sample daemon 1
-
SampleDaemon2–Sample daemon 2
SampleDaemon1
SampleDaemon1(name: str = '', pidfile: Pidfile | None = None, working_directory: str = '/', umask: int = 0, dlogger: Logger | None = None, stop_daemon_signal: int = SIGTERM, *args, **kwargs)
Bases: UNIXDaemon
Sample daemon 1
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
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–Function run
-
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
Function run
Override of the UNIXDaemon.run function
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
SampleDaemon2
SampleDaemon2(name: str = '', pidfile: Pidfile | None = None, working_directory: str = '/', umask: int = 0, dlogger: Logger | None = None, stop_daemon_signal: int = SIGTERM, *args, **kwargs)
Bases: UNIXDaemon
Sample daemon 2
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
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–Function run
-
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
Function run
Override of the UNIXDaemon.run function
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