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

View File

@@ -102,6 +102,8 @@ raft
`pysyncobj` module in order to use python Raft implementation as DCS
aws
`boto3` in order to use AWS callbacks
systemd
`systemd-python` in order to use sd_notify integration
all
all of the above (except psycopg family)
psycopg3

View File

@@ -62,6 +62,8 @@ aws
`boto3` in order to use AWS callbacks
jsonlogger
`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 of the above (except psycopg family)
psycopg

View File

@@ -6,7 +6,7 @@ Description=Runners to orchestrate a high-availability PostgreSQL
After=syslog.target network.target
[Service]
Type=simple
Type=notify
User=postgres
Group=postgres

View File

@@ -7,6 +7,7 @@ from __future__ import print_function
import abc
import argparse
import logging
import os
import signal
import sys
@@ -17,6 +18,8 @@ from typing import Any, Optional, Type, TYPE_CHECKING
if TYPE_CHECKING: # pragma: no cover
from .config import Config
logger = logging.getLogger(__name__)
def get_base_arg_parser() -> argparse.ArgumentParser:
"""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
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()
while not self.received_sigterm:
if self._received_sighup:

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'],
'consul': ['py-consul'], 'exhibitor': ['kazoo'], 'zookeeper': ['kazoo'],
'systemd': ['systemd-python'],
'kubernetes': [], 'raft': ['pysyncobj', 'cryptography'], 'jsonlogger': ['python-json-logger']}
# Add here all kinds of additional classifiers as defined under