>From a5eeaf156cdf1224dd50058238665b0177af0293 Mon Sep 17 00:00:00 2001
From: Martin <martin@2ndquadrant.com>
Date: Wed, 30 Dec 2015 17:25:28 -0300
Subject: [PATCH] fix BUG related with systemd not killing repmgrd

---
 rpm/redhat/9.1/repmgr/EL-5/repmgr-9.1.service | 11 ++++++-----
 rpm/redhat/9.1/repmgr/EL-6/repmgr-9.1.service | 11 ++++++-----
 rpm/redhat/9.2/repmgr/EL-5/repmgr-9.2.service | 13 ++++++++-----
 rpm/redhat/9.2/repmgr/EL-6/repmgr-9.2.service | 11 ++++++-----
 rpm/redhat/9.2/repmgr/EL-7/repmgr-9.2.service | 11 ++++++-----
 rpm/redhat/9.2/repmgr/F-19/repmgr-9.2.service | 11 ++++++-----
 rpm/redhat/9.3/repmgr/EL-5/repmgr-9.3.service | 13 ++++++++-----
 rpm/redhat/9.3/repmgr/EL-6/repmgr-9.3.service | 11 +++++++----
 rpm/redhat/9.3/repmgr/EL-7/repmgr-9.3.service | 11 +++++++----
 rpm/redhat/9.3/repmgr/F-20/repmgr-9.3.service | 11 +++++++----
 rpm/redhat/9.3/repmgr/F-21/repmgr-9.3.service | 11 +++++++----
 rpm/redhat/9.3/repmgr/F-22/repmgr-9.3.service | 11 +++++++----
 rpm/redhat/9.3/repmgr/F-23/repmgr-9.3.service | 13 ++++++++-----
 rpm/redhat/9.4/repmgr/EL-5/repmgr-9.4.service | 11 +++++++----
 rpm/redhat/9.4/repmgr/EL-6/repmgr-9.4.service | 11 +++++++----
 rpm/redhat/9.4/repmgr/EL-7/repmgr-9.4.service | 11 +++++++----
 rpm/redhat/9.4/repmgr/F-20/repmgr-9.4.service | 11 +++++++----
 rpm/redhat/9.4/repmgr/F-21/repmgr-9.4.service | 11 +++++++----
 rpm/redhat/9.4/repmgr/F-22/repmgr-9.4.service | 11 +++++++----
 rpm/redhat/9.4/repmgr/F-23/repmgr-9.4.service | 11 +++++++----
 rpm/redhat/9.5/repmgr/EL-5/repmgr-9.5.service |  7 ++++---
 rpm/redhat/9.5/repmgr/EL-6/repmgr-9.5.service |  7 ++++---
 rpm/redhat/9.5/repmgr/EL-7/repmgr-9.5.service |  7 ++++---
 rpm/redhat/9.5/repmgr/F-20/repmgr-9.5.service |  7 ++++---
 rpm/redhat/9.5/repmgr/F-21/repmgr-9.5.service |  7 ++++---
 rpm/redhat/9.5/repmgr/F-22/repmgr-9.5.service |  7 ++++---
 rpm/redhat/9.5/repmgr/F-23/repmgr-9.5.service |  7 ++++---
 27 files changed, 166 insertions(+), 109 deletions(-)

diff --git a/rpm/redhat/9.1/repmgr/EL-5/repmgr-9.1.service b/rpm/redhat/9.1/repmgr/EL-5/repmgr-9.1.service
index 5a3d584..799696c 100644
--- a/rpm/redhat/9.1/repmgr/EL-5/repmgr-9.1.service
+++ b/rpm/redhat/9.1/repmgr/EL-5/repmgr-9.1.service
@@ -15,8 +15,9 @@ After=network.target
 [Service]
 Type=forking
 
-User=repmgr
-Group=repmgr
+PIDFile=/var/run/repmgr/repmgrd-9.1.pid
+User=postgres
+Group=postgres
 
 # Location of repmgr conf file:
 Environment=REPMGRDCONF=/etc/repmgr/9.1/repmgr.conf
@@ -26,9 +27,9 @@ Environment=REPMGRDLOG=/var/log/repmgr/repmgrd-9.1.log
 # Where to send early-startup messages from the server 
 # This is normally controlled by the global default set by systemd
 # StandardOutput=syslog
-ExecStart=/usr/pgsql-9.1/bin/repmgrd -f ${REPMGRDCONF} -p ${PIDFILE} -d > ${REPMGRDLOG} 2>&1" 
-ExecStop=/usr/bin/kill -TERM ${PIDFILE}
-ExecReload=/usr/bin/kill -HUP ${PIDFILE}
+ExecStart=/usr/pgsql-9.1/bin/repmgrd -f ${REPMGRDCONF} -p ${PIDFILE} -d >> ${REPMGRDLOG} 2>&1" 
+ExecStop=/usr/bin/kill -TERM $MAINPID
+ExecReload=/usr/bin/kill -HUP $MAINPID
 
 # Give a reasonable amount of time for the server to start up/shut down
 TimeoutSec=300
diff --git a/rpm/redhat/9.1/repmgr/EL-6/repmgr-9.1.service b/rpm/redhat/9.1/repmgr/EL-6/repmgr-9.1.service
index 1d545b4..d6208c0 100644
--- a/rpm/redhat/9.1/repmgr/EL-6/repmgr-9.1.service
+++ b/rpm/redhat/9.1/repmgr/EL-6/repmgr-9.1.service
@@ -15,8 +15,9 @@ After=network.target
 [Service]
 Type=forking
 
-User=repmgr
-Group=repmgr
+PIDFile=/var/run/repmgr/repmgrd-9.1.pid
+User=postgres
+Group=postgres
 
 # Location of repmgr conf file:
 Environment=REPMGRDCONF=/etc/repmgr/9.1/repmgr.conf
@@ -26,9 +27,9 @@ Environment=REPMGRDLOG=/var/log/repmgr/repmgrd-9.1.log
 # Where to send early-startup messages from the server 
 # This is normally controlled by the global default set by systemd
 # StandardOutput=syslog
