patroni.daemon module¶
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)¶ Bases:
abc.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¶ 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¶ 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.
-
api_sigterm
() → bool¶ 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
¶ If daemon was signaled with SIGTERM.
-
reload_config
(sighup: bool = False, local: Optional[bool] = False) → None¶ 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¶ Run the daemon process.
Start the logger thread and keep running execution cycles until a SIGTERM is eventually received. Also reload configuration uppon receiving SIGHUP.
-
setup_signal_handlers
() → None¶ Set up daemon signal handlers.
Set up SIGHUP and SIGTERM signal handlers.
Note
SIGHUP is only handled in non-Windows environments.
-
shutdown
() → None¶ Shut the daemon down when a SIGTERM is received.
Shut down the daemon process and the logger thread.
-
sigterm_handler
(*_: Any) → None¶ Handle SIGTERM signals.
Terminate the daemon process through
api_sigterm()
.
-
patroni.daemon.
abstract_main
(cls: Type[patroni.daemon.AbstractPatroniDaemon], configfile: str) → None¶ 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
() → argparse.ArgumentParser¶ Create a basic argument parser with the arguments used for both patroni and raft controller daemon.
- Returns
‘argparse.ArgumentParser’ object