[packages/pgpool-II] systemd unit added, configurable shutdown mode

jajcus jajcus at pld-linux.org
Wed Nov 30 13:07:46 CET 2016


commit 93d5f0ce2b9e54f096a319db3fb8b1c6eb325027
Author: Jacek Konieczny <j.konieczny at eggsoft.pl>
Date:   Wed Nov 30 12:07:06 2016 +0100

    systemd unit added, configurable shutdown mode

 pgpool-II.spec   | 12 ++++++++++--
 pgpool.init      |  8 +++++++-
 pgpool.service   | 17 +++++++++++++++++
 pgpool.sysconfig |  2 ++
 4 files changed, 36 insertions(+), 3 deletions(-)
---
diff --git a/pgpool-II.spec b/pgpool-II.spec
index 44251d7..253b162 100644
--- a/pgpool-II.spec
+++ b/pgpool-II.spec
@@ -1,6 +1,6 @@
 #
 # TODO
-# - logrotate script
+# - logrotate script (note not needed under systemd: logs go to journal)
 #
 %bcond_without	openssl	# build without SSL support
 %bcond_without	pam	# don't build with pam support
@@ -20,11 +20,13 @@ Source1:	%{relname}.init
 Source2:	%{relname}.monitrc
 Source3:	%{relname}.sysconfig
 Source4:	%{relname}.tmpfiles
+Source5:	%{relname}.service
 URL:		http://www.pgpool.net/
 %{?with_openssl:BuildRequires:	openssl-devel}
 %{?with_pam:BuildRequires:	pam-devel}
 BuildRequires:	postgresql-devel
 BuildRequires:	sed >= 4.0
+BuildRequires:	rpmbuild(macros) >= 1.671
 Requires(post,preun):	/sbin/chkconfig
 Requires(postun):	/usr/sbin/groupdel
 Requires(postun):	/usr/sbin/userdel
@@ -35,6 +37,7 @@ Requires(pre):	/usr/sbin/useradd
 Requires:	%{name}-libs = %{version}-%{release}
 %{?with_pam:Requires:	pam}
 Requires:	rc-scripts >= 0.2.0
+Requires:	systemd-units >= 38
 Provides:	group(pgpool)
 Provides:	pgpool
 Provides:	user(pgpool)
@@ -130,7 +133,7 @@ export CFLAGS CXXFLAGS
 %install
 rm -rf $RPM_BUILD_ROOT
 
-install -d $RPM_BUILD_ROOT{/etc/rc.d/init.d,%{_sysconfdir}/{sysconfig,monit,pam.d},%{_varrun}/pgpool,%{systemdtmpfilesdir},%{_mandir}/man{1,8},/var/log/pgpool}
+install -d $RPM_BUILD_ROOT{/etc/rc.d/init.d,%{_sysconfdir}/{sysconfig,monit,pam.d},%{_varrun}/pgpool,%{systemdtmpfilesdir},%{_mandir}/man{1,8},/var/log/pgpool,%{systemdunitdir}}
 
 %{__make} install \
 	DESTDIR=$RPM_BUILD_ROOT
@@ -142,6 +145,7 @@ cp -p %{SOURCE1} $RPM_BUILD_ROOT/etc/rc.d/init.d/%{relname}
 cp -p %{SOURCE2} $RPM_BUILD_ROOT%{_sysconfdir}/monit/%{relname}.monitrc
 cp -p %{SOURCE3} $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig/%{relname}
 cp -p %{SOURCE4} $RPM_BUILD_ROOT%{systemdtmpfilesdir}/%{relname}.conf
+cp -p %{SOURCE5} $RPM_BUILD_ROOT%{systemdunitdir}/%{relname}.service
 %if %{with pam}
 cp -p src/sample/pgpool.pam $RPM_BUILD_ROOT%{_sysconfdir}/pam.d/pgpool
 %endif
@@ -168,18 +172,21 @@ rm -rf $RPM_BUILD_ROOT
 %post
 /sbin/chkconfig --add %{relname}
 %service %{relname} restart