-ExecStart=/usr/pgsql-9.1/bin/repmgrd -f ${REPMGRDCONF} -p ${PIDFILE} -d ->> ${REPMGRDLOG} 2>&1
-ExecStop=/usr/bin/kill -TERM ${PIDFILE}
-ExecReload=/usr/bin/kill -HUP ${PIDFILE}
+ExecStart=/usr/pgsql-9.1/bin/repmgrd -f ${REPMGRDCONF} -p ${PIDFILE} -d >> ${REPMGRDLOG} 2>&1
+ExecStop=/usr/bin/kill -TERM $MAINPID
+ExecReload=/usr/bin/kill -HUP $MAINPID
 
 # Give a reasonable amount of time for the server to start up/shut down
 TimeoutSec=300
diff --git a/rpm/redhat/9.2/repmgr/EL-5/repmgr-9.2.service b/rpm/redhat/9.2/repmgr/EL-5/repmgr-9.2.service
index a54ee8d..e8fbe1e 100644
--- a/rpm/redhat/9.2/repmgr/EL-5/repmgr-9.2.service
+++ b/rpm/redhat/9.2/repmgr/EL-5/repmgr-9.2.service
@@ -15,8 +15,11 @@ After=network.target
 [Service]
 Type=forking
 
-User=repmgr
-Group=repmgr
+# PID file
+PIDFile=/var/run/repmgr/repmgrd-9.2.pid
+
+User=postgres
+Group=postgres
 
 # Location of repmgr conf file:
 Environment=REPMGRDCONF=/etc/repmgr/9.2/repmgr.conf
@@ -26,9 +29,9 @@ Environment=REPMGRDLOG=/var/log/repmgr/repmgrd-9.2.log
 # Where to send early-startup messages from the server 
 # This is normally controlled by the global default set by systemd
 # StandardOutput=syslog
-ExecStart=/usr/pgsql-9.2/bin/repmgrd -f ${REPMGRDCONF} -p ${PIDFILE} -d > ${REPMGRDLOG} 2>&1
-ExecStop=/usr/bin/kill -TERM ${PIDFILE}
-ExecReload=/usr/bin/kill -HUP ${PIDFILE}
+ExecStart=/usr/pgsql-9.2/bin/repmgrd -f ${REPMGRDCONF} -p ${PIDFILE} -d >> ${REPMGRDLOG} 2>&1
+ExecStop=/usr/bin/kill -TERM $MAINPID
+ExecReload=/usr/bin/kill -HUP $MAINPID
 
 # Give a reasonable amount of time for the server to start up/shut down
 TimeoutSec=300
diff --git a/rpm/redhat/9.2/repmgr/EL-6/repmgr-9.2.service b/rpm/redhat/9.2/repmgr/EL-6/repmgr-9.2.service
index ef1aeed..d5f3afc 100644
--- a/rpm/redhat/9.2/repmgr/EL-6/repmgr-9.2.service
+++ b/rpm/redhat/9.2/repmgr/EL-6/repmgr-9.2.service
@@ -15,8 +15,9 @@ After=network.target
 [Service]
 Type=forking
 
-User=repmgr
-Group=repmgr
+PIDFile=/var/run/repmgr/repmgrd-9.2.pid
+User=postgres
+Group=postgres
 
 # Location of repmgr conf file:
 Environment=REPMGRDCONF=/etc/repmgr/9.2/repmgr.conf
@@ -26,9 +27,9 @@ Environment=REPMGRDLOG=/var/log/repmgr/repmgrd-9.2.log
 # Where to send early-startup messages from the server 
 # This is normally controlled by the global default set by systemd
 # StandardOutput=syslog
-ExecStart=/usr/pgsql-9.2/bin/repmgrd -f ${REPMGRDCONF} -p ${PIDFILE} -d ->> ${REPMGRDLOG} 2>&1
-ExecStop=/usr/bin/kill -TERM ${PIDFILE}
-ExecReload=/usr/bin/kill -HUP ${PIDFILE}
+ExecStart=/usr/pgsql-9.2/bin/repmgrd -f ${REPMGRDCONF} -p ${PIDFILE} -d >> ${REPMGRDLOG} 2>&1
+ExecStop=/usr/bin/kill -TERM $MAINPID
+ExecReload=/usr/bin/kill -HUP $MAINPID
 
 # Give a reasonable amount of time for the server to start up/shut down
 TimeoutSec=300
diff --git a/rpm/redhat/9.2/repmgr/EL-7/repmgr-9.2.service b/rpm/redhat/9.2/repmgr/EL-7/repmgr-9.2.service
index ef1aeed..d5f3afc 100644
--- a/rpm/redhat/9.2/repmgr/EL-7/repmgr-9.2.service
+++ b/rpm/redhat/9.2/repmgr/EL-7/repmgr-9.2.service
@@ -15,8 +15,9 @@ After=network.target
 [Service]
 Type=forking
 
-User=repmgr
-Group=repmgr
+PIDFile=/var/run/repmgr/repmgrd-9.2.pid
+User=postgres
+Group=postgres
 
 # Location of repmgr conf file:
 Environment=REPMGRDCONF=/etc/repmgr/9.2/repmgr.conf
@@ -26,9 +27,9 @@ Environment=REPMGRDLOG=/var/log/repmgr/repmgrd-9.2.log
 # Where to send early-startup messages from the server 
 # This is normally controlled by the global default set by systemd
 # StandardOutput=syslog
-ExecStart=/usr/pgsql-9.2/bin/repmgrd -f ${REPMGRDCONF} -p ${PIDFILE} -d ->> ${REPMGRDLOG} 2>&1
-ExecStop=/usr/bin/kill -TERM ${PIDFILE}
-ExecReload=/usr/bin/kill -HUP ${PIDFILE}
+ExecStart=/usr/pgsql-9.2/bin/repmgrd -f ${REPMGRDCONF} -p ${PIDFILE} -d >> ${REPMGRDLOG} 2>&1
+ExecStop=/usr/bin/kill -TERM $MAINPID
+ExecReload=/usr/bin/kill -HUP $MAINPID
 
 # Give a reasonable amount of time for the server to start up/shut down
 TimeoutSec=300
