Daemon processes abstraction module.
This module implements abstraction classes and functions for creating and managing daemon processes in Patroni.
Currently it is only used for the main "Thread" of
patroni
and
patroni_raft_controller
commands.
- class patroni.daemon. AbstractPatroniDaemon ( config : Config ) View on GitHub
-
Bases:
ABC
A Patroni daemon process.
Note
When inheriting from
AbstractPatroniDaemon
you are expected to define the methods_run_cycle()
to determine what it should do in each execution cycle, and_shutdown()
to determine what it should do when shutting down.- Variables :
-
-
logger – log handler used by this daemon.
-
config – configuration options for this daemon.
-
- __init__ ( config : Config ) None View on GitHub
-
Set up signal handlers, logging handler and configuration.
- Parameters :
-
config – configuration options for this daemon.
- _abc_impl = <_abc._abc_data object>
- abstract _run_cycle ( ) None View on GitHub
-
Define what the daemon should do in each execution cycle.
Keep being called in the daemon’s main loop until the daemon is eventually terminated.
- abstract _shutdown ( ) None View on GitHub
-
Define what the daemon should do when shutting down.
- api_sigterm ( ) bool View on GitHub
-
Guarantee only a single SIGTERM is being processed.
Flag the daemon as "SIGTERM received" with a lock-based approach.
- Returns :
-
True
if the daemon was flagged as "SIGTERM received".
- property received_sigterm : bool View on GitHub
-
If daemon was signaled with SIGTERM.
- reload_config ( sighup : bool = False , local : bool | None = False ) None View on GitHub
-
Reload configuration.
- Parameters :
-
-
sighup – if it is related to a SIGHUP signal. The sighup parameter could be used in the method overridden in a child class.
-
local – will be
True
if there are changes in the local configuration file.
-
- run ( ) None View on GitHub
-
Run the daemon process.
Start the logger thread and keep running execution cycles until a SIGTERM is eventually received. Also reload configuration upon receiving SIGHUP.
- setup_signal_handlers ( ) None View on GitHub
-
Set up daemon signal handlers.
Set up SIGHUP and SIGTERM signal handlers.
Note
SIGHUP is only handled in non-Windows environments.
- shutdown ( ) None View on GitHub
-
Shut the daemon down when a SIGTERM is received.
Shut down the daemon process and the logger thread.
- sighup_handler ( * _ : Any ) None View on GitHub
-
Handle SIGHUP signals.
Flag the daemon as "SIGHUP received".
- sigterm_handler ( * _ : Any ) None View on GitHub
-
Handle SIGTERM signals.
Terminate the daemon process through
api_sigterm()
.
- patroni.daemon. abstract_main ( cls : Type [ AbstractPatroniDaemon ] , configfile : str ) None View on GitHub
-
Create the main entry point of a given daemon process.
- Parameters :
-
-
cls – a class that should inherit from
AbstractPatroniDaemon
. -
configfile
-
- patroni.daemon. get_base_arg_parser ( ) ArgumentParser View on GitHub
-
Create a basic argument parser with the arguments used for both patroni and raft controller daemon.
- Returns :
-
‘argparse.ArgumentParser’ object