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, patroni_logger: PatroniLogger)View on GitHub
Bases:
ABCA Patroni daemon process.
Note
When inheriting from
AbstractPatroniDaemonyou 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, patroni_logger: PatroniLogger) NoneView on GitHub
Set up signal handlers, logging handler and configuration.
- Parameters:
config – configuration options for this daemon.
patroni_logger – the logging handler for this daemon.
- _abc_impl = <_abc._abc_data object>
- abstractmethod _run_cycle() NoneView 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.
- abstractmethod _shutdown() NoneView on GitHub
Define what the daemon should do when shutting down.
- api_sigterm() boolView on GitHub
Guarantee only a single SIGTERM is being processed.
Flag the daemon as “SIGTERM received” with a lock-based approach.
- Returns:
Trueif the daemon was flagged as “SIGTERM received”.
- property received_sigterm: boolView on GitHub
If daemon was signaled with SIGTERM.
- reload_config(sighup: bool = False, local: bool | None = False) NoneView 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
Trueif there are changes in the local configuration file.
- run() NoneView 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() NoneView on GitHub
Set up daemon signal handlers.
Set up SIGHUP and SIGTERM signal handlers.
Note
SIGHUP is only handled in non-Windows environments.
- shutdown() NoneView on GitHub
Shut the daemon down when a SIGTERM is received.
Shut down the daemon process and the logger thread.
- sighup_handler(*_: Any) NoneView on GitHub
Handle SIGHUP signals.
Flag the daemon as “SIGHUP received”.
- sigterm_handler(*_: Any) NoneView on GitHub
Handle SIGTERM signals.
Terminate the daemon process through
api_sigterm().
- patroni.daemon.abstract_main(cls: Type[AbstractPatroniDaemon], configfile: str) NoneView 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() ArgumentParserView on GitHub
Create a basic argument parser with the arguments used for both patroni and raft controller daemon.
- Returns:
‘argparse.ArgumentParser’ object