diff --git a/rpm/redhat/9.2/repmgr/F-19/repmgr-9.2.service b/rpm/redhat/9.2/repmgr/F-19/repmgr-9.2.service
index ef1aeed..d5f3afc 100644
--- a/rpm/redhat/9.2/repmgr/F-19/repmgr-9.2.service
+++ b/rpm/redhat/9.2/repmgr/F-19/repmgr-9.2.service
@@ -15,8 +15,9 @@ After=network.target
 [Service]
 Type=forking
 
-User=repmgr
-Group=repmgr
+PIDFile=/var/run/repmgr/repmgrd-9.2.pid
+User=postgres
+Group=postgres
 
 # Location of repmgr conf file:
 Environment=REPMGRDCONF=/etc/repmgr/9.2/repmgr.conf
@@ -26,9 +27,9 @@ Environment=REPMGRDLOG=/var/log/repmgr/repmgrd-9.2.log
 # Where to send early-startup messages from the server 
 # This is normally controlled by the global default set by systemd
 # StandardOutput=syslog
-ExecStart=/usr/pgsql-9.2/bin/repmgrd -f ${REPMGRDCONF} -p ${PIDFILE} -d ->> ${REPMGRDLOG} 2>&1
-ExecStop=/usr/bin/kill -TERM ${PIDFILE}
-ExecReload=/usr/bin/kill -HUP ${PIDFILE}
+ExecStart=/usr/pgsql-9.2/bin/repmgrd -f ${REPMGRDCONF} -p ${PIDFILE} -d >> ${REPMGRDLOG} 2>&1
+ExecStop=/usr/bin/kill -TERM $MAINPID
+ExecReload=/usr/bin/kill -HUP $MAINPID
 
 # Give a reasonable amount of time for the server to start up/shut down
 TimeoutSec=300
diff --git a/rpm/redhat/9.3/repmgr/EL-5/repmgr-9.3.service b/rpm/redhat/9.3/repmgr/EL-5/repmgr-9.3.service
index 21bf5fc..ca29145 100644
--- a/rpm/redhat/9.3/repmgr/EL-5/repmgr-9.3.service
+++ b/rpm/redhat/9.3/repmgr/EL-5/repmgr-9.3.service
@@ -15,8 +15,11 @@ After=network.target
 [Service]
 Type=forking
 
-User=repmgr
-Group=repmgr
+# PID file
+PIDFile=/var/run/repmgr/repmgrd-9.3.pid
+
+User=postgres
+Group=postgres
 
 # Location of repmgr conf file:
 Environment=REPMGRDCONF=/etc/repmgr/9.3/repmgr.conf
@@ -26,9 +29,9 @@ Environment=REPMGRDLOG=/var/log/repmgr/repmgrd-9.3.log
 # Where to send early-startup messages from the server 
 # This is normally controlled by the global default set by systemd
 # StandardOutput=syslog
-ExecStart=/usr/pgsql-9.3/bin/repmgrd -f ${REPMGRDCONF} -p ${PIDFILE} -d > ${REPMGRDLOG} 2>&1
-ExecStop=/usr/bin/kill -TERM ${PIDFILE}
-ExecReload=/usr/bin/kill -HUP ${PIDFILE}
+ExecStart=/usr/pgsql-9.3/bin/repmgrd -f ${REPMGRDCONF} -p ${PIDFILE} -d >> ${REPMGRDLOG} 2>&1
+ExecStop=/usr/bin/kill -TERM $MAINPID
+ExecReload=/usr/bin/kill -HUP $MAINPID
 
 # Give a reasonable amount of time for the server to start up/shut down
 TimeoutSec=300
diff --git a/rpm/redhat/9.3/repmgr/EL-6/repmgr-9.3.service b/rpm/redhat/9.3/repmgr/EL-6/repmgr-9.3.service
index 8d6bb36..9cc1a31 100644
--- a/rpm/redhat/9.3/repmgr/EL-6/repmgr-9.3.service
+++ b/rpm/redhat/9.3/repmgr/EL-6/repmgr-9.3.service
@@ -15,8 +15,11 @@ After=network.target
 [Service]
 Type=forking
 
-User=repmgr
-Group=repmgr
+# PID file
+PIDFile=/var/run/repmgr/repmgrd-9.3.pid
+
+User=postgres
+Group=postgres
 
 # Location of repmgr conf file:
 Environment=REPMGRDCONF=/etc/repmgr/9.3/repmgr.conf
@@ -27,8 +30,8 @@ Environment=REPMGRDLOG=/var/log/repmgr/repmgrd-9.3.log
 # This is normally controlled by the global default set by systemd
 # StandardOutput=syslog
 ExecStart=/usr/pgsql-9.3/bin/repmgrd -f ${REPMGRDCONF} -p ${PIDFILE} -d ->> ${REPMGRDLOG} 2>&1
-ExecStop=/usr/bin/kill -TERM ${PIDFILE}
-ExecReload=/usr/bin/kill -HUP ${PIDFILE}
+ExecStop=/usr/bin/kill -TERM $MAINPID
+ExecReload=/usr/bin/kill -HUP $MAINPID
 
 # Give a reasonable amount of time for the server to start up/shut down
 TimeoutSec=300
diff --git a/rpm/redhat/9.3/repmgr/EL-7/repmgr-9.3.service b/rpm/redhat/9.3/repmgr/EL-7/repmgr-9.3.service
index 8d6bb36..9cc1a31 100644
--- a/rpm/redhat/9.3/repmgr/EL-7/repmgr-9.3.service
+++ b/rpm/redhat/9.3/repmgr/EL-7/repmgr-9.3.service
@@ -15,8 +15,11 @@ After=network.target
 [Service]
 Type=forking
 
