diff --git a/README.rst b/README.rst index 81313470..1ccb862a 100644 --- a/README.rst +++ b/README.rst @@ -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 diff --git a/docs/installation.rst b/docs/installation.rst index 100ad01e..d2d8ba7c 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -62,6 +62,8 @@ aws `boto3` in order to use AWS callbacks jsonlogger `python-json-logger` module in order to enable :ref:`logging ` in json format +systemd + `systemd-python` in order to use sd_notify integration all all of the above (except psycopg family) psycopg diff --git a/extras/startup-scripts/patroni.service b/extras/startup-scripts/patroni.service index 7c156492..5893b216 100644 --- a/extras/startup-scripts/patroni.service +++ b/extras/startup-scripts/patroni.service @@ -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 diff --git a/patroni/daemon.py b/patroni/daemon.py index d4cce10e..dfc71600 100644 --- a/patroni/daemon.py +++ b/patroni/daemon.py @@ -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: diff --git a/setup.py b/setup.py index 9ed84efd..d21141cc 100644 --- a/setup.py +++ b/setup.py @@ -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