|
18 | 18 |
|
19 | 19 | logger = logging.getLogger(__name__) |
20 | 20 |
|
| 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 | + |
21 | 33 |
|
22 | 34 | def get_base_arg_parser() -> argparse.ArgumentParser: |
23 | 35 | """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: |
67 | 79 | Flag the daemon as "SIGHUP received". |
68 | 80 | """ |
69 | 81 | self._received_sighup = True |
| 82 | + notify_systemd("RELOADING=1") |
70 | 83 |
|
71 | 84 | def api_sigterm(self) -> bool: |
72 | 85 | """Guarantee only a single SIGTERM is being processed. |
@@ -135,16 +148,13 @@ def run(self) -> None: |
135 | 148 | Start the logger thread and keep running execution cycles until a SIGTERM is eventually received. Also reload |
136 | 149 | configuration upon receiving SIGHUP. |
137 | 150 | """ |
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") |
143 | 152 | self.logger.start() |
144 | 153 | while not self.received_sigterm: |
145 | 154 | if self._received_sighup: |
146 | 155 | self._received_sighup = False |
147 | 156 | self.reload_config(True, self.config.reload_local_configuration()) |
| 157 | + notify_systemd("READY=1") |
148 | 158 |
|
149 | 159 | self._run_cycle() |
150 | 160 |
|
|
0 commit comments