-User=repmgr
-Group=repmgr
+# PID file
+PIDFile=/var/run/repmgr/repmgrd-9.3.pid
+
+User=postgres
+Group=postgres
 
 # Location of repmgr conf file:
 Environment=REPMGRDCONF=/etc/repmgr/9.3/repmgr.conf
@@ -27,8 +30,8 @@ Environment=REPMGRDLOG=/var/log/repmgr/repmgrd-9.3.log
 # This is normally controlled by the global default set by systemd
 # StandardOutput=syslog
 ExecStart=/usr/pgsql-9.3/bin/repmgrd -f ${REPMGRDCONF} -p ${PIDFILE} -d ->> ${REPMGRDLOG} 2>&1
-ExecStop=/usr/bin/kill -TERM ${PIDFILE}
-ExecReload=/usr/bin/kill -HUP ${PIDFILE}
+ExecStop=/usr/bin/kill -TERM $MAINPID
+ExecReload=/usr/bin/kill -HUP $MAINPID
 
 # Give a reasonable amount of time for the server to start up/shut down
 TimeoutSec=300
diff --git a/rpm/redhat/9.3/repmgr/F-20/repmgr-9.3.service b/rpm/redhat/9.3/repmgr/F-20/repmgr-9.3.service
index 8d6bb36..9cc1a31 100644
--- a/rpm/redhat/9.3/repmgr/F-20/repmgr-9.3.service
+++ b/rpm/redhat/9.3/repmgr/F-20/repmgr-9.3.service
@@ -15,8 +15,11 @@ After=network.target
 [Service]
 Type=forking
 
-User=repmgr
-Group=repmgr
+# PID file
+PIDFile=/var/run/repmgr/repmgrd-9.3.pid
+
+User=postgres
+Group=postgres
 
 # Location of repmgr conf file:
 Environment=REPMGRDCONF=/etc/repmgr/9.3/repmgr.conf
@@ -27,8 +30,8 @@ Environment=REPMGRDLOG=/var/log/repmgr/repmgrd-9.3.log
 # This is normally controlled by the global default set by systemd
 # StandardOutput=syslog
 ExecStart=/usr/pgsql-9.3/bin/repmgrd -f ${REPMGRDCONF} -p ${PIDFILE} -d ->> ${REPMGRDLOG} 2>&1
-ExecStop=/usr/bin/kill -TERM ${PIDFILE}
-ExecReload=/usr/bin/kill -HUP ${PIDFILE}
+ExecStop=/usr/bin/kill -TERM $MAINPID
+ExecReload=/usr/bin/kill -HUP $MAINPID
 
 # Give a reasonable amount of time for the server to start up/shut down
 TimeoutSec=300
diff --git a/rpm/redhat/9.3/repmgr/F-21/repmgr-9.3.service b/rpm/redhat/9.3/repmgr/F-21/repmgr-9.3.service
index 8d6bb36..9cc1a31 100644
--- a/rpm/redhat/9.3/repmgr/F-21/repmgr-9.3.service
+++ b/rpm/redhat/9.3/repmgr/F-21/repmgr-9.3.service
@@ -15,8 +15,11 @@ After=network.target
 [Service]
 Type=forking
 
-User=repmgr
-Group=repmgr
+# PID file
+PIDFile=/var/run/repmgr/repmgrd-9.3.pid
+
+User=postgres
+Group=postgres
 
 # Location of repmgr conf file:
 Environment=REPMGRDCONF=/etc/repmgr/9.3/repmgr.conf
@@ -27,8 +30,8 @@ Environment=REPMGRDLOG=/var/log/repmgr/repmgrd-9.3.log
 # This is normally controlled by the global default set by systemd
 # StandardOutput=syslog
 ExecStart=/usr/pgsql-9.3/bin/repmgrd -f ${REPMGRDCONF} -p ${PIDFILE} -d ->> ${REPMGRDLOG} 2>&1
-ExecStop=/usr/bin/kill -TERM ${PIDFILE}
-ExecReload=/usr/bin/kill -HUP ${PIDFILE}
+ExecStop=/usr/bin/kill -TERM $MAINPID
+ExecReload=/usr/bin/kill -HUP $MAINPID
 
 # Give a reasonable amount of time for the server to start up/shut down
 TimeoutSec=300
diff --git a/rpm/redhat/9.3/repmgr/F-22/repmgr-9.3.service b/rpm/redhat/9.3/repmgr/F-22/repmgr-9.3.service
index 8d6bb36..9cc1a31 100644
--- a/rpm/redhat/9.3/repmgr/F-22/repmgr-9.3.service
+++ b/rpm/redhat/9.3/repmgr/F-22/repmgr-9.3.service
@@ -15,8 +15,11 @@ After=network.target
 [Service]
 Type=forking
 
-User=repmgr
-Group=repmgr
+# PID file
+PIDFile=/var/run/repmgr/repmgrd-9.3.pid
+
+User=postgres
+Group=postgres
 
 # Location of repmgr conf file:
 Environment=REPMGRDCONF=/etc/repmgr/9.3/repmgr.conf
@@ -27,8 +30,8 @@ Environment=REPMGRDLOG=/var/log/repmgr/repmgrd-9.3.log
 # This is normally controlled by the global default set by systemd
 # StandardOutput=syslog
 ExecStart=/usr/pgsql-9.3/bin/repmgrd -f ${REPMGRDCONF} -p ${PIDFILE} -d ->> ${REPMGRDLOG} 2>&1
-ExecStop=/usr/bin/kill -TERM ${PIDFILE}
-ExecReload=/usr/bin/kill -HUP ${PIDFILE}
+ExecStop=/usr/bin/kill -TERM $MAINPID
+ExecReload=/usr/bin/kill -HUP $MAINPID
 
 # Give a reasonable amount of time for the server to start up/shut down
 TimeoutSec=300
