Add support for systemd "notify" unit type (#3301)

Close #3300
This commit is contained in:
Ronan Dunklau
2025-03-12 17:28:54 +01:00
committed by GitHub
parent c6943dc415
commit 5ed4d33f7d
5 changed files with 14 additions and 1 deletions
+2
View File
@@ -102,6 +102,8 @@ raft
`pysyncobj` module in order to use python Raft implementation as DCS `pysyncobj` module in order to use python Raft implementation as DCS
aws aws
`boto3` in order to use AWS callbacks `boto3` in order to use AWS callbacks
systemd
`systemd-python` in order to use sd_notify integration
all all
all of the above (except psycopg family) all of the above (except psycopg family)
psycopg3 psycopg3
+2
View File
@@ -62,6 +62,8 @@ aws
`boto3` in order to use AWS callbacks `boto3` in order to use AWS callbacks
jsonlogger jsonlogger
`python-json-logger` module in order to enable :ref:`logging <log_settings>` in json format `python-json-logger` module in order to enable :ref:`logging <log_settings>` in json format
systemd
`systemd-python` in order to use sd_notify integration
all all
all of the above (except psycopg family) all of the above (except psycopg family)
psycopg psycopg
+1 -1
View File
@@ -6,7 +6,7 @@ Description=Runners to orchestrate a high-availability PostgreSQL
After=syslog.target network.target After=syslog.target network.target
[Service] [Service]
Type=simple Type=notify
User=postgres User=postgres
Group=postgres Group=postgres
+8
View File
@@ -7,6 +7,7 @@ from __future__ import print_function
import abc import abc
import argparse import argparse
import logging
import os import os
import signal import signal
import sys import sys
@@ -17,6 +18,8 @@ from typing import Any, Optional, Type, TYPE_CHECKING
if TYPE_CHECKING: # pragma: no cover if TYPE_CHECKING: # pragma: no cover
from .config import Config from .config import Config
logger = logging.getLogger(__name__)
def get_base_arg_parser() -> argparse.ArgumentParser: def get_base_arg_parser() -> argparse.ArgumentParser:
"""Create a basic argument parser with the arguments used for both patroni and raft controller daemon. """Create a basic argument parser with the arguments used for both patroni and raft controller daemon.
@@ -134,6 +137,11 @@ class AbstractPatroniDaemon(abc.ABC):
Start the logger thread and keep running execution cycles until a SIGTERM is eventually received. Also reload Start the logger thread and keep running execution cycles until a SIGTERM is eventually received. Also reload
configuration upon receiving SIGHUP. configuration upon receiving SIGHUP.
""" """
try: # pragma: no cover
from systemd import daemon # pyright: ignore
daemon.notify("READY=1") # pyright: ignore
except ImportError: # pragma: no cover
logger.info("Systemd integration is not supported")
self.logger.start() self.logger.start()
while not self.received_sigterm: while not self.received_sigterm:
if self._received_sighup: if self._received_sighup:
+1
View File
@@ -26,6 +26,7 @@ KEYWORDS = 'etcd governor patroni postgresql postgres ha haproxy confd' +\
EXTRAS_REQUIRE = {'aws': ['boto3'], 'etcd': ['python-etcd'], 'etcd3': ['python-etcd'], EXTRAS_REQUIRE = {'aws': ['boto3'], 'etcd': ['python-etcd'], 'etcd3': ['python-etcd'],
'consul': ['py-consul'], 'exhibitor': ['kazoo'], 'zookeeper': ['kazoo'], 'consul': ['py-consul'], 'exhibitor': ['kazoo'], 'zookeeper': ['kazoo'],
'systemd': ['systemd-python'],
'kubernetes': [], 'raft': ['pysyncobj', 'cryptography'], 'jsonlogger': ['python-json-logger']} 'kubernetes': [], 'raft': ['pysyncobj', 'cryptography'], 'jsonlogger': ['python-json-logger']}
# Add here all kinds of additional classifiers as defined under # Add here all kinds of additional classifiers as defined under