+%systemd_post %{relname}.service
 
 %preun
 if [ "$1" = "0" ]; then
 	%service %{relname} stop
 	/sbin/chkconfig --del %{relname}
 fi
+%systemd_preun %{relname}.service
 
 %postun
 if [ "$1" = "0" ]; then
 	%userremove pgpool
 	%groupremove pgpool
 fi
+%systemd_reload
 
 %post libs -p /sbin/ldconfig
 
@@ -200,6 +207,7 @@ fi
 %{_datadir}/%{name}
 %dir %attr(775,root,pgpool) %{_varrun}/pgpool
 %{systemdtmpfilesdir}/%{relname}.conf
+%{systemdunitdir}/%{relname}.service
 %if %{with pam}
 %config(noreplace) %verify(not md5 mtime size) /etc/pam.d/pgpool
 %endif
diff --git a/pgpool.init b/pgpool.init
index 829d11b..1b94d16 100644
--- a/pgpool.init
+++ b/pgpool.init
@@ -15,6 +15,12 @@
 . /etc/sysconfig/network
 
 PGPOOL_BIN=/usr/bin/pgpool
+PGPOOLUID=pgpool
+PGPOOLGID=pgpool
+PGPOOLCONF=/etc/pgpool.conf
+PGPOOLHBA=/etc/pool_hba.conf
+PGPOOLLOG=/var/log/pgpool.log
+SHUTDOWN_MODE=smart
 
 # Get service config
 [ -f /etc/sysconfig/pgpool ] && . /etc/sysconfig/pgpool
@@ -59,7 +65,7 @@ stop() {
 	if [ -f /var/lock/subsys/pgpool ]; then
 		msg_stopping pgpool
 		busy
-		output=$($PGPOOL_BIN -f "$PGPOOLCONF" stop 2>&1)
+		output=$($PGPOOL_BIN -f "$PGPOOLCONF" -m "$SHUTDOWN_MODE" stop 2>&1)
 		if [ $? -eq 0 ]; then
 			rm -f /var/run/pgpool/pgpool.pid >/dev/null 2>&1
 			ok
diff --git a/pgpool.service b/pgpool.service
new file mode 100644
index 0000000..3e0f288
--- /dev/null
+++ b/pgpool.service
@@ -0,0 +1,17 @@
+[Unit]
+Description=Pgpool - a connection pooling/replication server for PostgreSQL
+After=network.target
+
+[Service]
+Type=forking
+Environment=PGPOOLCONF=/etc/pgpool.conf PGPOOLHBA=/etc/pool_hba.conf SHUTDOWN_MODE=smart
+EnvironmentFile=-/etc/sysconfig/pgpool
+ExecStart=/usr/bin/pgpool -f ${PGPOOLCONF} -a ${PGPOOLHBA} $OPTS
+ExecStop=/usr/bin/pgpool -f ${PGPOOLCONF} -m ${SHUTDOWN_MODE} stop
+ExecReload=/usr/bin/pgpool -f ${PGPOOLCONF} reload
+PIDFile=/var/run/pgpool/pgpool.pid
+User=pgpool
+Group=pgpool
+
+[Install]
+WantedBy=multi-user.target
diff --git a/pgpool.sysconfig b/pgpool.sysconfig
index 2bf4e6c..be92298 100644
--- a/pgpool.sysconfig
+++ b/pgpool.sysconfig
@@ -10,6 +10,8 @@ PGPOOLHBA=/etc/pool_hba.conf
 
 PGPOOLLOG=/var/log/pgpool.log
 
+SHUTDOWN_MODE=smart
+
 # Options for pgpool
 # -n: don't run in daemon mode; does not detach control TTY
 # -d: debug mode; lots of debug information will be printed
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/packages/pgpool-II.git/commitdiff/eb61ed23e7d323047bfc2aa1fab56e9d695428d7



More information about the pld-cvs-commit mailing list