diff --git a/rpm/redhat/9.3/repmgr/F-23/repmgr-9.3.service b/rpm/redhat/9.3/repmgr/F-23/repmgr-9.3.service
index 8d6bb36..ca29145 100644
--- a/rpm/redhat/9.3/repmgr/F-23/repmgr-9.3.service
+++ b/rpm/redhat/9.3/repmgr/F-23/repmgr-9.3.service
@@ -15,8 +15,11 @@ After=network.target
 [Service]
 Type=forking
 
-User=repmgr
-Group=repmgr
+# PID file
+PIDFile=/var/run/repmgr/repmgrd-9.3.pid
+
+User=postgres
+Group=postgres
 
 # Location of repmgr conf file:
 Environment=REPMGRDCONF=/etc/repmgr/9.3/repmgr.conf
@@ -26,9 +29,9 @@ Environment=REPMGRDLOG=/var/log/repmgr/repmgrd-9.3.log
 # Where to send early-startup messages from the server 
 # This is normally controlled by the global default set by systemd
 # StandardOutput=syslog
-ExecStart=/usr/pgsql-9.3/bin/repmgrd -f ${REPMGRDCONF} -p ${PIDFILE} -d ->> ${REPMGRDLOG} 2>&1
-ExecStop=/usr/bin/kill -TERM ${PIDFILE}
-ExecReload=/usr/bin/kill -HUP ${PIDFILE}
+ExecStart=/usr/pgsql-9.3/bin/repmgrd -f ${REPMGRDCONF} -p ${PIDFILE} -d >> ${REPMGRDLOG} 2>&1
+ExecStop=/usr/bin/kill -TERM $MAINPID
+ExecReload=/usr/bin/kill -HUP $MAINPID
 
 # Give a reasonable amount of time for the server to start up/shut down
 TimeoutSec=300
diff --git a/rpm/redhat/9.4/repmgr/EL-5/repmgr-9.4.service b/rpm/redhat/9.4/repmgr/EL-5/repmgr-9.4.service
index 0a38556..6dd7acb 100644
--- a/rpm/redhat/9.4/repmgr/EL-5/repmgr-9.4.service
+++ b/rpm/redhat/9.4/repmgr/EL-5/repmgr-9.4.service
@@ -15,8 +15,11 @@ After=network.target
 [Service]
 Type=forking
 
-User=repmgr
-Group=repmgr
+# PID file
+PIDFile=/var/run/repmgr/repmgrd-9.4.pid
+
+User=postgres
+Group=postgres
 
 # Location of repmgr conf file:
 Environment=REPMGRDCONF=/etc/repmgr/9.4/repmgr.conf
@@ -27,8 +30,8 @@ Environment=REPMGRDLOG=/var/log/repmgr/repmgrd-9.4.log
 # This is normally controlled by the global default set by systemd
 # StandardOutput=syslog
 ExecStart=/usr/pgsql-9.4/bin/repmgrd -f ${REPMGRDCONF} -p ${PIDFILE} -d > ${REPMGRDLOG} 2>&1" 
-ExecStop=/usr/bin/kill -TERM ${PIDFILE}
-ExecReload=/usr/bin/kill -HUP ${PIDFILE}
+ExecStop=/usr/bin/kill -TERM $MAINPID
+ExecReload=/usr/bin/kill -HUP $MAINPID
 
 # Give a reasonable amount of time for the server to start up/shut down
 TimeoutSec=300
diff --git a/rpm/redhat/9.4/repmgr/EL-6/repmgr-9.4.service b/rpm/redhat/9.4/repmgr/EL-6/repmgr-9.4.service
index 0a38556..6dd7acb 100644
--- a/rpm/redhat/9.4/repmgr/EL-6/repmgr-9.4.service
+++ b/rpm/redhat/9.4/repmgr/EL-6/repmgr-9.4.service
@@ -15,8 +15,11 @@ After=network.target
 [Service]
 Type=forking
 
-User=repmgr
-Group=repmgr
+# PID file
+PIDFile=/var/run/repmgr/repmgrd-9.4.pid
+
+User=postgres
+Group=postgres
 
 # Location of repmgr conf file:
 Environment=REPMGRDCONF=/etc/repmgr/9.4/repmgr.conf
@@ -27,8 +30,8 @@ Environment=REPMGRDLOG=/var/log/repmgr/repmgrd-9.4.log
 # This is normally controlled by the global default set by systemd
 # StandardOutput=syslog
 ExecStart=/usr/pgsql-9.4/bin/repmgrd -f ${REPMGRDCONF} -p ${PIDFILE} -d > ${REPMGRDLOG} 2>&1" 
-ExecStop=/usr/bin/kill -TERM ${PIDFILE}
-ExecReload=/usr/bin/kill -HUP ${PIDFILE}
+ExecStop=/usr/bin/kill -TERM $MAINPID
+ExecReload=/usr/bin/kill -HUP $MAINPID
 
 # Give a reasonable amount of time for the server to start up/shut down
 TimeoutSec=300
diff --git a/rpm/redhat/9.4/repmgr/EL-7/repmgr-9.4.service b/rpm/redhat/9.4/repmgr/EL-7/repmgr-9.4.service
index 0a38556..6dd7acb 100644
--- a/rpm/redhat/9.4/repmgr/EL-7/repmgr-9.4.service
+++ b/rpm/redhat/9.4/repmgr/EL-7/repmgr-9.4.service
@@ -15,8 +15,11 @@ After=network.target
 [Service]
 Type=forking
 
-User=repmgr
-Group=repmgr
+# PID file
+PIDFile=/var/run/repmgr/repmgrd-9.4.pid
+
+User=postgres
+Group=postgres
 
 # Location of repmgr conf file:
 Environment=REPMGRDCONF=/etc/repmgr/9.4/repmgr.conf
@@ -27,8 +30,8 @@ Environment=REPMGRDLOG=/var/log/repmgr/repmgrd-9.4.log
 # This is normally controlled by the global default set by systemd
 # StandardOutput=syslog
 ExecStart=/usr/pgsql-9.4/bin/repmgrd -f ${REPMGRDCONF} -p ${PIDFILE} -d > ${REPMGRDLOG} 2>&1" 
