8787#include <dns_sd.h>
8888#endif
8989
90+ #ifdef USE_SYSTEMD
91+ #include <systemd/sd-daemon.h>
92+ #endif
93+
9094#ifdef HAVE_PTHREAD_IS_THREADED_NP
9195#include <pthread.h>
9296#endif
@@ -2533,6 +2537,9 @@ pmdie(SIGNAL_ARGS)
25332537 Shutdown = SmartShutdown ;
25342538 ereport (LOG ,
25352539 (errmsg ("received smart shutdown request" )));
2540+ #ifdef USE_SYSTEMD
2541+ sd_notify (0 , "STOPPING=1" );
2542+ #endif
25362543
25372544 if (pmState == PM_RUN || pmState == PM_RECOVERY ||
25382545 pmState == PM_HOT_STANDBY || pmState == PM_STARTUP )
@@ -2585,6 +2592,9 @@ pmdie(SIGNAL_ARGS)
25852592 Shutdown = FastShutdown ;
25862593 ereport (LOG ,
25872594 (errmsg ("received fast shutdown request" )));
2595+ #ifdef USE_SYSTEMD
2596+ sd_notify (0 , "STOPPING=1" );
2597+ #endif
25882598
25892599 if (StartupPID != 0 )
25902600 signal_child (StartupPID , SIGTERM );
@@ -2645,6 +2655,9 @@ pmdie(SIGNAL_ARGS)
26452655 Shutdown = ImmediateShutdown ;
26462656 ereport (LOG ,
26472657 (errmsg ("received immediate shutdown request" )));
2658+ #ifdef USE_SYSTEMD
2659+ sd_notify (0 , "STOPPING=1" );
2660+ #endif
26482661
26492662 TerminateChildren (SIGQUIT );
26502663 pmState = PM_WAIT_BACKENDS ;
@@ -2787,6 +2800,10 @@ reaper(SIGNAL_ARGS)
27872800 ereport (LOG ,
27882801 (errmsg ("database system is ready to accept connections" )));
27892802
2803+ #ifdef USE_SYSTEMD
2804+ sd_notify (0 , "READY=1" );
2805+ #endif
2806+
27902807 continue ;
27912808 }
27922809
@@ -4916,6 +4933,11 @@ sigusr1_handler(SIGNAL_ARGS)
49164933 if (XLogArchivingAlways ())
49174934 PgArchPID = pgarch_start ();
49184935
4936+ #ifdef USE_SYSTEMD
4937+ if (!EnableHotStandby )
4938+ sd_notify (0 , "READY=1" );
4939+ #endif
4940+
49194941 pmState = PM_RECOVERY ;
49204942 }
49214943 if (CheckPostmasterSignal (PMSIGNAL_BEGIN_HOT_STANDBY ) &&
@@ -4930,6 +4952,10 @@ sigusr1_handler(SIGNAL_ARGS)
49304952 ereport (LOG ,
49314953 (errmsg ("database system is ready to accept read only connections" )));
49324954
4955+ #ifdef USE_SYSTEMD
4956+ sd_notify (0 , "READY=1" );
4957+ #endif
4958+
49334959 pmState = PM_HOT_STANDBY ;
49344960 /* Some workers may be scheduled to start now */
49354961 StartWorkerNeeded = true;
0 commit comments