aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPeter Eisentraut <peter_e@gmx.net>2015-11-17 06:46:17 -0500
committerPeter Eisentraut <peter_e@gmx.net>2016-02-02 21:04:29 -0500
commit7d17e683fcc28a1b371c7dd02935728cd2cbf9bf (patch)
tree5c27c3a9dedb188013e4d886c8a24feebfebf69d /src
parentac7238dc0faccb0ad077aa9922df6e75b0b1bda3 (diff)
downloadpostgresql-7d17e683fcc28a1b371c7dd02935728cd2cbf9bf.tar.gz
postgresql-7d17e683fcc28a1b371c7dd02935728cd2cbf9bf.zip
Add support for systemd service notifications
Insert sd_notify() calls at server start and stop for integration with systemd. This allows the use of systemd service units of type "notify", which greatly simplifies the systemd configuration. Reviewed-by: Pavel Stěhule <pavel.stehule@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.global.in1
-rw-r--r--src/backend/Makefile4
-rw-r--r--src/backend/postmaster/postmaster.c26
-rw-r--r--src/include/pg_config.h.in3
4 files changed, 34 insertions, 0 deletions
diff --git a/src/Makefile.global.in b/src/Makefile.global.in
index 51f479713c3..e94d6a58a0c 100644
--- a/src/Makefile.global.in
+++ b/src/Makefile.global.in
@@ -184,6 +184,7 @@ with_python = @with_python@
with_tcl = @with_tcl@
with_openssl = @with_openssl@
with_selinux = @with_selinux@
+with_systemd = @with_systemd@
with_libxml = @with_libxml@
with_libxslt = @with_libxslt@
with_system_tzdata = @with_system_tzdata@
diff --git a/src/backend/Makefile b/src/backend/Makefile
index d4db8ff57a2..b3d5e2e1bd9 100644
--- a/src/backend/Makefile
+++ b/src/backend/Makefile
@@ -45,6 +45,10 @@ LIBS := $(filter-out -lpgport -lpgcommon, $(LIBS)) $(LDAP_LIBS_BE)
# The backend doesn't need everything that's in LIBS, however
LIBS := $(filter-out -lz -lreadline -ledit -ltermcap -lncurses -lcurses, $(LIBS))
+ifeq ($(with_systemd),yes)
+LIBS += -lsystemd
+endif
+
##########################################################################
all: submake-libpgport submake-schemapg postgres $(POSTGRES_IMP)
diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c
index 9aaed5b9848..d983a50ee1d 100644
--- a/src/backend/postmaster/postmaster.c
+++ b/src/backend/postmaster/postmaster.c
@@ -87,6 +87,10 @@
#include <dns_sd.h>
#endif
+#ifdef USE_SYSTEMD
+#include <systemd/sd-daemon.h>
+#endif
+
#ifdef HAVE_PTHREAD_IS_THREADED_NP
#include <pthread.h>
#endif
@@ -2533,6 +2537,9 @@ pmdie(SIGNAL_ARGS)
Shutdown = SmartShutdown;
ereport(LOG,
(errmsg("received smart shutdown request")));
+#ifdef USE_SYSTEMD
+ sd_notify(0, "STOPPING=1");
+#endif
if (pmState == PM_RUN || pmState == PM_RECOVERY ||
pmState == PM_HOT_STANDBY || pmState == PM_STARTUP)
@@ -2585,6 +2592,9 @@ pmdie(SIGNAL_ARGS)
Shutdown = FastShutdown;
ereport(LOG,
(errmsg("received fast shutdown request")));
+#ifdef USE_SYSTEMD
+ sd_notify(0, "STOPPING=1");
+#endif
if (StartupPID != 0)
signal_child(StartupPID, SIGTERM);
@@ -2645,6 +2655,9 @@ pmdie(SIGNAL_ARGS)
Shutdown = ImmediateShutdown;
ereport(LOG,
(errmsg("received immediate shutdown request")));
+#ifdef USE_SYSTEMD
+ sd_notify(0, "STOPPING=1");
+#endif
TerminateChildren(SIGQUIT);
pmState = PM_WAIT_BACKENDS;
@@ -2787,6 +2800,10 @@ reaper(SIGNAL_ARGS)
ereport(LOG,
(errmsg("database system is ready to accept connections")));
+#ifdef USE_SYSTEMD
+ sd_notify(0, "READY=1");
+#endif
+
continue;
}
@@ -4916,6 +4933,11 @@ sigusr1_handler(SIGNAL_ARGS)
if (XLogArchivingAlways())
PgArchPID = pgarch_start();
+#ifdef USE_SYSTEMD
+ if (!EnableHotStandby)
+ sd_notify(0, "READY=1");
+#endif
+
pmState = PM_RECOVERY;
}
if (CheckPostmasterSignal(PMSIGNAL_BEGIN_HOT_STANDBY) &&
@@ -4930,6 +4952,10 @@ sigusr1_handler(SIGNAL_ARGS)
ereport(LOG,
(errmsg("database system is ready to accept read only connections")));
+#ifdef USE_SYSTEMD
+ sd_notify(0, "READY=1");
+#endif
+
pmState = PM_HOT_STANDBY;
/* Some workers may be scheduled to start now */
StartWorkerNeeded = true;
diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in
index 16a272efdee..b3ceea5edc9 100644
--- a/src/include/pg_config.h.in
+++ b/src/include/pg_config.h.in
@@ -833,6 +833,9 @@
/* Define to 1 to use Intel SSSE 4.2 CRC instructions with a runtime check. */
#undef USE_SSE42_CRC32C_WITH_RUNTIME_CHECK
+/* Define to build with systemd support. (--with-systemd) */
+#undef USE_SYSTEMD
+
/* Define to select SysV-style semaphores. */
#undef USE_SYSV_SEMAPHORES