-ExecStop=/usr/bin/kill -TERM ${PIDFILE}
-ExecReload=/usr/bin/kill -HUP ${PIDFILE}
+ExecStop=/usr/bin/kill -TERM $MAINPID
+ExecReload=/usr/bin/kill -HUP $MAINPID
 
 # Give a reasonable amount of time for the server to start up/shut down
 TimeoutSec=300
diff --git a/rpm/redhat/9.4/repmgr/F-20/repmgr-9.4.service b/rpm/redhat/9.4/repmgr/F-20/repmgr-9.4.service
index 0a38556..6dd7acb 100644
--- a/rpm/redhat/9.4/repmgr/F-20/repmgr-9.4.service
+++ b/rpm/redhat/9.4/repmgr/F-20/repmgr-9.4.service
@@ -15,8 +15,11 @@ After=network.target
 [Service]
 Type=forking
 
-User=repmgr
-Group=repmgr
+# PID file
+PIDFile=/var/run/repmgr/repmgrd-9.4.pid
+
+User=postgres
+Group=postgres
 
 # Location of repmgr conf file:
 Environment=REPMGRDCONF=/etc/repmgr/9.4/repmgr.conf
@@ -27,8 +30,8 @@ Environment=REPMGRDLOG=/var/log/repmgr/repmgrd-9.4.log
 # This is normally controlled by the global default set by systemd
 # StandardOutput=syslog
 ExecStart=/usr/pgsql-9.4/bin/repmgrd -f ${REPMGRDCONF} -p ${PIDFILE} -d > ${REPMGRDLOG} 2>&1" 
-ExecStop=/usr/bin/kill -TERM ${PIDFILE}
-ExecReload=/usr/bin/kill -HUP ${PIDFILE}
+ExecStop=/usr/bin/kill -TERM $MAINPID
+ExecReload=/usr/bin/kill -HUP $MAINPID
 
 # Give a reasonable amount of time for the server to start up/shut down
 TimeoutSec=300
diff --git a/rpm/redhat/9.4/repmgr/F-21/repmgr-9.4.service b/rpm/redhat/9.4/repmgr/F-21/repmgr-9.4.service
index 0a38556..6dd7acb 100644
--- a/rpm/redhat/9.4/repmgr/F-21/repmgr-9.4.service
+++ b/rpm/redhat/9.4/repmgr/F-21/repmgr-9.4.service
@@ -15,8 +15,11 @@ After=network.target
 [Service]
 Type=forking
 
-User=repmgr
-Group=repmgr
+# PID file
+PIDFile=/var/run/repmgr/repmgrd-9.4.pid
+
+User=postgres
+Group=postgres
 
 # Location of repmgr conf file:
 Environment=REPMGRDCONF=/etc/repmgr/9.4/repmgr.conf
@@ -27,8 +30,8 @@ Environment=REPMGRDLOG=/var/log/repmgr/repmgrd-9.4.log
 # This is normally controlled by the global default set by systemd
 # StandardOutput=syslog
 ExecStart=/usr/pgsql-9.4/bin/repmgrd -f ${REPMGRDCONF} -p ${PIDFILE} -d > ${REPMGRDLOG} 2>&1" 
-ExecStop=/usr/bin/kill -TERM ${PIDFILE}
-ExecReload=/usr/bin/kill -HUP ${PIDFILE}
+ExecStop=/usr/bin/kill -TERM $MAINPID
+ExecReload=/usr/bin/kill -HUP $MAINPID
 
 # Give a reasonable amount of time for the server to start up/shut down
 TimeoutSec=300
diff --git a/rpm/redhat/9.4/repmgr/F-22/repmgr-9.4.service b/rpm/redhat/9.4/repmgr/F-22/repmgr-9.4.service
index 0a38556..6dd7acb 100644
--- a/rpm/redhat/9.4/repmgr/F-22/repmgr-9.4.service
+++ b/rpm/redhat/9.4/repmgr/F-22/repmgr-9.4.service
@@ -15,8 +15,11 @@ After=network.target
 [Service]
 Type=forking
 
-User=repmgr
-Group=repmgr
+# PID file
+PIDFile=/var/run/repmgr/repmgrd-9.4.pid
+
+User=postgres
+Group=postgres
 
 # Location of repmgr conf file:
 Environment=REPMGRDCONF=/etc/repmgr/9.4/repmgr.conf
@@ -27,8 +30,8 @@ Environment=REPMGRDLOG=/var/log/repmgr/repmgrd-9.4.log
 # This is normally controlled by the global default set by systemd
 # StandardOutput=syslog
 ExecStart=/usr/pgsql-9.4/bin/repmgrd -f ${REPMGRDCONF} -p ${PIDFILE} -d > ${REPMGRDLOG} 2>&1" 
-ExecStop=/usr/bin/kill -TERM ${PIDFILE}
-ExecReload=/usr/bin/kill -HUP ${PIDFILE}
+ExecStop=/usr/bin/kill -TERM $MAINPID
+ExecReload=/usr/bin/kill -HUP $MAINPID
 
 # Give a reasonable amount of time for the server to start up/shut down
 TimeoutSec=300
diff --git a/rpm/redhat/9.4/repmgr/F-23/repmgr-9.4.service b/rpm/redhat/9.4/repmgr/F-23/repmgr-9.4.service
index 0a38556..6dd7acb 100644
--- a/rpm/redhat/9.4/repmgr/F-23/repmgr-9.4.service
+++ b/rpm/redhat/9.4/repmgr/F-23/repmgr-9.4.service
@@ -15,8 +15,11 @@ After=network.target
 [Service]
 Type=forking
 
-User=repmgr
-Group=repmgr
+# PID file
+PIDFile=/var/run/repmgr/repmgrd-9.4.pid
+
+User=postgres
+Group=postgres
 
 # Location of repmgr conf file:
 Environment=REPMGRDCONF=/etc/repmgr/9.4/repmgr.conf
