Skip to content

Commit 7ef3cd4

Browse files
rdunklauCyberDem0n
authored andcommitted
Add support for notify-reload systemd unit type (patroni#3450)
This allows systemd-reload command to wait for the configuration to actually have been processed. Encapsulate the import logic in a separate function to be used by the already present notify implementation.
1 parent a79f35a commit 7ef3cd4

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

patroni/daemon.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@
1818

1919
logger = logging.getLogger(__name__)
2020

21+
try: # pragma: no cover
22+
from systemd import daemon # pyright: ignore
23+
24+
def notify_systemd(msg: str) -> None:
25+
daemon.notify(msg) # pyright: ignore
26+
27+
except ImportError: # pragma: no cover
28+
logger.info("Systemd integration is not supported")
29+
30+
def notify_systemd(msg: str) -> None:
31+
pass
32+
2133

2234
def get_base_arg_parser() -> argparse.ArgumentParser:
2335
"""Create a basic argument parser with the arguments used for both patroni and raft controller daemon.
@@ -67,6 +79,7 @@ def sighup_handler(self, *_: Any) -> None:
6779
Flag the daemon as "SIGHUP received".
6880
"""
6981
self._received_sighup = True
82+
notify_systemd("RELOADING=1")
7083

7184
def api_sigterm(self) -> bool:
7285
"""Guarantee only a single SIGTERM is being processed.
@@ -135,16 +148,13 @@ def run(self) -> None:
135148
Start the logger thread and keep running execution cycles until a SIGTERM is eventually received. Also reload
136149
configuration upon receiving SIGHUP.
137150
"""
138-
try: # pragma: no cover
139-
from systemd import daemon # pyright: ignore
140-
daemon.notify("READY=1") # pyright: ignore
141-
except ImportError: # pragma: no cover
142-
logger.info("Systemd integration is not supported")
151+
notify_systemd("READY=1")
143152
self.logger.start()
144153
while not self.received_sigterm:
145154
if self._received_sighup:
146155
self._received_sighup = False
147156
self.reload_config(True, self.config.reload_local_configuration())
157+
notify_systemd("READY=1")
148158

149159
self._run_cycle()
150160

0 commit comments

Comments
 (0)