@@ -27,8 +30,8 @@ Environment=REPMGRDLOG=/var/log/repmgr/repmgrd-9.4.log
 # This is normally controlled by the global default set by systemd
 # StandardOutput=syslog
 ExecStart=/usr/pgsql-9.4/bin/repmgrd -f ${REPMGRDCONF} -p ${PIDFILE} -d > ${REPMGRDLOG} 2>&1" 
-ExecStop=/usr/bin/kill -TERM ${PIDFILE}
-ExecReload=/usr/bin/kill -HUP ${PIDFILE}
+ExecStop=/usr/bin/kill -TERM $MAINPID
+ExecReload=/usr/bin/kill -HUP $MAINPID
 
 # Give a reasonable amount of time for the server to start up/shut down
 TimeoutSec=300
diff --git a/rpm/redhat/9.5/repmgr/EL-5/repmgr-9.5.service b/rpm/redhat/9.5/repmgr/EL-5/repmgr-9.5.service
index d1d050f..14106c6 100644
--- a/rpm/redhat/9.5/repmgr/EL-5/repmgr-9.5.service
+++ b/rpm/redhat/9.5/repmgr/EL-5/repmgr-9.5.service
@@ -15,6 +15,7 @@ After=network.target
 [Service]
 Type=forking
 
+PIDFile=/var/run/repmgr/repmgrd-9.5.pid
 User=postgres
 Group=postgres
 
@@ -26,9 +27,9 @@ Environment=REPMGRDLOG=/var/log/repmgr/repmgrd-9.5.log
 # Where to send early-startup messages from the server 
 # This is normally controlled by the global default set by systemd
 # StandardOutput=syslog
-ExecStart=/usr/pgsql-9.5/bin/repmgrd -f ${REPMGRDCONF} -p ${PIDFILE} -d > ${REPMGRDLOG} 2>&1
-ExecStop=/usr/bin/kill -TERM ${PIDFILE}
-ExecReload=/usr/bin/kill -HUP ${PIDFILE}
+ExecStart=/usr/pgsql-9.5/bin/repmgrd -f ${REPMGRDCONF} -p ${PIDFILE} -d >> ${REPMGRDLOG} 2>&1
+ExecStop=/usr/bin/kill -TERM $MAINPID
+ExecReload=/usr/bin/kill -HUP $MAINPID
 
 # Give a reasonable amount of time for the server to start up/shut down
 TimeoutSec=300
diff --git a/rpm/redhat/9.5/repmgr/EL-6/repmgr-9.5.service b/rpm/redhat/9.5/repmgr/EL-6/repmgr-9.5.service
index d1d050f..14106c6 100644
--- a/rpm/redhat/9.5/repmgr/EL-6/repmgr-9.5.service
+++ b/rpm/redhat/9.5/repmgr/EL-6/repmgr-9.5.service
@@ -15,6 +15,7 @@ After=network.target
 [Service]
 Type=forking
 
+PIDFile=/var/run/repmgr/repmgrd-9.5.pid
 User=postgres
 Group=postgres
 
@@ -26,9 +27,9 @@ Environment=REPMGRDLOG=/var/log/repmgr/repmgrd-9.5.log
 # Where to send early-startup messages from the server 
 # This is normally controlled by the global default set by systemd
 # StandardOutput=syslog
-ExecStart=/usr/pgsql-9.5/bin/repmgrd -f ${REPMGRDCONF} -p ${PIDFILE} -d > ${REPMGRDLOG} 2>&1
-ExecStop=/usr/bin/kill -TERM ${PIDFILE}
-ExecReload=/usr/bin/kill -HUP ${PIDFILE}
+ExecStart=/usr/pgsql-9.5/bin/repmgrd -f ${REPMGRDCONF} -p ${PIDFILE} -d >> ${REPMGRDLOG} 2>&1
+ExecStop=/usr/bin/kill -TERM $MAINPID
+ExecReload=/usr/bin/kill -HUP $MAINPID
 
 # Give a reasonable amount of time for the server to start up/shut down
 TimeoutSec=300
diff --git a/rpm/redhat/9.5/repmgr/EL-7/repmgr-9.5.service b/rpm/redhat/9.5/repmgr/EL-7/repmgr-9.5.service
index d1d050f..14106c6 100644
--- a/rpm/redhat/9.5/repmgr/EL-7/repmgr-9.5.service
+++ b/rpm/redhat/9.5/repmgr/EL-7/repmgr-9.5.service
@@ -15,6 +15,7 @@ After=network.target
 [Service]
 Type=forking
 
+PIDFile=/var/run/repmgr/repmgrd-9.5.pid
 User=postgres
 Group=postgres
 
@@ -26,9 +27,9 @@ Environment=REPMGRDLOG=/var/log/repmgr/repmgrd-9.5.log
 # Where to send early-startup messages from the server 
 # This is normally controlled by the global default set by systemd
 # StandardOutput=syslog
-ExecStart=/usr/pgsql-9.5/bin/repmgrd -f ${REPMGRDCONF} -p ${PIDFILE} -d > ${REPMGRDLOG} 2>&1
-ExecStop=/usr/bin/kill -TERM ${PIDFILE}
-ExecReload=/usr/bin/kill -HUP ${PIDFILE}
+ExecStart=/usr/pgsql-9.5/bin/repmgrd -f ${REPMGRDCONF} -p ${PIDFILE} -d >> ${REPMGRDLOG} 2>&1
+ExecStop=/usr/bin/kill -TERM $MAINPID
+ExecReload=/usr/bin/kill -HUP $MAINPID
 
 # Give a reasonable amount of time for the server to start up/shut down
 TimeoutSec=300
diff --git a/rpm/redhat/9.5/repmgr/F-20/repmgr-9.5.service b/rpm/redhat/9.5/repmgr/F-20/repmgr-9.5.service
index d1d050f..14106c6 100644
--- a/rpm/redhat/9.5/repmgr/F-20/repmgr-9.5.service
+++ b/rpm/redhat/9.5/repmgr/F-20/repmgr-9.5.service
@@ -15,6 +15,7 @@ After=network.target
 [Service]
 Type=forking
 
+PIDFile=/var/run/repmgr/repmgrd-9.5.pid
 User=postgres
 Group=postgres
 
@@ -26,9 +27,9 @@ Environment=REPMGRDLOG=/var/log/repmgr/repmgrd-9.5.log
 # Where to send early-startup messages from the server 
 # This is normally controlled by the global default set by systemd
 # StandardOutput=syslog
-ExecStart=/usr/pgsql-9.5/bin/repmgrd -f ${REPMGRDCONF} -p ${PIDFILE} -d > ${REPMGRDLOG} 2>&1
-ExecStop=/usr/bin/kill -TERM ${PIDFILE}
-ExecReload=/usr/bin/kill -HUP ${PIDFILE}
+ExecStart=/usr/pgsql-9.5/bin/repmgrd -f ${REPMGRDCONF} -p ${PIDFILE} -d >> ${REPMGRDLOG} 2>&1
+ExecStop=/usr/bin/kill -TERM $MAINPID
+ExecReload=/usr/bin/kill -HUP $MAINPID
 
 # Give a reasonable amount of time for the server to start up/shut down
 TimeoutSec=300
diff --git a/rpm/redhat/9.5/repmgr/F-21/repmgr-9.5.service b/rpm/redhat/9.5/repmgr/F-21/repmgr-9.5.service
index d1d050f..14106c6 100644
--- a/rpm/redhat/9.5/repmgr/F-21/repmgr-9.5.service
+++ b/rpm/redhat/9.5/repmgr/F-21/repmgr-9.5.service
@@ -15,6 +15,7 @@ After=network.target
 [Service]
 Type=forking
 
+PIDFile=/var/run/repmgr/repmgrd-9.5.pid
 User=postgres
 Group=postgres
 
@@ -26,9 +27,9 @@ Environment=REPMGRDLOG=/var/log/repmgr/repmgrd-9.5.log
 # Where to send early-startup messages from the server 
 # This is normally controlled by the global default set by systemd
 # StandardOutput=syslog
-ExecStart=/usr/pgsql-9.5/bin/repmgrd -f ${REPMGRDCONF} -p ${PIDFILE} -d > ${REPMGRDLOG} 2>&1
-ExecStop=/usr/bin/kill -TERM ${PIDFILE}
-ExecReload=/usr/bin/kill -HUP ${PIDFILE}
+ExecStart=/usr/pgsql-9.5/bin/repmgrd -f ${REPMGRDCONF} -p ${PIDFILE} -d >> ${REPMGRDLOG} 2>&1
+ExecStop=/usr/bin/kill -TERM $MAINPID
+ExecReload=/usr/bin/kill -HUP $MAINPID
 
 # Give a reasonable amount of time for the server to start up/shut down
 TimeoutSec=300
diff --git a/rpm/redhat/9.5/repmgr/F-22/repmgr-9.5.service b/rpm/redhat/9.5/repmgr/F-22/repmgr-9.5.service
index d1d050f..14106c6 100644
--- a/rpm/redhat/9.5/repmgr/F-22/repmgr-9.5.service
+++ b/rpm/redhat/9.5/repmgr/F-22/repmgr-9.5.service
@@ -15,6 +15,7 @@ After=network.target
 [Service]
 Type=forking
 
+PIDFile=/var/run/repmgr/repmgrd-9.5.pid
 User=postgres
 Group=postgres
 
@@ -26,9 +27,9 @@ Environment=REPMGRDLOG=/var/log/repmgr/repmgrd-9.5.log
 # Where to send early-startup messages from the server 
 # This is normally controlled by the global default set by systemd
 # StandardOutput=syslog
-ExecStart=/usr/pgsql-9.5/bin/repmgrd -f ${REPMGRDCONF} -p ${PIDFILE} -d > ${REPMGRDLOG} 2>&1
-ExecStop=/usr/bin/kill -TERM ${PIDFILE}
-ExecReload=/usr/bin/kill -HUP ${PIDFILE}
+ExecStart=/usr/pgsql-9.5/bin/repmgrd -f ${REPMGRDCONF} -p ${PIDFILE} -d >> ${REPMGRDLOG} 2>&1
+ExecStop=/usr/bin/kill -TERM $MAINPID
+ExecReload=/usr/bin/kill -HUP $MAINPID
 
 # Give a reasonable amount of time for the server to start up/shut down
 TimeoutSec=300
diff --git a/rpm/redhat/9.5/repmgr/F-23/repmgr-9.5.service b/rpm/redhat/9.5/repmgr/F-23/repmgr-9.5.service
index d1d050f..14106c6 100644
--- a/rpm/redhat/9.5/repmgr/F-23/repmgr-9.5.service
+++ b/rpm/redhat/9.5/repmgr/F-23/repmgr-9.5.service
@@ -15,6 +15,7 @@ After=network.target
 [Service]
 Type=forking
 
+PIDFile=/var/run/repmgr/repmgrd-9.5.pid
 User=postgres
 Group=postgres
 
@@ -26,9 +27,9 @@ Environment=REPMGRDLOG=/var/log/repmgr/repmgrd-9.5.log
 # Where to send early-startup messages from the server 
 # This is normally controlled by the global default set by systemd
 # StandardOutput=syslog
-ExecStart=/usr/pgsql-9.5/bin/repmgrd -f ${REPMGRDCONF} -p ${PIDFILE} -d > ${REPMGRDLOG} 2>&1
-ExecStop=/usr/bin/kill -TERM ${PIDFILE}
-ExecReload=/usr/bin/kill -HUP ${PIDFILE}
+ExecStart=/usr/pgsql-9.5/bin/repmgrd -f ${REPMGRDCONF} -p ${PIDFILE} -d >> ${REPMGRDLOG} 2>&1
+ExecStop=/usr/bin/kill -TERM $MAINPID
+ExecReload=/usr/bin/kill -HUP $MAINPID
 
 # Give a reasonable amount of time for the server to start up/shut down
 TimeoutSec=300
-- 
2.5.0

