Subject: repmgr.service

From: Justin King <[email-masked]>
Date: Fri, 13 Nov 2015 20:59:27 -0500

Please modify the repmgr-9.x.service files for the packages.

The service files currently have:

ExecStop=/usr/bin/kill -TERM ${PIDFILE}
> ExecReload=/usr/bin/kill -HUP ${PIDFILE}

/bin/kill does not accept files, you may be thinking of /bin/pkill -f

Replace them with:

ExecStop=/usr/bin/kill -TERM $MAINPID
> ExecReload=/usr/bin/kill -HUP $MAINPID

$MAINPID is a special systemd provided variable that references the known
PID of the process

And add the following under the [Service] section:

PIDFile=/var/run/repmgr/repmgrd-9.x.pid

This prevents systemd from guessing what the PID is and being wrong when
Type=forking

As it stands now `systemctl stop repmgrd` and `systemctl reload repmgrd`
will always fail.

Justin

---

From: Martín Marqués <[email-masked]>
Date: Thu, 17 Dec 2015 17:25:13 -0300

Hi,

I see this hasn't been committed yet into the pgrpms git repo.

Is it under review? If so I can say the changes are good, and if needed
I can send over a patch for easy applying.

Regards,

El 13/11/15 a las 22:59, Justin King escribió:
> $MAINPID is a special systemd provided variable that references the
> known PID of the process 
> 

-- 
Martín Marqués                http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

-- 
Sent via pgsql-pkg-yum mailing list ([email-masked])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-pkg-yum

---

From: Jeff Frost <[email-masked]>
Date: Tue, 22 Dec 2015 18:52:42 -0800

Sorry for the slow reply on this.

We did make some changes recently, but it seems this was not one of them.

A patch would definitely speed us up and would be most welcome!

> On Dec 17, 2015, at 12:25 PM, Martín Marqués <[email-masked]> wrote:
> 
> Hi,
> 

---
Jeff Frost <[email-masked]>
Director, PostgreSQL Experts, Inc.
Phone: 1-888-PG-EXPRT x506
FAX: 415-762-5122
http://www.pgexperts.com/

---

From: Martín Marqués <[email-masked]>
Date: Wed, 30 Dec 2015 15:09:32 -0300

> A patch would definitely speed us up and would be most welcome!

I'm working on a patch against the pgrpms repo and I see that there are
systemd service files for EL-5.

For example, check ./9.4/repmgr/EL-5/repmgr-9.4.service

Any reason for that?

---

From: Devrim Gündüz <[email-masked]>
Date: Wed, 30 Dec 2015 20:18:32 +0200

Hi,

Recent spec file is a unified one, which can be used on both old and new distros -- so to keep branches the same, I committed same files to each distro.

Regards, Devrim

-- 
Sent from my Android device with K-9 Mail. Please excuse my brevity.

---

From: Martín Marqués <[email-masked]>
Date: Wed, 30 Dec 2015 15:50:20 -0300

Hi Devrim,

2015-12-30 15:18 GMT-03:00 Devrim Gündüz <[email-masked]>:
> Hi,
>
> Recent spec file is a unified one, which can be used on both old and new
> distros -- so to keep branches the same, I committed same files to each
> distro.

Yes, I've seen the spec, but didn't realize there would be useless files around.

BTW, why not unify everything in one directory for all distros and
versions? It would make it much easier to maintain, and especially to
patch (like what I'm doing now)

Regards,

---

From: Devrim Gündüz <[email-masked]>
Date: Wed, 30 Dec 2015 21:25:20 +0200

Hi,

That makes the build process easier. We have separate VMs for each combination.  When we use separate dirs, we can build packages with a single command.

I inherited this from Fedora's build system, btw.

Regards, Devrim

---

From: Martín Marqués <[email-masked]>
Date: Wed, 30 Dec 2015 17:34:16 -0300

El 30/12/15 a las 16:25, Devrim Gündüz escribió:
> Hi,
> 
> That makes the build process easier. We have separate VMs for each
> combination. When we use separate dirs, we can build packages with a
> single command.

I still don't understand why separate dirs would have anything to do.

If you have one spec and one dir with everything needed for any distro,
you can just use the same directory and same spec for any build.

BTW, I'm sending a patch for the systemd bug in a separate mail any time
soon.

I have a few other patches (for the init script and for the spec file).
I'll send those later or next week.

---

From: Martín Marqués <[email-masked]>
Date: Wed, 30 Dec 2015 17:40:52 -0300

> A patch would definitely speed us up and would be most welcome!

Promised patch. Let me know if there's something to fix.

Regards,

>From a5eeaf156cdf1224dd50058238665b0177af0293 Mon Sep 17 00:00:00 2001
From: Martin <[email-masked]>
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

---

From: Martín Marqués <[email-masked]>
Date: Wed, 30 Dec 2015 18:27:27 -0300

> A patch would definitely speed us up and would be most welcome!

This is another patch I had pending for a long time which adds some
improvements to the old sysV init scripts.

I'll try to roll the spec file patch.

>From e4d4b1695c0e04610edde5767a23bdd014b80066 Mon Sep 17 00:00:00 2001
From: Martin <[email-masked]>
Date: Wed, 30 Dec 2015 18:22:27 -0300
Subject: [PATCH] Improvements to sysV init script and the use of s sysconfig
 file for extra options the DBA might want to use.

---
 rpm/redhat/9.0/repmgr/EL-5/repmgr.init       | 45 +++++++++++++++++++++++-----
 rpm/redhat/9.0/repmgr/EL-5/repmgrd.sysconfig | 24 +++++++++++++++
 rpm/redhat/9.0/repmgr/EL-6/repmgr.init       | 45 +++++++++++++++++++++++-----
 rpm/redhat/9.0/repmgr/EL-6/repmgrd.sysconfig | 24 +++++++++++++++
 rpm/redhat/9.1/repmgr/EL-5/repmgr.init       | 45 +++++++++++++++++++++++-----
 rpm/redhat/9.1/repmgr/EL-5/repmgrd.sysconfig | 24 +++++++++++++++
 rpm/redhat/9.1/repmgr/EL-6/repmgr.init       | 45 +++++++++++++++++++++++-----
 rpm/redhat/9.1/repmgr/EL-6/repmgrd.sysconfig | 24 +++++++++++++++
 rpm/redhat/9.2/repmgr/EL-5/repmgr.init       | 45 +++++++++++++++++++++++-----
 rpm/redhat/9.2/repmgr/EL-5/repmgrd.sysconfig | 24 +++++++++++++++
 rpm/redhat/9.2/repmgr/EL-6/repmgr.init       | 45 +++++++++++++++++++++++-----
 rpm/redhat/9.2/repmgr/EL-6/repmgrd.sysconfig | 24 +++++++++++++++
 rpm/redhat/9.2/repmgr/EL-7/repmgr.init       | 45 +++++++++++++++++++++++-----
 rpm/redhat/9.2/repmgr/EL-7/repmgrd.sysconfig | 24 +++++++++++++++
 rpm/redhat/9.2/repmgr/F-19/repmgr.init       | 45 +++++++++++++++++++++++-----
 rpm/redhat/9.2/repmgr/F-19/repmgrd.sysconfig | 24 +++++++++++++++
 rpm/redhat/9.3/repmgr/EL-5/repmgr.init       | 45 +++++++++++++++++++++++-----
 rpm/redhat/9.3/repmgr/EL-5/repmgrd.sysconfig | 24 +++++++++++++++
 rpm/redhat/9.3/repmgr/EL-6/repmgr.init       | 45 +++++++++++++++++++++++-----
 rpm/redhat/9.3/repmgr/EL-6/repmgrd.sysconfig | 24 +++++++++++++++
 rpm/redhat/9.3/repmgr/EL-7/repmgr.init       | 45 +++++++++++++++++++++++-----
 rpm/redhat/9.3/repmgr/EL-7/repmgrd.sysconfig | 24 +++++++++++++++
 rpm/redhat/9.3/repmgr/F-19/repmgr.init       | 45 +++++++++++++++++++++++-----
 rpm/redhat/9.3/repmgr/F-19/repmgrd.sysconfig | 24 +++++++++++++++
 rpm/redhat/9.3/repmgr/F-20/repmgr.init       | 45 +++++++++++++++++++++++-----
 rpm/redhat/9.3/repmgr/F-20/repmgrd.sysconfig | 24 +++++++++++++++
 rpm/redhat/9.3/repmgr/F-21/repmgr.init       | 45 +++++++++++++++++++++++-----
 rpm/redhat/9.3/repmgr/F-21/repmgrd.sysconfig | 24 +++++++++++++++
 rpm/redhat/9.3/repmgr/F-22/repmgr.init       | 45 +++++++++++++++++++++++-----
 rpm/redhat/9.3/repmgr/F-22/repmgrd.sysconfig | 24 +++++++++++++++
 rpm/redhat/9.3/repmgr/F-23/repmgr.init       | 45 +++++++++++++++++++++++-----
 rpm/redhat/9.3/repmgr/F-23/repmgrd.sysconfig | 24 +++++++++++++++
 rpm/redhat/9.4/repmgr/EL-5/repmgr.init       | 45 +++++++++++++++++++++++-----
 rpm/redhat/9.4/repmgr/EL-6/repmgr.init       | 45 +++++++++++++++++++++++-----
 rpm/redhat/9.4/repmgr/EL-6/repmgrd.sysconfig | 24 +++++++++++++++
 rpm/redhat/9.4/repmgr/EL-7/repmgr.init       | 45 +++++++++++++++++++++++-----
 rpm/redhat/9.4/repmgr/F-20/repmgr.init       | 45 +++++++++++++++++++++++-----
 rpm/redhat/9.4/repmgr/F-21/repmgr.init       | 45 +++++++++++++++++++++++-----
 rpm/redhat/9.4/repmgr/F-22/repmgr.init       | 45 +++++++++++++++++++++++-----
 rpm/redhat/9.4/repmgr/F-23/repmgr.init       | 45 +++++++++++++++++++++++-----
 rpm/redhat/9.5/repmgr/EL-5/repmgr.init       | 45 +++++++++++++++++++++++-----
 rpm/redhat/9.5/repmgr/EL-5/repmgrd.sysconfig | 24 +++++++++++++++
 rpm/redhat/9.5/repmgr/EL-6/repmgr.init       | 45 +++++++++++++++++++++++-----
 rpm/redhat/9.5/repmgr/EL-6/repmgrd.sysconfig | 24 +++++++++++++++
 rpm/redhat/9.5/repmgr/EL-7/repmgr.init       | 45 +++++++++++++++++++++++-----
 rpm/redhat/9.5/repmgr/EL-7/repmgrd.sysconfig | 24 +++++++++++++++
 rpm/redhat/9.5/repmgr/F-20/repmgr.init       | 45 +++++++++++++++++++++++-----
 rpm/redhat/9.5/repmgr/F-20/repmgrd.sysconfig | 24 +++++++++++++++
 rpm/redhat/9.5/repmgr/F-21/repmgr.init       | 45 +++++++++++++++++++++++-----
 rpm/redhat/9.5/repmgr/F-21/repmgrd.sysconfig | 24 +++++++++++++++
 rpm/redhat/9.5/repmgr/F-22/repmgr.init       | 45 +++++++++++++++++++++++-----
 rpm/redhat/9.5/repmgr/F-22/repmgrd.sysconfig | 24 +++++++++++++++
 rpm/redhat/9.5/repmgr/F-23/repmgr.init       | 45 +++++++++++++++++++++++-----
 rpm/redhat/9.5/repmgr/F-23/repmgrd.sysconfig | 24 +++++++++++++++
 54 files changed, 1716 insertions(+), 210 deletions(-)
 create mode 100644 rpm/redhat/9.0/repmgr/EL-5/repmgrd.sysconfig
 create mode 100644 rpm/redhat/9.0/repmgr/EL-6/repmgrd.sysconfig
 create mode 100644 rpm/redhat/9.1/repmgr/EL-5/repmgrd.sysconfig
 create mode 100644 rpm/redhat/9.1/repmgr/EL-6/repmgrd.sysconfig
 create mode 100644 rpm/redhat/9.2/repmgr/EL-5/repmgrd.sysconfig
 create mode 100644 rpm/redhat/9.2/repmgr/EL-6/repmgrd.sysconfig
 create mode 100644 rpm/redhat/9.2/repmgr/EL-7/repmgrd.sysconfig
 create mode 100644 rpm/redhat/9.2/repmgr/F-19/repmgrd.sysconfig
 create mode 100644 rpm/redhat/9.3/repmgr/EL-5/repmgrd.sysconfig
 create mode 100644 rpm/redhat/9.3/repmgr/EL-6/repmgrd.sysconfig
 create mode 100644 rpm/redhat/9.3/repmgr/EL-7/repmgrd.sysconfig
 create mode 100644 rpm/redhat/9.3/repmgr/F-19/repmgrd.sysconfig
 create mode 100644 rpm/redhat/9.3/repmgr/F-20/repmgrd.sysconfig
 create mode 100644 rpm/redhat/9.3/repmgr/F-21/repmgrd.sysconfig
 create mode 100644 rpm/redhat/9.3/repmgr/F-22/repmgrd.sysconfig
 create mode 100644 rpm/redhat/9.3/repmgr/F-23/repmgrd.sysconfig
 create mode 100644 rpm/redhat/9.4/repmgr/EL-6/repmgrd.sysconfig
 create mode 100644 rpm/redhat/9.5/repmgr/EL-5/repmgrd.sysconfig
 create mode 100644 rpm/redhat/9.5/repmgr/EL-6/repmgrd.sysconfig
 create mode 100644 rpm/redhat/9.5/repmgr/EL-7/repmgrd.sysconfig
 create mode 100644 rpm/redhat/9.5/repmgr/F-20/repmgrd.sysconfig
 create mode 100644 rpm/redhat/9.5/repmgr/F-21/repmgrd.sysconfig
 create mode 100644 rpm/redhat/9.5/repmgr/F-22/repmgrd.sysconfig
 create mode 100644 rpm/redhat/9.5/repmgr/F-23/repmgrd.sysconfig

diff --git a/rpm/redhat/9.0/repmgr/EL-5/repmgr.init b/rpm/redhat/9.0/repmgr/EL-5/repmgr.init
index e00089b..5b5bc6f 100644
--- a/rpm/redhat/9.0/repmgr/EL-5/repmgr.init
+++ b/rpm/redhat/9.0/repmgr/EL-5/repmgr.init
@@ -29,32 +29,63 @@ user=repmgr
 prog=repmgrd
 pidfile=/var/run/repmgr/repmgrd-9.0.pid
 lockfile=/var/lock/subsys/$prog
+REPMGRD_ENABLED=no
+REPMGRD_OPTS=
 REPMGRDCONF=/etc/repmgr/9.0/repmgr.conf
 REPMGRDLOG=/var/log/repmgr/repmgrd-9.0.log
 
 # Get config.
 . /etc/sysconfig/network
 
+# Read configuration variable file if it is present
+[ -r /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
+
+# For SELinux we need to use 'runuser' not 'su'
+if [ -x /sbin/runuser ]
+then
+    SU=runuser
+else
+    SU=su
+fi
+
+test -x $exec || exit 0
+
+case "$REPMGRD_ENABLED" in
+    [Yy]*)
+	break
+	;;
+    *)
+	exit 0
+	;;
+esac
+
+if [ -z "${REPMGRD_OPTS}" ]
+then
+    echo "Not starting ${prog}, REPMGRD_OPTS not set in /etc/sysconfig/${prog}"
+    exit 0
+fi
+
 # Check that networking is up.
 [ "${NETWORKING}" = "no" ] && exit 6
 start(){
         [ -x $exec ] || exit 5
-        [ -f "$REPMGRDCONF" ] || exit 6
+        [ -f "${REPMGRDCONF}" ] || exit 6
         echo -n "Starting $prog: "
 
         # Make sure startup-time log file is valid
-        if [ ! -e "$REPMGRDLOG" -a ! -h "$REPMGRDLOG" ]
+        if [ ! -e "${REPMGRDLOG}" -a ! -h "${REPMGRDLOG}" ]
         then
-                touch "$REPMGRDLOG" || exit 1
-                chown $user: "$REPMGRDLOG"
-                chmod go-rwx "$REPMGRDLOG"
-                [ -x /usr/bin/chcon ] && /usr/bin/chcon -u system_u -r object_r -t postgresql_log_t "$REPMGRDLOG" 2>/dev/null
+                touch "${REPMGRDLOG}" || exit 1
+                chown $user: "${REPMGRDLOG}"
+                chmod go-rwx "${REPMGRDLOG}"
+                [ -x /usr/bin/chcon ] && /usr/bin/chcon -u system_u -r object_r -t postgresql_log_t "${REPMGRDLOG}" 2>/dev/null
         fi
 
         mkdir -p $(dirname $pidfile)
         chown $user: $(dirname $pidfile)
 
-	su -l repmgr -c "$exec -f $REPMGRDCONF -p $pidfile -d ->> $REPMGRDLOG 2>&1" $user # --monitoring-history --verbose
+	${SU} -l -c "${exec} -f ${REPMGR_CONF} ${REPMGRD_OPTS} -p ${pidfile} >> ${REPMGRDLOG} 2>&1" ${user} < /dev/null
+	sleep 2
         retval=$?
 	[ $retval -eq 0 ] && success 
         echo
diff --git a/rpm/redhat/9.0/repmgr/EL-5/repmgrd.sysconfig b/rpm/redhat/9.0/repmgr/EL-5/repmgrd.sysconfig
new file mode 100644
index 0000000..e9c5aa9
--- /dev/null
+++ b/rpm/redhat/9.0/repmgr/EL-5/repmgrd.sysconfig
@@ -0,0 +1,24 @@
+# default settings for repmgrd. This file is source by /bin/sh from
+# /etc/init.d/repmgrd
+
+# disable repmgrd by default so it won't get started upon installation
+# valid values: yes/no
+REPMGRD_ENABLED=no
+
+# Repmgr conf file
+REPMGR_CONF=/var/lib/pgsql/repmgr/repmgr.conf
+
+# Options for repmgrd (required)
+#REPMGRD_OPTS="--verbose -d "
+
+# User to run repmgrd as
+#REPMGRD_USER=postgres
+
+# repmgrd binary
+#REPMGRD_BIN=/usr/bin/repmgrd
+
+# pid file
+#REPMGRD_PIDFILE=/var/lib/pgsql/repmgr/repmgrd.pid
+
+# log file
+#REPMGRD_LOG=/var/lib/pgsql/repmgr/repmgrd.log
diff --git a/rpm/redhat/9.0/repmgr/EL-6/repmgr.init b/rpm/redhat/9.0/repmgr/EL-6/repmgr.init
index e00089b..5b5bc6f 100644
--- a/rpm/redhat/9.0/repmgr/EL-6/repmgr.init
+++ b/rpm/redhat/9.0/repmgr/EL-6/repmgr.init
@@ -29,32 +29,63 @@ user=repmgr
 prog=repmgrd
 pidfile=/var/run/repmgr/repmgrd-9.0.pid
 lockfile=/var/lock/subsys/$prog
+REPMGRD_ENABLED=no
+REPMGRD_OPTS=
 REPMGRDCONF=/etc/repmgr/9.0/repmgr.conf
 REPMGRDLOG=/var/log/repmgr/repmgrd-9.0.log
 
 # Get config.
 . /etc/sysconfig/network
 
+# Read configuration variable file if it is present
+[ -r /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
+
+# For SELinux we need to use 'runuser' not 'su'
+if [ -x /sbin/runuser ]
+then
+    SU=runuser
+else
+    SU=su
+fi
+
+test -x $exec || exit 0
+
+case "$REPMGRD_ENABLED" in
+    [Yy]*)
+	break
+	;;
+    *)
+	exit 0
+	;;
+esac
+
+if [ -z "${REPMGRD_OPTS}" ]
+then
+    echo "Not starting ${prog}, REPMGRD_OPTS not set in /etc/sysconfig/${prog}"
+    exit 0
+fi
+
 # Check that networking is up.
 [ "${NETWORKING}" = "no" ] && exit 6
 start(){
         [ -x $exec ] || exit 5
-        [ -f "$REPMGRDCONF" ] || exit 6
+        [ -f "${REPMGRDCONF}" ] || exit 6
         echo -n "Starting $prog: "
 
         # Make sure startup-time log file is valid
-        if [ ! -e "$REPMGRDLOG" -a ! -h "$REPMGRDLOG" ]
+        if [ ! -e "${REPMGRDLOG}" -a ! -h "${REPMGRDLOG}" ]
         then
-                touch "$REPMGRDLOG" || exit 1
-                chown $user: "$REPMGRDLOG"
-                chmod go-rwx "$REPMGRDLOG"
-                [ -x /usr/bin/chcon ] && /usr/bin/chcon -u system_u -r object_r -t postgresql_log_t "$REPMGRDLOG" 2>/dev/null
+                touch "${REPMGRDLOG}" || exit 1
+                chown $user: "${REPMGRDLOG}"
+                chmod go-rwx "${REPMGRDLOG}"
+                [ -x /usr/bin/chcon ] && /usr/bin/chcon -u system_u -r object_r -t postgresql_log_t "${REPMGRDLOG}" 2>/dev/null
         fi
 
         mkdir -p $(dirname $pidfile)
         chown $user: $(dirname $pidfile)
 
-	su -l repmgr -c "$exec -f $REPMGRDCONF -p $pidfile -d ->> $REPMGRDLOG 2>&1" $user # --monitoring-history --verbose
+	${SU} -l -c "${exec} -f ${REPMGR_CONF} ${REPMGRD_OPTS} -p ${pidfile} >> ${REPMGRDLOG} 2>&1" ${user} < /dev/null
+	sleep 2
         retval=$?
 	[ $retval -eq 0 ] && success 
         echo
diff --git a/rpm/redhat/9.0/repmgr/EL-6/repmgrd.sysconfig b/rpm/redhat/9.0/repmgr/EL-6/repmgrd.sysconfig
new file mode 100644
index 0000000..e9c5aa9
--- /dev/null
+++ b/rpm/redhat/9.0/repmgr/EL-6/repmgrd.sysconfig
@@ -0,0 +1,24 @@
+# default settings for repmgrd. This file is source by /bin/sh from
+# /etc/init.d/repmgrd
+
+# disable repmgrd by default so it won't get started upon installation
+# valid values: yes/no
+REPMGRD_ENABLED=no
+
+# Repmgr conf file
+REPMGR_CONF=/var/lib/pgsql/repmgr/repmgr.conf
+
+# Options for repmgrd (required)
+#REPMGRD_OPTS="--verbose -d "
+
+# User to run repmgrd as
+#REPMGRD_USER=postgres
+
+# repmgrd binary
+#REPMGRD_BIN=/usr/bin/repmgrd
+
+# pid file
+#REPMGRD_PIDFILE=/var/lib/pgsql/repmgr/repmgrd.pid
+
+# log file
+#REPMGRD_LOG=/var/lib/pgsql/repmgr/repmgrd.log
diff --git a/rpm/redhat/9.1/repmgr/EL-5/repmgr.init b/rpm/redhat/9.1/repmgr/EL-5/repmgr.init
index c7c16ac..3e72255 100644
--- a/rpm/redhat/9.1/repmgr/EL-5/repmgr.init
+++ b/rpm/redhat/9.1/repmgr/EL-5/repmgr.init
@@ -29,32 +29,63 @@ user=repmgr
 prog=repmgrd
 pidfile=/var/run/repmgr/repmgrd-9.1.pid
 lockfile=/var/lock/subsys/$prog
+REPMGRD_ENABLED=no
+REPMGRD_OPTS=
 REPMGRDCONF=/etc/repmgr/9.1/repmgr.conf
 REPMGRDLOG=/var/log/repmgr/repmgrd-9.1.log
 
 # Get config.
 . /etc/sysconfig/network
 
+# Read configuration variable file if it is present
+[ -r /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
+
+# For SELinux we need to use 'runuser' not 'su'
+if [ -x /sbin/runuser ]
+then
+    SU=runuser
+else
+    SU=su
+fi
+
+test -x $exec || exit 0
+
+case "$REPMGRD_ENABLED" in
+    [Yy]*)
+	break
+	;;
+    *)
+	exit 0
+	;;
+esac
+
+if [ -z "${REPMGRD_OPTS}" ]
+then
+    echo "Not starting ${prog}, REPMGRD_OPTS not set in /etc/sysconfig/${prog}"
+    exit 0
+fi
+
 # Check that networking is up.
 [ "${NETWORKING}" = "no" ] && exit 6
 start(){
         [ -x $exec ] || exit 5
-        [ -f "$REPMGRDCONF" ] || exit 6
+        [ -f "${REPMGRDCONF}" ] || exit 6
         echo -n "Starting $prog: "
 
         # Make sure startup-time log file is valid
-        if [ ! -e "$REPMGRDLOG" -a ! -h "$REPMGRDLOG" ]
+        if [ ! -e "${REPMGRDLOG}" -a ! -h "${REPMGRDLOG}" ]
         then
-                touch "$REPMGRDLOG" || exit 1
-                chown $user: "$REPMGRDLOG"
-                chmod go-rwx "$REPMGRDLOG"
-                [ -x /usr/bin/chcon ] && /usr/bin/chcon -u system_u -r object_r -t postgresql_log_t "$REPMGRDLOG" 2>/dev/null
+                touch "${REPMGRDLOG}" || exit 1
+                chown $user: "${REPMGRDLOG}"
+                chmod go-rwx "${REPMGRDLOG}"
+                [ -x /usr/bin/chcon ] && /usr/bin/chcon -u system_u -r object_r -t postgresql_log_t "${REPMGRDLOG}" 2>/dev/null
         fi
 
         mkdir -p $(dirname $pidfile)
         chown $user: $(dirname $pidfile)
 
-	su -l repmgr -c "$exec -f $REPMGRDCONF -p $pidfile -d ->> $REPMGRDLOG 2>&1" $user # --monitoring-history --verbose
+	${SU} -l -c "${exec} -f ${REPMGR_CONF} ${REPMGRD_OPTS} -p ${pidfile} >> ${REPMGRDLOG} 2>&1" ${user} < /dev/null
+	sleep 2
         retval=$?
 	[ $retval -eq 0 ] && success 
         echo
diff --git a/rpm/redhat/9.1/repmgr/EL-5/repmgrd.sysconfig b/rpm/redhat/9.1/repmgr/EL-5/repmgrd.sysconfig
new file mode 100644
index 0000000..e9c5aa9
--- /dev/null
+++ b/rpm/redhat/9.1/repmgr/EL-5/repmgrd.sysconfig
@@ -0,0 +1,24 @@
+# default settings for repmgrd. This file is source by /bin/sh from
+# /etc/init.d/repmgrd
+
+# disable repmgrd by default so it won't get started upon installation
+# valid values: yes/no
+REPMGRD_ENABLED=no
+
+# Repmgr conf file
+REPMGR_CONF=/var/lib/pgsql/repmgr/repmgr.conf
+
+# Options for repmgrd (required)
+#REPMGRD_OPTS="--verbose -d "
+
+# User to run repmgrd as
+#REPMGRD_USER=postgres
+
+# repmgrd binary
+#REPMGRD_BIN=/usr/bin/repmgrd
+
+# pid file
+#REPMGRD_PIDFILE=/var/lib/pgsql/repmgr/repmgrd.pid
+
+# log file
+#REPMGRD_LOG=/var/lib/pgsql/repmgr/repmgrd.log
diff --git a/rpm/redhat/9.1/repmgr/EL-6/repmgr.init b/rpm/redhat/9.1/repmgr/EL-6/repmgr.init
index c7c16ac..3e72255 100644
--- a/rpm/redhat/9.1/repmgr/EL-6/repmgr.init
+++ b/rpm/redhat/9.1/repmgr/EL-6/repmgr.init
@@ -29,32 +29,63 @@ user=repmgr
 prog=repmgrd
 pidfile=/var/run/repmgr/repmgrd-9.1.pid
 lockfile=/var/lock/subsys/$prog
+REPMGRD_ENABLED=no
+REPMGRD_OPTS=
 REPMGRDCONF=/etc/repmgr/9.1/repmgr.conf
 REPMGRDLOG=/var/log/repmgr/repmgrd-9.1.log
 
 # Get config.
 . /etc/sysconfig/network
 
+# Read configuration variable file if it is present
+[ -r /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
+
+# For SELinux we need to use 'runuser' not 'su'
+if [ -x /sbin/runuser ]
+then
+    SU=runuser
+else
+    SU=su
+fi
+
+test -x $exec || exit 0
+
+case "$REPMGRD_ENABLED" in
+    [Yy]*)
+	break
+	;;
+    *)
+	exit 0
+	;;
+esac
+
+if [ -z "${REPMGRD_OPTS}" ]
+then
+    echo "Not starting ${prog}, REPMGRD_OPTS not set in /etc/sysconfig/${prog}"
+    exit 0
+fi
+
 # Check that networking is up.
 [ "${NETWORKING}" = "no" ] && exit 6
 start(){
         [ -x $exec ] || exit 5
-        [ -f "$REPMGRDCONF" ] || exit 6
+        [ -f "${REPMGRDCONF}" ] || exit 6
         echo -n "Starting $prog: "
 
         # Make sure startup-time log file is valid
-        if [ ! -e "$REPMGRDLOG" -a ! -h "$REPMGRDLOG" ]
+        if [ ! -e "${REPMGRDLOG}" -a ! -h "${REPMGRDLOG}" ]
         then
-                touch "$REPMGRDLOG" || exit 1
-                chown $user: "$REPMGRDLOG"
-                chmod go-rwx "$REPMGRDLOG"
-                [ -x /usr/bin/chcon ] && /usr/bin/chcon -u system_u -r object_r -t postgresql_log_t "$REPMGRDLOG" 2>/dev/null
+                touch "${REPMGRDLOG}" || exit 1
+                chown $user: "${REPMGRDLOG}"
+                chmod go-rwx "${REPMGRDLOG}"
+                [ -x /usr/bin/chcon ] && /usr/bin/chcon -u system_u -r object_r -t postgresql_log_t "${REPMGRDLOG}" 2>/dev/null
         fi
 
         mkdir -p $(dirname $pidfile)
         chown $user: $(dirname $pidfile)
 
-	su -l repmgr -c "$exec -f $REPMGRDCONF -p $pidfile -d ->> $REPMGRDLOG 2>&1" $user # --monitoring-history --verbose
+	${SU} -l -c "${exec} -f ${REPMGR_CONF} ${REPMGRD_OPTS} -p ${pidfile} >> ${REPMGRDLOG} 2>&1" ${user} < /dev/null
+	sleep 2
         retval=$?
 	[ $retval -eq 0 ] && success 
         echo
diff --git a/rpm/redhat/9.1/repmgr/EL-6/repmgrd.sysconfig b/rpm/redhat/9.1/repmgr/EL-6/repmgrd.sysconfig
new file mode 100644
index 0000000..e9c5aa9
--- /dev/null
+++ b/rpm/redhat/9.1/repmgr/EL-6/repmgrd.sysconfig
@@ -0,0 +1,24 @@
+# default settings for repmgrd. This file is source by /bin/sh from
+# /etc/init.d/repmgrd
+
+# disable repmgrd by default so it won't get started upon installation
+# valid values: yes/no
+REPMGRD_ENABLED=no
+
+# Repmgr conf file
+REPMGR_CONF=/var/lib/pgsql/repmgr/repmgr.conf
+
+# Options for repmgrd (required)
+#REPMGRD_OPTS="--verbose -d "
+
+# User to run repmgrd as
+#REPMGRD_USER=postgres
+
+# repmgrd binary
+#REPMGRD_BIN=/usr/bin/repmgrd
+
+# pid file
+#REPMGRD_PIDFILE=/var/lib/pgsql/repmgr/repmgrd.pid
+
+# log file
+#REPMGRD_LOG=/var/lib/pgsql/repmgr/repmgrd.log
diff --git a/rpm/redhat/9.2/repmgr/EL-5/repmgr.init b/rpm/redhat/9.2/repmgr/EL-5/repmgr.init
index 91a89ef..7a8463e 100644
--- a/rpm/redhat/9.2/repmgr/EL-5/repmgr.init
+++ b/rpm/redhat/9.2/repmgr/EL-5/repmgr.init
@@ -29,32 +29,63 @@ user=repmgr
 prog=repmgrd
 pidfile=/var/run/repmgr/repmgrd-9.2.pid
 lockfile=/var/lock/subsys/$prog
+REPMGRD_ENABLED=no
+REPMGRD_OPTS=
 REPMGRDCONF=/etc/repmgr/9.2/repmgr.conf
 REPMGRDLOG=/var/log/repmgr/repmgrd-9.2.log
 
 # Get config.
 . /etc/sysconfig/network
 
+# Read configuration variable file if it is present
+[ -r /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
+
+# For SELinux we need to use 'runuser' not 'su'
+if [ -x /sbin/runuser ]
+then
+    SU=runuser
+else
+    SU=su
+fi
+
+test -x $exec || exit 0
+
+case "$REPMGRD_ENABLED" in
+    [Yy]*)
+	break
+	;;
+    *)
+	exit 0
+	;;
+esac
+
+if [ -z "${REPMGRD_OPTS}" ]
+then
+    echo "Not starting ${prog}, REPMGRD_OPTS not set in /etc/sysconfig/${prog}"
+    exit 0
+fi
+
 # Check that networking is up.
 [ "${NETWORKING}" = "no" ] && exit 6
 start(){
         [ -x $exec ] || exit 5
-        [ -f "$REPMGRDCONF" ] || exit 6
+        [ -f "${REPMGRDCONF}" ] || exit 6
         echo -n "Starting $prog: "
 
         # Make sure startup-time log file is valid
-        if [ ! -e "$REPMGRDLOG" -a ! -h "$REPMGRDLOG" ]
+        if [ ! -e "${REPMGRDLOG}" -a ! -h "${REPMGRDLOG}" ]
         then
-                touch "$REPMGRDLOG" || exit 1
-                chown $user: "$REPMGRDLOG"
-                chmod go-rwx "$REPMGRDLOG"
-                [ -x /usr/bin/chcon ] && /usr/bin/chcon -u system_u -r object_r -t postgresql_log_t "$REPMGRDLOG" 2>/dev/null
+                touch "${REPMGRDLOG}" || exit 1
+                chown $user: "${REPMGRDLOG}"
+                chmod go-rwx "${REPMGRDLOG}"
+                [ -x /usr/bin/chcon ] && /usr/bin/chcon -u system_u -r object_r -t postgresql_log_t "${REPMGRDLOG}" 2>/dev/null
         fi
 
         mkdir -p $(dirname $pidfile)
         chown $user: $(dirname $pidfile)
 
-	su -l repmgr -c "$exec -f $REPMGRDCONF -p $pidfile -d ->> $REPMGRDLOG 2>&1" $user # --monitoring-history --verbose
+	${SU} -l -c "${exec} -f ${REPMGR_CONF} ${REPMGRD_OPTS} -p ${pidfile} >> ${REPMGRDLOG} 2>&1" ${user} < /dev/null
+	sleep 2
         retval=$?
 	[ $retval -eq 0 ] && success 
         echo
diff --git a/rpm/redhat/9.2/repmgr/EL-5/repmgrd.sysconfig b/rpm/redhat/9.2/repmgr/EL-5/repmgrd.sysconfig
new file mode 100644
index 0000000..e9c5aa9
--- /dev/null
+++ b/rpm/redhat/9.2/repmgr/EL-5/repmgrd.sysconfig
@@ -0,0 +1,24 @@
+# default settings for repmgrd. This file is source by /bin/sh from
+# /etc/init.d/repmgrd
+
+# disable repmgrd by default so it won't get started upon installation
+# valid values: yes/no
+REPMGRD_ENABLED=no
+
+# Repmgr conf file
+REPMGR_CONF=/var/lib/pgsql/repmgr/repmgr.conf
+
+# Options for repmgrd (required)
+#REPMGRD_OPTS="--verbose -d "
+
+# User to run repmgrd as
+#REPMGRD_USER=postgres
+
+# repmgrd binary
+#REPMGRD_BIN=/usr/bin/repmgrd
+
+# pid file
+#REPMGRD_PIDFILE=/var/lib/pgsql/repmgr/repmgrd.pid
+
+# log file
+#REPMGRD_LOG=/var/lib/pgsql/repmgr/repmgrd.log
diff --git a/rpm/redhat/9.2/repmgr/EL-6/repmgr.init b/rpm/redhat/9.2/repmgr/EL-6/repmgr.init
index 91a89ef..7a8463e 100644
--- a/rpm/redhat/9.2/repmgr/EL-6/repmgr.init
+++ b/rpm/redhat/9.2/repmgr/EL-6/repmgr.init
@@ -29,32 +29,63 @@ user=repmgr
 prog=repmgrd
 pidfile=/var/run/repmgr/repmgrd-9.2.pid
 lockfile=/var/lock/subsys/$prog
+REPMGRD_ENABLED=no
+REPMGRD_OPTS=
 REPMGRDCONF=/etc/repmgr/9.2/repmgr.conf
 REPMGRDLOG=/var/log/repmgr/repmgrd-9.2.log
 
 # Get config.
 . /etc/sysconfig/network
 
+# Read configuration variable file if it is present
+[ -r /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
+
+# For SELinux we need to use 'runuser' not 'su'
+if [ -x /sbin/runuser ]
+then
+    SU=runuser
+else
+    SU=su
+fi
+
+test -x $exec || exit 0
+
+case "$REPMGRD_ENABLED" in
+    [Yy]*)
+	break
+	;;
+    *)
+	exit 0
+	;;
+esac
+
+if [ -z "${REPMGRD_OPTS}" ]
+then
+    echo "Not starting ${prog}, REPMGRD_OPTS not set in /etc/sysconfig/${prog}"
+    exit 0
+fi
+
 # Check that networking is up.
 [ "${NETWORKING}" = "no" ] && exit 6
 start(){
         [ -x $exec ] || exit 5
-        [ -f "$REPMGRDCONF" ] || exit 6
+        [ -f "${REPMGRDCONF}" ] || exit 6
         echo -n "Starting $prog: "
 
         # Make sure startup-time log file is valid
-        if [ ! -e "$REPMGRDLOG" -a ! -h "$REPMGRDLOG" ]
+        if [ ! -e "${REPMGRDLOG}" -a ! -h "${REPMGRDLOG}" ]
         then
-                touch "$REPMGRDLOG" || exit 1
-                chown $user: "$REPMGRDLOG"
-                chmod go-rwx "$REPMGRDLOG"
-                [ -x /usr/bin/chcon ] && /usr/bin/chcon -u system_u -r object_r -t postgresql_log_t "$REPMGRDLOG" 2>/dev/null
+                touch "${REPMGRDLOG}" || exit 1
+                chown $user: "${REPMGRDLOG}"
+                chmod go-rwx "${REPMGRDLOG}"
+                [ -x /usr/bin/chcon ] && /usr/bin/chcon -u system_u -r object_r -t postgresql_log_t "${REPMGRDLOG}" 2>/dev/null
         fi
 
         mkdir -p $(dirname $pidfile)
         chown $user: $(dirname $pidfile)
 
-	su -l repmgr -c "$exec -f $REPMGRDCONF -p $pidfile -d ->> $REPMGRDLOG 2>&1" $user # --monitoring-history --verbose
+	${SU} -l -c "${exec} -f ${REPMGR_CONF} ${REPMGRD_OPTS} -p ${pidfile} >> ${REPMGRDLOG} 2>&1" ${user} < /dev/null
+	sleep 2
         retval=$?
 	[ $retval -eq 0 ] && success 
         echo
diff --git a/rpm/redhat/9.2/repmgr/EL-6/repmgrd.sysconfig b/rpm/redhat/9.2/repmgr/EL-6/repmgrd.sysconfig
new file mode 100644
index 0000000..e9c5aa9
--- /dev/null
+++ b/rpm/redhat/9.2/repmgr/EL-6/repmgrd.sysconfig
@@ -0,0 +1,24 @@
+# default settings for repmgrd. This file is source by /bin/sh from
+# /etc/init.d/repmgrd
+
+# disable repmgrd by default so it won't get started upon installation
+# valid values: yes/no
+REPMGRD_ENABLED=no
+
+# Repmgr conf file
+REPMGR_CONF=/var/lib/pgsql/repmgr/repmgr.conf
+
+# Options for repmgrd (required)
+#REPMGRD_OPTS="--verbose -d "
+
+# User to run repmgrd as
+#REPMGRD_USER=postgres
+
+# repmgrd binary
+#REPMGRD_BIN=/usr/bin/repmgrd
+
+# pid file
+#REPMGRD_PIDFILE=/var/lib/pgsql/repmgr/repmgrd.pid
+
+# log file
+#REPMGRD_LOG=/var/lib/pgsql/repmgr/repmgrd.log
diff --git a/rpm/redhat/9.2/repmgr/EL-7/repmgr.init b/rpm/redhat/9.2/repmgr/EL-7/repmgr.init
index 91a89ef..7a8463e 100644
--- a/rpm/redhat/9.2/repmgr/EL-7/repmgr.init
+++ b/rpm/redhat/9.2/repmgr/EL-7/repmgr.init
@@ -29,32 +29,63 @@ user=repmgr
 prog=repmgrd
 pidfile=/var/run/repmgr/repmgrd-9.2.pid
 lockfile=/var/lock/subsys/$prog
+REPMGRD_ENABLED=no
+REPMGRD_OPTS=
 REPMGRDCONF=/etc/repmgr/9.2/repmgr.conf
 REPMGRDLOG=/var/log/repmgr/repmgrd-9.2.log
 
 # Get config.
 . /etc/sysconfig/network
 
+# Read configuration variable file if it is present
+[ -r /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
+
+# For SELinux we need to use 'runuser' not 'su'
+if [ -x /sbin/runuser ]
+then
+    SU=runuser
+else
+    SU=su
+fi
+
+test -x $exec || exit 0
+
+case "$REPMGRD_ENABLED" in
+    [Yy]*)
+	break
+	;;
+    *)
+	exit 0
+	;;
+esac
+
+if [ -z "${REPMGRD_OPTS}" ]
+then
+    echo "Not starting ${prog}, REPMGRD_OPTS not set in /etc/sysconfig/${prog}"
+    exit 0
+fi
+
 # Check that networking is up.
 [ "${NETWORKING}" = "no" ] && exit 6
 start(){
         [ -x $exec ] || exit 5
-        [ -f "$REPMGRDCONF" ] || exit 6
+        [ -f "${REPMGRDCONF}" ] || exit 6
         echo -n "Starting $prog: "
 
         # Make sure startup-time log file is valid
-        if [ ! -e "$REPMGRDLOG" -a ! -h "$REPMGRDLOG" ]
+        if [ ! -e "${REPMGRDLOG}" -a ! -h "${REPMGRDLOG}" ]
         then
-                touch "$REPMGRDLOG" || exit 1
-                chown $user: "$REPMGRDLOG"
-                chmod go-rwx "$REPMGRDLOG"
-                [ -x /usr/bin/chcon ] && /usr/bin/chcon -u system_u -r object_r -t postgresql_log_t "$REPMGRDLOG" 2>/dev/null
+                touch "${REPMGRDLOG}" || exit 1
+                chown $user: "${REPMGRDLOG}"
+                chmod go-rwx "${REPMGRDLOG}"
+                [ -x /usr/bin/chcon ] && /usr/bin/chcon -u system_u -r object_r -t postgresql_log_t "${REPMGRDLOG}" 2>/dev/null
         fi
 
         mkdir -p $(dirname $pidfile)
         chown $user: $(dirname $pidfile)
 
-	su -l repmgr -c "$exec -f $REPMGRDCONF -p $pidfile -d ->> $REPMGRDLOG 2>&1" $user # --monitoring-history --verbose
+	${SU} -l -c "${exec} -f ${REPMGR_CONF} ${REPMGRD_OPTS} -p ${pidfile} >> ${REPMGRDLOG} 2>&1" ${user} < /dev/null
+	sleep 2
         retval=$?
 	[ $retval -eq 0 ] && success 
         echo
diff --git a/rpm/redhat/9.2/repmgr/EL-7/repmgrd.sysconfig b/rpm/redhat/9.2/repmgr/EL-7/repmgrd.sysconfig
new file mode 100644
index 0000000..e9c5aa9
--- /dev/null
+++ b/rpm/redhat/9.2/repmgr/EL-7/repmgrd.sysconfig
@@ -0,0 +1,24 @@
+# default settings for repmgrd. This file is source by /bin/sh from
+# /etc/init.d/repmgrd
+
+# disable repmgrd by default so it won't get started upon installation
+# valid values: yes/no
+REPMGRD_ENABLED=no
+
+# Repmgr conf file
+REPMGR_CONF=/var/lib/pgsql/repmgr/repmgr.conf
+
+# Options for repmgrd (required)
+#REPMGRD_OPTS="--verbose -d "
+
+# User to run repmgrd as
+#REPMGRD_USER=postgres
+
+# repmgrd binary
+#REPMGRD_BIN=/usr/bin/repmgrd
+
+# pid file
+#REPMGRD_PIDFILE=/var/lib/pgsql/repmgr/repmgrd.pid
+
+# log file
+#REPMGRD_LOG=/var/lib/pgsql/repmgr/repmgrd.log
diff --git a/rpm/redhat/9.2/repmgr/F-19/repmgr.init b/rpm/redhat/9.2/repmgr/F-19/repmgr.init
index 91a89ef..7a8463e 100644
--- a/rpm/redhat/9.2/repmgr/F-19/repmgr.init
+++ b/rpm/redhat/9.2/repmgr/F-19/repmgr.init
@@ -29,32 +29,63 @@ user=repmgr
 prog=repmgrd
 pidfile=/var/run/repmgr/repmgrd-9.2.pid
 lockfile=/var/lock/subsys/$prog
+REPMGRD_ENABLED=no
+REPMGRD_OPTS=
 REPMGRDCONF=/etc/repmgr/9.2/repmgr.conf
 REPMGRDLOG=/var/log/repmgr/repmgrd-9.2.log
 
 # Get config.
 . /etc/sysconfig/network
 
+# Read configuration variable file if it is present
+[ -r /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
+
+# For SELinux we need to use 'runuser' not 'su'
+if [ -x /sbin/runuser ]
+then
+    SU=runuser
+else
+    SU=su
+fi
+
+test -x $exec || exit 0
+
+case "$REPMGRD_ENABLED" in
+    [Yy]*)
+	break
+	;;
+    *)
+	exit 0
+	;;
+esac
+
+if [ -z "${REPMGRD_OPTS}" ]
+then
+    echo "Not starting ${prog}, REPMGRD_OPTS not set in /etc/sysconfig/${prog}"
+    exit 0
+fi
+
 # Check that networking is up.
 [ "${NETWORKING}" = "no" ] && exit 6
 start(){
         [ -x $exec ] || exit 5
-        [ -f "$REPMGRDCONF" ] || exit 6
+        [ -f "${REPMGRDCONF}" ] || exit 6
         echo -n "Starting $prog: "
 
         # Make sure startup-time log file is valid
-        if [ ! -e "$REPMGRDLOG" -a ! -h "$REPMGRDLOG" ]
+        if [ ! -e "${REPMGRDLOG}" -a ! -h "${REPMGRDLOG}" ]
         then
-                touch "$REPMGRDLOG" || exit 1
-                chown $user: "$REPMGRDLOG"
-                chmod go-rwx "$REPMGRDLOG"
-                [ -x /usr/bin/chcon ] && /usr/bin/chcon -u system_u -r object_r -t postgresql_log_t "$REPMGRDLOG" 2>/dev/null
+                touch "${REPMGRDLOG}" || exit 1
+                chown $user: "${REPMGRDLOG}"
+                chmod go-rwx "${REPMGRDLOG}"
+                [ -x /usr/bin/chcon ] && /usr/bin/chcon -u system_u -r object_r -t postgresql_log_t "${REPMGRDLOG}" 2>/dev/null
         fi
 
         mkdir -p $(dirname $pidfile)
         chown $user: $(dirname $pidfile)
 
-	su -l repmgr -c "$exec -f $REPMGRDCONF -p $pidfile -d ->> $REPMGRDLOG 2>&1" $user # --monitoring-history --verbose
+	${SU} -l -c "${exec} -f ${REPMGR_CONF} ${REPMGRD_OPTS} -p ${pidfile} >> ${REPMGRDLOG} 2>&1" ${user} < /dev/null
+	sleep 2
         retval=$?
 	[ $retval -eq 0 ] && success 
         echo
diff --git a/rpm/redhat/9.2/repmgr/F-19/repmgrd.sysconfig b/rpm/redhat/9.2/repmgr/F-19/repmgrd.sysconfig
new file mode 100644
index 0000000..e9c5aa9
--- /dev/null
+++ b/rpm/redhat/9.2/repmgr/F-19/repmgrd.sysconfig
@@ -0,0 +1,24 @@
+# default settings for repmgrd. This file is source by /bin/sh from
+# /etc/init.d/repmgrd
+
+# disable repmgrd by default so it won't get started upon installation
+# valid values: yes/no
+REPMGRD_ENABLED=no
+
+# Repmgr conf file
+REPMGR_CONF=/var/lib/pgsql/repmgr/repmgr.conf
+
+# Options for repmgrd (required)
+#REPMGRD_OPTS="--verbose -d "
+
+# User to run repmgrd as
+#REPMGRD_USER=postgres
+
+# repmgrd binary
+#REPMGRD_BIN=/usr/bin/repmgrd
+
+# pid file
+#REPMGRD_PIDFILE=/var/lib/pgsql/repmgr/repmgrd.pid
+
+# log file
+#REPMGRD_LOG=/var/lib/pgsql/repmgr/repmgrd.log
diff --git a/rpm/redhat/9.3/repmgr/EL-5/repmgr.init b/rpm/redhat/9.3/repmgr/EL-5/repmgr.init
index e7b2237..3f9bf49 100644
--- a/rpm/redhat/9.3/repmgr/EL-5/repmgr.init
+++ b/rpm/redhat/9.3/repmgr/EL-5/repmgr.init
@@ -29,32 +29,63 @@ user=repmgr
 prog=repmgrd
 pidfile=/var/run/repmgr/repmgrd-9.3.pid
 lockfile=/var/lock/subsys/$prog
+REPMGRD_ENABLED=no
+REPMGRD_OPTS=
 REPMGRDCONF=/etc/repmgr/9.3/repmgr.conf
 REPMGRDLOG=/var/log/repmgr/repmgrd-9.3.log
 
 # Get config.
 . /etc/sysconfig/network
 
+# Read configuration variable file if it is present
+[ -r /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
+
+# For SELinux we need to use 'runuser' not 'su'
+if [ -x /sbin/runuser ]
+then
+    SU=runuser
+else
+    SU=su
+fi
+
+test -x $exec || exit 0
+
+case "$REPMGRD_ENABLED" in
+    [Yy]*)
+	break
+	;;
+    *)
+	exit 0
+	;;
+esac
+
+if [ -z "${REPMGRD_OPTS}" ]
+then
+    echo "Not starting ${prog}, REPMGRD_OPTS not set in /etc/sysconfig/${prog}"
+    exit 0
+fi
+
 # Check that networking is up.
 [ "${NETWORKING}" = "no" ] && exit 6
 start(){
         [ -x $exec ] || exit 5
-        [ -f "$REPMGRDCONF" ] || exit 6
+        [ -f "${REPMGRDCONF}" ] || exit 6
         echo -n "Starting $prog: "
 
         # Make sure startup-time log file is valid
-        if [ ! -e "$REPMGRDLOG" -a ! -h "$REPMGRDLOG" ]
+        if [ ! -e "${REPMGRDLOG}" -a ! -h "${REPMGRDLOG}" ]
         then
-                touch "$REPMGRDLOG" || exit 1
-                chown $user: "$REPMGRDLOG"
-                chmod go-rwx "$REPMGRDLOG"
-                [ -x /usr/bin/chcon ] && /usr/bin/chcon -u system_u -r object_r -t postgresql_log_t "$REPMGRDLOG" 2>/dev/null
+                touch "${REPMGRDLOG}" || exit 1
+                chown $user: "${REPMGRDLOG}"
+                chmod go-rwx "${REPMGRDLOG}"
+                [ -x /usr/bin/chcon ] && /usr/bin/chcon -u system_u -r object_r -t postgresql_log_t "${REPMGRDLOG}" 2>/dev/null
         fi
 
         mkdir -p $(dirname $pidfile)
         chown $user: $(dirname $pidfile)
 
-	su -l repmgr -c "$exec -f $REPMGRDCONF -p $pidfile -d ->> $REPMGRDLOG 2>&1" $user # --monitoring-history --verbose
+	${SU} -l -c "${exec} -f ${REPMGR_CONF} ${REPMGRD_OPTS} -p ${pidfile} >> ${REPMGRDLOG} 2>&1" ${user} < /dev/null
+	sleep 2
         retval=$?
 	[ $retval -eq 0 ] && success 
         echo
diff --git a/rpm/redhat/9.3/repmgr/EL-5/repmgrd.sysconfig b/rpm/redhat/9.3/repmgr/EL-5/repmgrd.sysconfig
new file mode 100644
index 0000000..e9c5aa9
--- /dev/null
+++ b/rpm/redhat/9.3/repmgr/EL-5/repmgrd.sysconfig
@@ -0,0 +1,24 @@
+# default settings for repmgrd. This file is source by /bin/sh from
+# /etc/init.d/repmgrd
+
+# disable repmgrd by default so it won't get started upon installation
+# valid values: yes/no
+REPMGRD_ENABLED=no
+
+# Repmgr conf file
+REPMGR_CONF=/var/lib/pgsql/repmgr/repmgr.conf
+
+# Options for repmgrd (required)
+#REPMGRD_OPTS="--verbose -d "
+
+# User to run repmgrd as
+#REPMGRD_USER=postgres
+
+# repmgrd binary
+#REPMGRD_BIN=/usr/bin/repmgrd
+
+# pid file
+#REPMGRD_PIDFILE=/var/lib/pgsql/repmgr/repmgrd.pid
+
+# log file
+#REPMGRD_LOG=/var/lib/pgsql/repmgr/repmgrd.log
diff --git a/rpm/redhat/9.3/repmgr/EL-6/repmgr.init b/rpm/redhat/9.3/repmgr/EL-6/repmgr.init
index e7b2237..3f9bf49 100644
--- a/rpm/redhat/9.3/repmgr/EL-6/repmgr.init
+++ b/rpm/redhat/9.3/repmgr/EL-6/repmgr.init
@@ -29,32 +29,63 @@ user=repmgr
 prog=repmgrd
 pidfile=/var/run/repmgr/repmgrd-9.3.pid
 lockfile=/var/lock/subsys/$prog
+REPMGRD_ENABLED=no
+REPMGRD_OPTS=
 REPMGRDCONF=/etc/repmgr/9.3/repmgr.conf
 REPMGRDLOG=/var/log/repmgr/repmgrd-9.3.log
 
 # Get config.
 . /etc/sysconfig/network
 
+# Read configuration variable file if it is present
+[ -r /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
+
+# For SELinux we need to use 'runuser' not 'su'
+if [ -x /sbin/runuser ]
+then
+    SU=runuser
+else
+    SU=su
+fi
+
+test -x $exec || exit 0
+
+case "$REPMGRD_ENABLED" in
+    [Yy]*)
+	break
+	;;
+    *)
+	exit 0
+	;;
+esac
+
+if [ -z "${REPMGRD_OPTS}" ]
+then
+    echo "Not starting ${prog}, REPMGRD_OPTS not set in /etc/sysconfig/${prog}"
+    exit 0
+fi
+
 # Check that networking is up.
 [ "${NETWORKING}" = "no" ] && exit 6
 start(){
         [ -x $exec ] || exit 5
-        [ -f "$REPMGRDCONF" ] || exit 6
+        [ -f "${REPMGRDCONF}" ] || exit 6
         echo -n "Starting $prog: "
 
         # Make sure startup-time log file is valid
-        if [ ! -e "$REPMGRDLOG" -a ! -h "$REPMGRDLOG" ]
+        if [ ! -e "${REPMGRDLOG}" -a ! -h "${REPMGRDLOG}" ]
         then
-                touch "$REPMGRDLOG" || exit 1
-                chown $user: "$REPMGRDLOG"
-                chmod go-rwx "$REPMGRDLOG"
-                [ -x /usr/bin/chcon ] && /usr/bin/chcon -u system_u -r object_r -t postgresql_log_t "$REPMGRDLOG" 2>/dev/null
+                touch "${REPMGRDLOG}" || exit 1
+                chown $user: "${REPMGRDLOG}"
+                chmod go-rwx "${REPMGRDLOG}"
+                [ -x /usr/bin/chcon ] && /usr/bin/chcon -u system_u -r object_r -t postgresql_log_t "${REPMGRDLOG}" 2>/dev/null
         fi
 
         mkdir -p $(dirname $pidfile)
         chown $user: $(dirname $pidfile)
 
-	su -l repmgr -c "$exec -f $REPMGRDCONF -p $pidfile -d ->> $REPMGRDLOG 2>&1" $user # --monitoring-history --verbose
+	${SU} -l -c "${exec} -f ${REPMGR_CONF} ${REPMGRD_OPTS} -p ${pidfile} >> ${REPMGRDLOG} 2>&1" ${user} < /dev/null
+	sleep 2
         retval=$?
 	[ $retval -eq 0 ] && success 
         echo
diff --git a/rpm/redhat/9.3/repmgr/EL-6/repmgrd.sysconfig b/rpm/redhat/9.3/repmgr/EL-6/repmgrd.sysconfig
new file mode 100644
index 0000000..e9c5aa9
--- /dev/null
+++ b/rpm/redhat/9.3/repmgr/EL-6/repmgrd.sysconfig
@@ -0,0 +1,24 @@
+# default settings for repmgrd. This file is source by /bin/sh from
+# /etc/init.d/repmgrd
+
+# disable repmgrd by default so it won't get started upon installation
+# valid values: yes/no
+REPMGRD_ENABLED=no
+
+# Repmgr conf file
+REPMGR_CONF=/var/lib/pgsql/repmgr/repmgr.conf
+
+# Options for repmgrd (required)
+#REPMGRD_OPTS="--verbose -d "
+
+# User to run repmgrd as
+#REPMGRD_USER=postgres
+
+# repmgrd binary
+#REPMGRD_BIN=/usr/bin/repmgrd
+
+# pid file
+#REPMGRD_PIDFILE=/var/lib/pgsql/repmgr/repmgrd.pid
+
+# log file
+#REPMGRD_LOG=/var/lib/pgsql/repmgr/repmgrd.log
diff --git a/rpm/redhat/9.3/repmgr/EL-7/repmgr.init b/rpm/redhat/9.3/repmgr/EL-7/repmgr.init
index e7b2237..3f9bf49 100644
--- a/rpm/redhat/9.3/repmgr/EL-7/repmgr.init
+++ b/rpm/redhat/9.3/repmgr/EL-7/repmgr.init
@@ -29,32 +29,63 @@ user=repmgr
 prog=repmgrd
 pidfile=/var/run/repmgr/repmgrd-9.3.pid
 lockfile=/var/lock/subsys/$prog
+REPMGRD_ENABLED=no
+REPMGRD_OPTS=
 REPMGRDCONF=/etc/repmgr/9.3/repmgr.conf
 REPMGRDLOG=/var/log/repmgr/repmgrd-9.3.log
 
 # Get config.
 . /etc/sysconfig/network
 
+# Read configuration variable file if it is present
+[ -r /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
+
+# For SELinux we need to use 'runuser' not 'su'
+if [ -x /sbin/runuser ]
+then
+    SU=runuser
+else
+    SU=su
+fi
+
+test -x $exec || exit 0
+
+case "$REPMGRD_ENABLED" in
+    [Yy]*)
+	break
+	;;
+    *)
+	exit 0
+	;;
+esac
+
+if [ -z "${REPMGRD_OPTS}" ]
+then
+    echo "Not starting ${prog}, REPMGRD_OPTS not set in /etc/sysconfig/${prog}"
+    exit 0
+fi
+
 # Check that networking is up.
 [ "${NETWORKING}" = "no" ] && exit 6
 start(){
         [ -x $exec ] || exit 5
-        [ -f "$REPMGRDCONF" ] || exit 6
+        [ -f "${REPMGRDCONF}" ] || exit 6
         echo -n "Starting $prog: "
 
         # Make sure startup-time log file is valid
-        if [ ! -e "$REPMGRDLOG" -a ! -h "$REPMGRDLOG" ]
+        if [ ! -e "${REPMGRDLOG}" -a ! -h "${REPMGRDLOG}" ]
         then
-                touch "$REPMGRDLOG" || exit 1
-                chown $user: "$REPMGRDLOG"
-                chmod go-rwx "$REPMGRDLOG"
-                [ -x /usr/bin/chcon ] && /usr/bin/chcon -u system_u -r object_r -t postgresql_log_t "$REPMGRDLOG" 2>/dev/null
+                touch "${REPMGRDLOG}" || exit 1
+                chown $user: "${REPMGRDLOG}"
+                chmod go-rwx "${REPMGRDLOG}"
+                [ -x /usr/bin/chcon ] && /usr/bin/chcon -u system_u -r object_r -t postgresql_log_t "${REPMGRDLOG}" 2>/dev/null
         fi
 
         mkdir -p $(dirname $pidfile)
         chown $user: $(dirname $pidfile)
 
-	su -l repmgr -c "$exec -f $REPMGRDCONF -p $pidfile -d ->> $REPMGRDLOG 2>&1" $user # --monitoring-history --verbose
+	${SU} -l -c "${exec} -f ${REPMGR_CONF} ${REPMGRD_OPTS} -p ${pidfile} >> ${REPMGRDLOG} 2>&1" ${user} < /dev/null
+	sleep 2
         retval=$?
 	[ $retval -eq 0 ] && success 
         echo
diff --git a/rpm/redhat/9.3/repmgr/EL-7/repmgrd.sysconfig b/rpm/redhat/9.3/repmgr/EL-7/repmgrd.sysconfig
new file mode 100644
index 0000000..e9c5aa9
--- /dev/null
+++ b/rpm/redhat/9.3/repmgr/EL-7/repmgrd.sysconfig
@@ -0,0 +1,24 @@
+# default settings for repmgrd. This file is source by /bin/sh from
+# /etc/init.d/repmgrd
+
+# disable repmgrd by default so it won't get started upon installation
+# valid values: yes/no
+REPMGRD_ENABLED=no
+
+# Repmgr conf file
+REPMGR_CONF=/var/lib/pgsql/repmgr/repmgr.conf
+
+# Options for repmgrd (required)
+#REPMGRD_OPTS="--verbose -d "
+
+# User to run repmgrd as
+#REPMGRD_USER=postgres
+
+# repmgrd binary
+#REPMGRD_BIN=/usr/bin/repmgrd
+
+# pid file
+#REPMGRD_PIDFILE=/var/lib/pgsql/repmgr/repmgrd.pid
+
+# log file
+#REPMGRD_LOG=/var/lib/pgsql/repmgr/repmgrd.log
diff --git a/rpm/redhat/9.3/repmgr/F-19/repmgr.init b/rpm/redhat/9.3/repmgr/F-19/repmgr.init
index e7b2237..3f9bf49 100644
--- a/rpm/redhat/9.3/repmgr/F-19/repmgr.init
+++ b/rpm/redhat/9.3/repmgr/F-19/repmgr.init
@@ -29,32 +29,63 @@ user=repmgr
 prog=repmgrd
 pidfile=/var/run/repmgr/repmgrd-9.3.pid
 lockfile=/var/lock/subsys/$prog
+REPMGRD_ENABLED=no
+REPMGRD_OPTS=
 REPMGRDCONF=/etc/repmgr/9.3/repmgr.conf
 REPMGRDLOG=/var/log/repmgr/repmgrd-9.3.log
 
 # Get config.
 . /etc/sysconfig/network
 
+# Read configuration variable file if it is present
+[ -r /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
+
+# For SELinux we need to use 'runuser' not 'su'
+if [ -x /sbin/runuser ]
+then
+    SU=runuser
+else
+    SU=su
+fi
+
+test -x $exec || exit 0
+
+case "$REPMGRD_ENABLED" in
+    [Yy]*)
+	break
+	;;
+    *)
+	exit 0
+	;;
+esac
+
+if [ -z "${REPMGRD_OPTS}" ]
+then
+    echo "Not starting ${prog}, REPMGRD_OPTS not set in /etc/sysconfig/${prog}"
+    exit 0
+fi
+
 # Check that networking is up.
 [ "${NETWORKING}" = "no" ] && exit 6
 start(){
         [ -x $exec ] || exit 5
-        [ -f "$REPMGRDCONF" ] || exit 6
+        [ -f "${REPMGRDCONF}" ] || exit 6
         echo -n "Starting $prog: "
 
         # Make sure startup-time log file is valid
-        if [ ! -e "$REPMGRDLOG" -a ! -h "$REPMGRDLOG" ]
+        if [ ! -e "${REPMGRDLOG}" -a ! -h "${REPMGRDLOG}" ]
         then
-                touch "$REPMGRDLOG" || exit 1
-                chown $user: "$REPMGRDLOG"
-                chmod go-rwx "$REPMGRDLOG"
-                [ -x /usr/bin/chcon ] && /usr/bin/chcon -u system_u -r object_r -t postgresql_log_t "$REPMGRDLOG" 2>/dev/null
+                touch "${REPMGRDLOG}" || exit 1
+                chown $user: "${REPMGRDLOG}"
+                chmod go-rwx "${REPMGRDLOG}"
+                [ -x /usr/bin/chcon ] && /usr/bin/chcon -u system_u -r object_r -t postgresql_log_t "${REPMGRDLOG}" 2>/dev/null
         fi
 
         mkdir -p $(dirname $pidfile)
         chown $user: $(dirname $pidfile)
 
-	su -l repmgr -c "$exec -f $REPMGRDCONF -p $pidfile -d ->> $REPMGRDLOG 2>&1" $user # --monitoring-history --verbose
+	${SU} -l -c "${exec} -f ${REPMGR_CONF} ${REPMGRD_OPTS} -p ${pidfile} >> ${REPMGRDLOG} 2>&1" ${user} < /dev/null
+	sleep 2
         retval=$?
 	[ $retval -eq 0 ] && success 
         echo
diff --git a/rpm/redhat/9.3/repmgr/F-19/repmgrd.sysconfig b/rpm/redhat/9.3/repmgr/F-19/repmgrd.sysconfig
new file mode 100644
index 0000000..e9c5aa9
--- /dev/null
+++ b/rpm/redhat/9.3/repmgr/F-19/repmgrd.sysconfig
@@ -0,0 +1,24 @@
+# default settings for repmgrd. This file is source by /bin/sh from
+# /etc/init.d/repmgrd
+
+# disable repmgrd by default so it won't get started upon installation
+# valid values: yes/no
+REPMGRD_ENABLED=no
+
+# Repmgr conf file
+REPMGR_CONF=/var/lib/pgsql/repmgr/repmgr.conf
+
+# Options for repmgrd (required)
+#REPMGRD_OPTS="--verbose -d "
+
+# User to run repmgrd as
+#REPMGRD_USER=postgres
+
+# repmgrd binary
+#REPMGRD_BIN=/usr/bin/repmgrd
+
+# pid file
+#REPMGRD_PIDFILE=/var/lib/pgsql/repmgr/repmgrd.pid
+
+# log file
+#REPMGRD_LOG=/var/lib/pgsql/repmgr/repmgrd.log
diff --git a/rpm/redhat/9.3/repmgr/F-20/repmgr.init b/rpm/redhat/9.3/repmgr/F-20/repmgr.init
index e7b2237..3f9bf49 100644
--- a/rpm/redhat/9.3/repmgr/F-20/repmgr.init
+++ b/rpm/redhat/9.3/repmgr/F-20/repmgr.init
@@ -29,32 +29,63 @@ user=repmgr
 prog=repmgrd
 pidfile=/var/run/repmgr/repmgrd-9.3.pid
 lockfile=/var/lock/subsys/$prog
+REPMGRD_ENABLED=no
+REPMGRD_OPTS=
 REPMGRDCONF=/etc/repmgr/9.3/repmgr.conf
 REPMGRDLOG=/var/log/repmgr/repmgrd-9.3.log
 
 # Get config.
 . /etc/sysconfig/network
 
+# Read configuration variable file if it is present
+[ -r /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
+
+# For SELinux we need to use 'runuser' not 'su'
+if [ -x /sbin/runuser ]
+then
+    SU=runuser
+else
+    SU=su
+fi
+
+test -x $exec || exit 0
+
+case "$REPMGRD_ENABLED" in
+    [Yy]*)
+	break
+	;;
+    *)
+	exit 0
+	;;
+esac
+
+if [ -z "${REPMGRD_OPTS}" ]
+then
+    echo "Not starting ${prog}, REPMGRD_OPTS not set in /etc/sysconfig/${prog}"
+    exit 0
+fi
+
 # Check that networking is up.
 [ "${NETWORKING}" = "no" ] && exit 6
 start(){
         [ -x $exec ] || exit 5
-        [ -f "$REPMGRDCONF" ] || exit 6
+        [ -f "${REPMGRDCONF}" ] || exit 6
         echo -n "Starting $prog: "
 
         # Make sure startup-time log file is valid
-        if [ ! -e "$REPMGRDLOG" -a ! -h "$REPMGRDLOG" ]
+        if [ ! -e "${REPMGRDLOG}" -a ! -h "${REPMGRDLOG}" ]
         then
-                touch "$REPMGRDLOG" || exit 1
-                chown $user: "$REPMGRDLOG"
-                chmod go-rwx "$REPMGRDLOG"
-                [ -x /usr/bin/chcon ] && /usr/bin/chcon -u system_u -r object_r -t postgresql_log_t "$REPMGRDLOG" 2>/dev/null
+                touch "${REPMGRDLOG}" || exit 1
+                chown $user: "${REPMGRDLOG}"
+                chmod go-rwx "${REPMGRDLOG}"
+                [ -x /usr/bin/chcon ] && /usr/bin/chcon -u system_u -r object_r -t postgresql_log_t "${REPMGRDLOG}" 2>/dev/null
         fi
 
         mkdir -p $(dirname $pidfile)
         chown $user: $(dirname $pidfile)
 
-	su -l repmgr -c "$exec -f $REPMGRDCONF -p $pidfile -d ->> $REPMGRDLOG 2>&1" $user # --monitoring-history --verbose
+	${SU} -l -c "${exec} -f ${REPMGR_CONF} ${REPMGRD_OPTS} -p ${pidfile} >> ${REPMGRDLOG} 2>&1" ${user} < /dev/null
+	sleep 2
         retval=$?
 	[ $retval -eq 0 ] && success 
         echo
diff --git a/rpm/redhat/9.3/repmgr/F-20/repmgrd.sysconfig b/rpm/redhat/9.3/repmgr/F-20/repmgrd.sysconfig
new file mode 100644
index 0000000..e9c5aa9
--- /dev/null
+++ b/rpm/redhat/9.3/repmgr/F-20/repmgrd.sysconfig
@@ -0,0 +1,24 @@
+# default settings for repmgrd. This file is source by /bin/sh from
+# /etc/init.d/repmgrd
+
+# disable repmgrd by default so it won't get started upon installation
+# valid values: yes/no
+REPMGRD_ENABLED=no
+
+# Repmgr conf file
+REPMGR_CONF=/var/lib/pgsql/repmgr/repmgr.conf
+
+# Options for repmgrd (required)
+#REPMGRD_OPTS="--verbose -d "
+
+# User to run repmgrd as
+#REPMGRD_USER=postgres
+
+# repmgrd binary
+#REPMGRD_BIN=/usr/bin/repmgrd
+
+# pid file
+#REPMGRD_PIDFILE=/var/lib/pgsql/repmgr/repmgrd.pid
+
+# log file
+#REPMGRD_LOG=/var/lib/pgsql/repmgr/repmgrd.log
diff --git a/rpm/redhat/9.3/repmgr/F-21/repmgr.init b/rpm/redhat/9.3/repmgr/F-21/repmgr.init
index e7b2237..3f9bf49 100644
--- a/rpm/redhat/9.3/repmgr/F-21/repmgr.init
+++ b/rpm/redhat/9.3/repmgr/F-21/repmgr.init
@@ -29,32 +29,63 @@ user=repmgr
 prog=repmgrd
 pidfile=/var/run/repmgr/repmgrd-9.3.pid
 lockfile=/var/lock/subsys/$prog
+REPMGRD_ENABLED=no
+REPMGRD_OPTS=
 REPMGRDCONF=/etc/repmgr/9.3/repmgr.conf
 REPMGRDLOG=/var/log/repmgr/repmgrd-9.3.log
 
 # Get config.
 . /etc/sysconfig/network
 
+# Read configuration variable file if it is present
+[ -r /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
+
+# For SELinux we need to use 'runuser' not 'su'
+if [ -x /sbin/runuser ]
+then
+    SU=runuser
+else
+    SU=su
+fi
+
+test -x $exec || exit 0
+
+case "$REPMGRD_ENABLED" in
+    [Yy]*)
+	break
+	;;
+    *)
+	exit 0
+	;;
+esac
+
+if [ -z "${REPMGRD_OPTS}" ]
+then
+    echo "Not starting ${prog}, REPMGRD_OPTS not set in /etc/sysconfig/${prog}"
+    exit 0
+fi
+
 # Check that networking is up.
 [ "${NETWORKING}" = "no" ] && exit 6
 start(){
         [ -x $exec ] || exit 5
-        [ -f "$REPMGRDCONF" ] || exit 6
+        [ -f "${REPMGRDCONF}" ] || exit 6
         echo -n "Starting $prog: "
 
         # Make sure startup-time log file is valid
-        if [ ! -e "$REPMGRDLOG" -a ! -h "$REPMGRDLOG" ]
+        if [ ! -e "${REPMGRDLOG}" -a ! -h "${REPMGRDLOG}" ]
         then
-                touch "$REPMGRDLOG" || exit 1
-                chown $user: "$REPMGRDLOG"
-                chmod go-rwx "$REPMGRDLOG"
-                [ -x /usr/bin/chcon ] && /usr/bin/chcon -u system_u -r object_r -t postgresql_log_t "$REPMGRDLOG" 2>/dev/null
+                touch "${REPMGRDLOG}" || exit 1
+                chown $user: "${REPMGRDLOG}"
+                chmod go-rwx "${REPMGRDLOG}"
+                [ -x /usr/bin/chcon ] && /usr/bin/chcon -u system_u -r object_r -t postgresql_log_t "${REPMGRDLOG}" 2>/dev/null
         fi
 
         mkdir -p $(dirname $pidfile)
         chown $user: $(dirname $pidfile)
 
-	su -l repmgr -c "$exec -f $REPMGRDCONF -p $pidfile -d ->> $REPMGRDLOG 2>&1" $user # --monitoring-history --verbose
+	${SU} -l -c "${exec} -f ${REPMGR_CONF} ${REPMGRD_OPTS} -p ${pidfile} >> ${REPMGRDLOG} 2>&1" ${user} < /dev/null
+	sleep 2
         retval=$?
 	[ $retval -eq 0 ] && success 
         echo
diff --git a/rpm/redhat/9.3/repmgr/F-21/repmgrd.sysconfig b/rpm/redhat/9.3/repmgr/F-21/repmgrd.sysconfig
new file mode 100644
index 0000000..e9c5aa9
--- /dev/null
+++ b/rpm/redhat/9.3/repmgr/F-21/repmgrd.sysconfig
@@ -0,0 +1,24 @@
+# default settings for repmgrd. This file is source by /bin/sh from
+# /etc/init.d/repmgrd
+
+# disable repmgrd by default so it won't get started upon installation
+# valid values: yes/no
+REPMGRD_ENABLED=no
+
+# Repmgr conf file
+REPMGR_CONF=/var/lib/pgsql/repmgr/repmgr.conf
+
+# Options for repmgrd (required)
+#REPMGRD_OPTS="--verbose -d "
+
+# User to run repmgrd as
+#REPMGRD_USER=postgres
+
+# repmgrd binary
+#REPMGRD_BIN=/usr/bin/repmgrd
+
+# pid file
+#REPMGRD_PIDFILE=/var/lib/pgsql/repmgr/repmgrd.pid
+
+# log file
+#REPMGRD_LOG=/var/lib/pgsql/repmgr/repmgrd.log
diff --git a/rpm/redhat/9.3/repmgr/F-22/repmgr.init b/rpm/redhat/9.3/repmgr/F-22/repmgr.init
index e7b2237..3f9bf49 100644
--- a/rpm/redhat/9.3/repmgr/F-22/repmgr.init
+++ b/rpm/redhat/9.3/repmgr/F-22/repmgr.init
@@ -29,32 +29,63 @@ user=repmgr
 prog=repmgrd
 pidfile=/var/run/repmgr/repmgrd-9.3.pid
 lockfile=/var/lock/subsys/$prog
+REPMGRD_ENABLED=no
+REPMGRD_OPTS=
 REPMGRDCONF=/etc/repmgr/9.3/repmgr.conf
 REPMGRDLOG=/var/log/repmgr/repmgrd-9.3.log
 
 # Get config.
 . /etc/sysconfig/network
 
+# Read configuration variable file if it is present
+[ -r /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
+
+# For SELinux we need to use 'runuser' not 'su'
+if [ -x /sbin/runuser ]
+then
+    SU=runuser
+else
+    SU=su
+fi
+
+test -x $exec || exit 0
+
+case "$REPMGRD_ENABLED" in
+    [Yy]*)
+	break
+	;;
+    *)
+	exit 0
+	;;
+esac
+
+if [ -z "${REPMGRD_OPTS}" ]
+then
+    echo "Not starting ${prog}, REPMGRD_OPTS not set in /etc/sysconfig/${prog}"
+    exit 0
+fi
+
 # Check that networking is up.
 [ "${NETWORKING}" = "no" ] && exit 6
 start(){
         [ -x $exec ] || exit 5
-        [ -f "$REPMGRDCONF" ] || exit 6
+        [ -f "${REPMGRDCONF}" ] || exit 6
         echo -n "Starting $prog: "
 
         # Make sure startup-time log file is valid
-        if [ ! -e "$REPMGRDLOG" -a ! -h "$REPMGRDLOG" ]
+        if [ ! -e "${REPMGRDLOG}" -a ! -h "${REPMGRDLOG}" ]
         then
-                touch "$REPMGRDLOG" || exit 1
-                chown $user: "$REPMGRDLOG"
-                chmod go-rwx "$REPMGRDLOG"
-                [ -x /usr/bin/chcon ] && /usr/bin/chcon -u system_u -r object_r -t postgresql_log_t "$REPMGRDLOG" 2>/dev/null
+                touch "${REPMGRDLOG}" || exit 1
+                chown $user: "${REPMGRDLOG}"
+                chmod go-rwx "${REPMGRDLOG}"
+                [ -x /usr/bin/chcon ] && /usr/bin/chcon -u system_u -r object_r -t postgresql_log_t "${REPMGRDLOG}" 2>/dev/null
         fi
 
         mkdir -p $(dirname $pidfile)
         chown $user: $(dirname $pidfile)
 
-	su -l repmgr -c "$exec -f $REPMGRDCONF -p $pidfile -d ->> $REPMGRDLOG 2>&1" $user # --monitoring-history --verbose
+	${SU} -l -c "${exec} -f ${REPMGR_CONF} ${REPMGRD_OPTS} -p ${pidfile} >> ${REPMGRDLOG} 2>&1" ${user} < /dev/null
+	sleep 2
         retval=$?
 	[ $retval -eq 0 ] && success 
         echo
diff --git a/rpm/redhat/9.3/repmgr/F-22/repmgrd.sysconfig b/rpm/redhat/9.3/repmgr/F-22/repmgrd.sysconfig
new file mode 100644
index 0000000..e9c5aa9
--- /dev/null
+++ b/rpm/redhat/9.3/repmgr/F-22/repmgrd.sysconfig
@@ -0,0 +1,24 @@
+# default settings for repmgrd. This file is source by /bin/sh from
+# /etc/init.d/repmgrd
+
+# disable repmgrd by default so it won't get started upon installation
+# valid values: yes/no
+REPMGRD_ENABLED=no
+
+# Repmgr conf file
+REPMGR_CONF=/var/lib/pgsql/repmgr/repmgr.conf
+
+# Options for repmgrd (required)
+#REPMGRD_OPTS="--verbose -d "
+
+# User to run repmgrd as
+#REPMGRD_USER=postgres
+
+# repmgrd binary
+#REPMGRD_BIN=/usr/bin/repmgrd
+
+# pid file
+#REPMGRD_PIDFILE=/var/lib/pgsql/repmgr/repmgrd.pid
+
+# log file
+#REPMGRD_LOG=/var/lib/pgsql/repmgr/repmgrd.log
diff --git a/rpm/redhat/9.3/repmgr/F-23/repmgr.init b/rpm/redhat/9.3/repmgr/F-23/repmgr.init
index e7b2237..3f9bf49 100644
--- a/rpm/redhat/9.3/repmgr/F-23/repmgr.init
+++ b/rpm/redhat/9.3/repmgr/F-23/repmgr.init
@@ -29,32 +29,63 @@ user=repmgr
 prog=repmgrd
 pidfile=/var/run/repmgr/repmgrd-9.3.pid
 lockfile=/var/lock/subsys/$prog
+REPMGRD_ENABLED=no
+REPMGRD_OPTS=
 REPMGRDCONF=/etc/repmgr/9.3/repmgr.conf
 REPMGRDLOG=/var/log/repmgr/repmgrd-9.3.log
 
 # Get config.
 . /etc/sysconfig/network
 
+# Read configuration variable file if it is present
+[ -r /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
+
+# For SELinux we need to use 'runuser' not 'su'
+if [ -x /sbin/runuser ]
+then
+    SU=runuser
+else
+    SU=su
+fi
+
+test -x $exec || exit 0
+
+case "$REPMGRD_ENABLED" in
+    [Yy]*)
+	break
+	;;
+    *)
+	exit 0
+	;;
+esac
+
+if [ -z "${REPMGRD_OPTS}" ]
+then
+    echo "Not starting ${prog}, REPMGRD_OPTS not set in /etc/sysconfig/${prog}"
+    exit 0
+fi
+
 # Check that networking is up.
 [ "${NETWORKING}" = "no" ] && exit 6
 start(){
         [ -x $exec ] || exit 5
-        [ -f "$REPMGRDCONF" ] || exit 6
+        [ -f "${REPMGRDCONF}" ] || exit 6
         echo -n "Starting $prog: "
 
         # Make sure startup-time log file is valid
-        if [ ! -e "$REPMGRDLOG" -a ! -h "$REPMGRDLOG" ]
+        if [ ! -e "${REPMGRDLOG}" -a ! -h "${REPMGRDLOG}" ]
         then
-                touch "$REPMGRDLOG" || exit 1
-                chown $user: "$REPMGRDLOG"
-                chmod go-rwx "$REPMGRDLOG"
-                [ -x /usr/bin/chcon ] && /usr/bin/chcon -u system_u -r object_r -t postgresql_log_t "$REPMGRDLOG" 2>/dev/null
+                touch "${REPMGRDLOG}" || exit 1
+                chown $user: "${REPMGRDLOG}"
+                chmod go-rwx "${REPMGRDLOG}"
+                [ -x /usr/bin/chcon ] && /usr/bin/chcon -u system_u -r object_r -t postgresql_log_t "${REPMGRDLOG}" 2>/dev/null
         fi
 
         mkdir -p $(dirname $pidfile)
         chown $user: $(dirname $pidfile)
 
-	su -l repmgr -c "$exec -f $REPMGRDCONF -p $pidfile -d ->> $REPMGRDLOG 2>&1" $user # --monitoring-history --verbose
+	${SU} -l -c "${exec} -f ${REPMGR_CONF} ${REPMGRD_OPTS} -p ${pidfile} >> ${REPMGRDLOG} 2>&1" ${user} < /dev/null
+	sleep 2
         retval=$?
 	[ $retval -eq 0 ] && success 
         echo
diff --git a/rpm/redhat/9.3/repmgr/F-23/repmgrd.sysconfig b/rpm/redhat/9.3/repmgr/F-23/repmgrd.sysconfig
new file mode 100644
index 0000000..e9c5aa9
--- /dev/null
+++ b/rpm/redhat/9.3/repmgr/F-23/repmgrd.sysconfig
@@ -0,0 +1,24 @@
+# default settings for repmgrd. This file is source by /bin/sh from
+# /etc/init.d/repmgrd
+
+# disable repmgrd by default so it won't get started upon installation
+# valid values: yes/no
+REPMGRD_ENABLED=no
+
+# Repmgr conf file
+REPMGR_CONF=/var/lib/pgsql/repmgr/repmgr.conf
+
+# Options for repmgrd (required)
+#REPMGRD_OPTS="--verbose -d "
+
+# User to run repmgrd as
+#REPMGRD_USER=postgres
+
+# repmgrd binary
+#REPMGRD_BIN=/usr/bin/repmgrd
+
+# pid file
+#REPMGRD_PIDFILE=/var/lib/pgsql/repmgr/repmgrd.pid
+
+# log file
+#REPMGRD_LOG=/var/lib/pgsql/repmgr/repmgrd.log
diff --git a/rpm/redhat/9.4/repmgr/EL-5/repmgr.init b/rpm/redhat/9.4/repmgr/EL-5/repmgr.init
index c900170..fd0fdd2 100644
--- a/rpm/redhat/9.4/repmgr/EL-5/repmgr.init
+++ b/rpm/redhat/9.4/repmgr/EL-5/repmgr.init
@@ -29,32 +29,63 @@ user=repmgr
 prog=repmgrd
 pidfile=/var/run/repmgr/repmgrd-9.4.pid
 lockfile=/var/lock/subsys/$prog
+REPMGRD_ENABLED=no
+REPMGRD_OPTS=
 REPMGRDCONF=/etc/repmgr/9.4/repmgr.conf
 REPMGRDLOG=/var/log/repmgr/repmgrd-9.4.log
 
 # Get config.
 . /etc/sysconfig/network
 
+# Read configuration variable file if it is present
+[ -r /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
+
+# For SELinux we need to use 'runuser' not 'su'
+if [ -x /sbin/runuser ]
+then
+    SU=runuser
+else
+    SU=su
+fi
+
+test -x $exec || exit 0
+
+case "$REPMGRD_ENABLED" in
+    [Yy]*)
+	break
+	;;
+    *)
+	exit 0
+	;;
+esac
+
+if [ -z "${REPMGRD_OPTS}" ]
+then
+    echo "Not starting ${prog}, REPMGRD_OPTS not set in /etc/sysconfig/${prog}"
+    exit 0
+fi
+
 # Check that networking is up.
 [ "${NETWORKING}" = "no" ] && exit 6
 start(){
         [ -x $exec ] || exit 5
-        [ -f "$REPMGRDCONF" ] || exit 6
+        [ -f "${REPMGRDCONF}" ] || exit 6
         echo -n "Starting $prog: "
 
         # Make sure startup-time log file is valid
-        if [ ! -e "$REPMGRDLOG" -a ! -h "$REPMGRDLOG" ]
+        if [ ! -e "${REPMGRDLOG}" -a ! -h "${REPMGRDLOG}" ]
         then
-                touch "$REPMGRDLOG" || exit 1
-                chown $user: "$REPMGRDLOG"
-                chmod go-rwx "$REPMGRDLOG"
-                [ -x /usr/bin/chcon ] && /usr/bin/chcon -u system_u -r object_r -t postgresql_log_t "$REPMGRDLOG" 2>/dev/null
+                touch "${REPMGRDLOG}" || exit 1
+                chown $user: "${REPMGRDLOG}"
+                chmod go-rwx "${REPMGRDLOG}"
+                [ -x /usr/bin/chcon ] && /usr/bin/chcon -u system_u -r object_r -t postgresql_log_t "${REPMGRDLOG}" 2>/dev/null
         fi
 
         mkdir -p $(dirname $pidfile)
         chown $user: $(dirname $pidfile)
 
-	su -l repmgr -c "$exec -f $REPMGRDCONF -p $pidfile -d ->> $REPMGRDLOG 2>&1" $user # --monitoring-history --verbose
+	${SU} -l -c "${exec} -f ${REPMGR_CONF} ${REPMGRD_OPTS} -p ${pidfile} >> ${REPMGRDLOG} 2>&1" ${user} < /dev/null
+	sleep 2
         retval=$?
 	[ $retval -eq 0 ] && success 
         echo
diff --git a/rpm/redhat/9.4/repmgr/EL-6/repmgr.init b/rpm/redhat/9.4/repmgr/EL-6/repmgr.init
index c900170..fd0fdd2 100644
--- a/rpm/redhat/9.4/repmgr/EL-6/repmgr.init
+++ b/rpm/redhat/9.4/repmgr/EL-6/repmgr.init
@@ -29,32 +29,63 @@ user=repmgr
 prog=repmgrd
 pidfile=/var/run/repmgr/repmgrd-9.4.pid
 lockfile=/var/lock/subsys/$prog
+REPMGRD_ENABLED=no
+REPMGRD_OPTS=
 REPMGRDCONF=/etc/repmgr/9.4/repmgr.conf
 REPMGRDLOG=/var/log/repmgr/repmgrd-9.4.log
 
 # Get config.
 . /etc/sysconfig/network
 
+# Read configuration variable file if it is present
+[ -r /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
+
+# For SELinux we need to use 'runuser' not 'su'
+if [ -x /sbin/runuser ]
+then
+    SU=runuser
+else
+    SU=su
+fi
+
+test -x $exec || exit 0
+
+case "$REPMGRD_ENABLED" in
+    [Yy]*)
+	break
+	;;
+    *)
+	exit 0
+	;;
+esac
+
+if [ -z "${REPMGRD_OPTS}" ]
+then
+    echo "Not starting ${prog}, REPMGRD_OPTS not set in /etc/sysconfig/${prog}"
+    exit 0
+fi
+
 # Check that networking is up.
 [ "${NETWORKING}" = "no" ] && exit 6
 start(){
         [ -x $exec ] || exit 5
-        [ -f "$REPMGRDCONF" ] || exit 6
+        [ -f "${REPMGRDCONF}" ] || exit 6
         echo -n "Starting $prog: "
 
         # Make sure startup-time log file is valid
-        if [ ! -e "$REPMGRDLOG" -a ! -h "$REPMGRDLOG" ]
+        if [ ! -e "${REPMGRDLOG}" -a ! -h "${REPMGRDLOG}" ]
         then
-                touch "$REPMGRDLOG" || exit 1
-                chown $user: "$REPMGRDLOG"
-                chmod go-rwx "$REPMGRDLOG"
-                [ -x /usr/bin/chcon ] && /usr/bin/chcon -u system_u -r object_r -t postgresql_log_t "$REPMGRDLOG" 2>/dev/null
+                touch "${REPMGRDLOG}" || exit 1
+                chown $user: "${REPMGRDLOG}"
+                chmod go-rwx "${REPMGRDLOG}"
+                [ -x /usr/bin/chcon ] && /usr/bin/chcon -u system_u -r object_r -t postgresql_log_t "${REPMGRDLOG}" 2>/dev/null
         fi
 
         mkdir -p $(dirname $pidfile)
         chown $user: $(dirname $pidfile)
 
-	su -l repmgr -c "$exec -f $REPMGRDCONF -p $pidfile -d ->> $REPMGRDLOG 2>&1" $user # --monitoring-history --verbose
+	${SU} -l -c "${exec} -f ${REPMGR_CONF} ${REPMGRD_OPTS} -p ${pidfile} >> ${REPMGRDLOG} 2>&1" ${user} < /dev/null
+	sleep 2
         retval=$?
 	[ $retval -eq 0 ] && success 
         echo
diff --git a/rpm/redhat/9.4/repmgr/EL-6/repmgrd.sysconfig b/rpm/redhat/9.4/repmgr/EL-6/repmgrd.sysconfig
new file mode 100644
index 0000000..e9c5aa9
--- /dev/null
+++ b/rpm/redhat/9.4/repmgr/EL-6/repmgrd.sysconfig
@@ -0,0 +1,24 @@
+# default settings for repmgrd. This file is source by /bin/sh from
+# /etc/init.d/repmgrd
+
+# disable repmgrd by default so it won't get started upon installation
+# valid values: yes/no
+REPMGRD_ENABLED=no
+
+# Repmgr conf file
+REPMGR_CONF=/var/lib/pgsql/repmgr/repmgr.conf
+
+# Options for repmgrd (required)
+#REPMGRD_OPTS="--verbose -d "
+
+# User to run repmgrd as
+#REPMGRD_USER=postgres
+
+# repmgrd binary
+#REPMGRD_BIN=/usr/bin/repmgrd
+
+# pid file
+#REPMGRD_PIDFILE=/var/lib/pgsql/repmgr/repmgrd.pid
+
+# log file
+#REPMGRD_LOG=/var/lib/pgsql/repmgr/repmgrd.log
diff --git a/rpm/redhat/9.4/repmgr/EL-7/repmgr.init b/rpm/redhat/9.4/repmgr/EL-7/repmgr.init
index c900170..fd0fdd2 100644
--- a/rpm/redhat/9.4/repmgr/EL-7/repmgr.init
+++ b/rpm/redhat/9.4/repmgr/EL-7/repmgr.init
@@ -29,32 +29,63 @@ user=repmgr
 prog=repmgrd
 pidfile=/var/run/repmgr/repmgrd-9.4.pid
 lockfile=/var/lock/subsys/$prog
+REPMGRD_ENABLED=no
+REPMGRD_OPTS=
 REPMGRDCONF=/etc/repmgr/9.4/repmgr.conf
 REPMGRDLOG=/var/log/repmgr/repmgrd-9.4.log
 
 # Get config.
 . /etc/sysconfig/network
 
+# Read configuration variable file if it is present
+[ -r /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
+
+# For SELinux we need to use 'runuser' not 'su'
+if [ -x /sbin/runuser ]
+then
+    SU=runuser
+else
+    SU=su
+fi
+
+test -x $exec || exit 0
+
+case "$REPMGRD_ENABLED" in
+    [Yy]*)
+	break
+	;;
+    *)
+	exit 0
+	;;
+esac
+
+if [ -z "${REPMGRD_OPTS}" ]
+then
+    echo "Not starting ${prog}, REPMGRD_OPTS not set in /etc/sysconfig/${prog}"
+    exit 0
+fi
+
 # Check that networking is up.
 [ "${NETWORKING}" = "no" ] && exit 6
 start(){
         [ -x $exec ] || exit 5
-        [ -f "$REPMGRDCONF" ] || exit 6
+        [ -f "${REPMGRDCONF}" ] || exit 6
         echo -n "Starting $prog: "
 
         # Make sure startup-time log file is valid
-        if [ ! -e "$REPMGRDLOG" -a ! -h "$REPMGRDLOG" ]
+        if [ ! -e "${REPMGRDLOG}" -a ! -h "${REPMGRDLOG}" ]
         then
-                touch "$REPMGRDLOG" || exit 1
-                chown $user: "$REPMGRDLOG"
-                chmod go-rwx "$REPMGRDLOG"
-                [ -x /usr/bin/chcon ] && /usr/bin/chcon -u system_u -r object_r -t postgresql_log_t "$REPMGRDLOG" 2>/dev/null
+                touch "${REPMGRDLOG}" || exit 1
+                chown $user: "${REPMGRDLOG}"
+                chmod go-rwx "${REPMGRDLOG}"
+                [ -x /usr/bin/chcon ] && /usr/bin/chcon -u system_u -r object_r -t postgresql_log_t "${REPMGRDLOG}" 2>/dev/null
         fi
 
         mkdir -p $(dirname $pidfile)
         chown $user: $(dirname $pidfile)
 
-	su -l repmgr -c "$exec -f $REPMGRDCONF -p $pidfile -d ->> $REPMGRDLOG 2>&1" $user # --monitoring-history --verbose
+	${SU} -l -c "${exec} -f ${REPMGR_CONF} ${REPMGRD_OPTS} -p ${pidfile} >> ${REPMGRDLOG} 2>&1" ${user} < /dev/null
+	sleep 2
         retval=$?
 	[ $retval -eq 0 ] && success 
         echo
diff --git a/rpm/redhat/9.4/repmgr/F-20/repmgr.init b/rpm/redhat/9.4/repmgr/F-20/repmgr.init
index c900170..fd0fdd2 100644
--- a/rpm/redhat/9.4/repmgr/F-20/repmgr.init
+++ b/rpm/redhat/9.4/repmgr/F-20/repmgr.init
@@ -29,32 +29,63 @@ user=repmgr
 prog=repmgrd
 pidfile=/var/run/repmgr/repmgrd-9.4.pid
 lockfile=/var/lock/subsys/$prog
+REPMGRD_ENABLED=no
+REPMGRD_OPTS=
 REPMGRDCONF=/etc/repmgr/9.4/repmgr.conf
 REPMGRDLOG=/var/log/repmgr/repmgrd-9.4.log
 
 # Get config.
 . /etc/sysconfig/network
 
+# Read configuration variable file if it is present
+[ -r /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
+
+# For SELinux we need to use 'runuser' not 'su'
+if [ -x /sbin/runuser ]
+then
+    SU=runuser
+else
+    SU=su
+fi
+
+test -x $exec || exit 0
+
+case "$REPMGRD_ENABLED" in
+    [Yy]*)
+	break
+	;;
+    *)
+	exit 0
+	;;
+esac
+
+if [ -z "${REPMGRD_OPTS}" ]
+then
+    echo "Not starting ${prog}, REPMGRD_OPTS not set in /etc/sysconfig/${prog}"
+    exit 0
+fi
+
 # Check that networking is up.
 [ "${NETWORKING}" = "no" ] && exit 6
 start(){
         [ -x $exec ] || exit 5
-        [ -f "$REPMGRDCONF" ] || exit 6
+        [ -f "${REPMGRDCONF}" ] || exit 6
         echo -n "Starting $prog: "
 
         # Make sure startup-time log file is valid
-        if [ ! -e "$REPMGRDLOG" -a ! -h "$REPMGRDLOG" ]
+        if [ ! -e "${REPMGRDLOG}" -a ! -h "${REPMGRDLOG}" ]
         then
-                touch "$REPMGRDLOG" || exit 1
-                chown $user: "$REPMGRDLOG"
-                chmod go-rwx "$REPMGRDLOG"
-                [ -x /usr/bin/chcon ] && /usr/bin/chcon -u system_u -r object_r -t postgresql_log_t "$REPMGRDLOG" 2>/dev/null
+                touch "${REPMGRDLOG}" || exit 1
+                chown $user: "${REPMGRDLOG}"
+                chmod go-rwx "${REPMGRDLOG}"
+                [ -x /usr/bin/chcon ] && /usr/bin/chcon -u system_u -r object_r -t postgresql_log_t "${REPMGRDLOG}" 2>/dev/null
         fi
 
         mkdir -p $(dirname $pidfile)
         chown $user: $(dirname $pidfile)
 
-	su -l repmgr -c "$exec -f $REPMGRDCONF -p $pidfile -d ->> $REPMGRDLOG 2>&1" $user # --monitoring-history --verbose
+	${SU} -l -c "${exec} -f ${REPMGR_CONF} ${REPMGRD_OPTS} -p ${pidfile} >> ${REPMGRDLOG} 2>&1" ${user} < /dev/null
+	sleep 2
         retval=$?
 	[ $retval -eq 0 ] && success 
         echo
diff --git a/rpm/redhat/9.4/repmgr/F-21/repmgr.init b/rpm/redhat/9.4/repmgr/F-21/repmgr.init
index c900170..fd0fdd2 100644
--- a/rpm/redhat/9.4/repmgr/F-21/repmgr.init
+++ b/rpm/redhat/9.4/repmgr/F-21/repmgr.init
@@ -29,32 +29,63 @@ user=repmgr
 prog=repmgrd
 pidfile=/var/run/repmgr/repmgrd-9.4.pid
 lockfile=/var/lock/subsys/$prog
+REPMGRD_ENABLED=no
+REPMGRD_OPTS=
 REPMGRDCONF=/etc/repmgr/9.4/repmgr.conf
 REPMGRDLOG=/var/log/repmgr/repmgrd-9.4.log
 
 # Get config.
 . /etc/sysconfig/network
 
+# Read configuration variable file if it is present
+[ -r /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
+
+# For SELinux we need to use 'runuser' not 'su'
+if [ -x /sbin/runuser ]
+then
+    SU=runuser
+else
+    SU=su
+fi
+
+test -x $exec || exit 0
+
+case "$REPMGRD_ENABLED" in
+    [Yy]*)
+	break
+	;;
+    *)
+	exit 0
+	;;
+esac
+
+if [ -z "${REPMGRD_OPTS}" ]
+then
+    echo "Not starting ${prog}, REPMGRD_OPTS not set in /etc/sysconfig/${prog}"
+    exit 0
+fi
+
 # Check that networking is up.
 [ "${NETWORKING}" = "no" ] && exit 6
 start(){
         [ -x $exec ] || exit 5
-        [ -f "$REPMGRDCONF" ] || exit 6
+        [ -f "${REPMGRDCONF}" ] || exit 6
         echo -n "Starting $prog: "
 
         # Make sure startup-time log file is valid
-        if [ ! -e "$REPMGRDLOG" -a ! -h "$REPMGRDLOG" ]
+        if [ ! -e "${REPMGRDLOG}" -a ! -h "${REPMGRDLOG}" ]
         then
-                touch "$REPMGRDLOG" || exit 1
-                chown $user: "$REPMGRDLOG"
-                chmod go-rwx "$REPMGRDLOG"
-                [ -x /usr/bin/chcon ] && /usr/bin/chcon -u system_u -r object_r -t postgresql_log_t "$REPMGRDLOG" 2>/dev/null
+                touch "${REPMGRDLOG}" || exit 1
+                chown $user: "${REPMGRDLOG}"
+                chmod go-rwx "${REPMGRDLOG}"
+                [ -x /usr/bin/chcon ] && /usr/bin/chcon -u system_u -r object_r -t postgresql_log_t "${REPMGRDLOG}" 2>/dev/null
         fi
 
         mkdir -p $(dirname $pidfile)
         chown $user: $(dirname $pidfile)
 
-	su -l repmgr -c "$exec -f $REPMGRDCONF -p $pidfile -d ->> $REPMGRDLOG 2>&1" $user # --monitoring-history --verbose
+	${SU} -l -c "${exec} -f ${REPMGR_CONF} ${REPMGRD_OPTS} -p ${pidfile} >> ${REPMGRDLOG} 2>&1" ${user} < /dev/null
+	sleep 2
         retval=$?
 	[ $retval -eq 0 ] && success 
         echo
diff --git a/rpm/redhat/9.4/repmgr/F-22/repmgr.init b/rpm/redhat/9.4/repmgr/F-22/repmgr.init
index c900170..fd0fdd2 100644
--- a/rpm/redhat/9.4/repmgr/F-22/repmgr.init
+++ b/rpm/redhat/9.4/repmgr/F-22/repmgr.init
@@ -29,32 +29,63 @@ user=repmgr
 prog=repmgrd
 pidfile=/var/run/repmgr/repmgrd-9.4.pid
 lockfile=/var/lock/subsys/$prog
+REPMGRD_ENABLED=no
+REPMGRD_OPTS=
 REPMGRDCONF=/etc/repmgr/9.4/repmgr.conf
 REPMGRDLOG=/var/log/repmgr/repmgrd-9.4.log
 
 # Get config.
 . /etc/sysconfig/network
 
+# Read configuration variable file if it is present
+[ -r /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
+
+# For SELinux we need to use 'runuser' not 'su'
+if [ -x /sbin/runuser ]
+then
+    SU=runuser
+else
+    SU=su
+fi
+
+test -x $exec || exit 0
+
+case "$REPMGRD_ENABLED" in
+    [Yy]*)
+	break
+	;;
+    *)
+	exit 0
+	;;
+esac
+
+if [ -z "${REPMGRD_OPTS}" ]
+then
+    echo "Not starting ${prog}, REPMGRD_OPTS not set in /etc/sysconfig/${prog}"
+    exit 0
+fi
+
 # Check that networking is up.
 [ "${NETWORKING}" = "no" ] && exit 6
 start(){
         [ -x $exec ] || exit 5
-        [ -f "$REPMGRDCONF" ] || exit 6
+        [ -f "${REPMGRDCONF}" ] || exit 6
         echo -n "Starting $prog: "
 
         # Make sure startup-time log file is valid
-        if [ ! -e "$REPMGRDLOG" -a ! -h "$REPMGRDLOG" ]
+        if [ ! -e "${REPMGRDLOG}" -a ! -h "${REPMGRDLOG}" ]
         then
-                touch "$REPMGRDLOG" || exit 1
-                chown $user: "$REPMGRDLOG"
-                chmod go-rwx "$REPMGRDLOG"
-                [ -x /usr/bin/chcon ] && /usr/bin/chcon -u system_u -r object_r -t postgresql_log_t "$REPMGRDLOG" 2>/dev/null
+                touch "${REPMGRDLOG}" || exit 1
+                chown $user: "${REPMGRDLOG}"
+                chmod go-rwx "${REPMGRDLOG}"
+                [ -x /usr/bin/chcon ] && /usr/bin/chcon -u system_u -r object_r -t postgresql_log_t "${REPMGRDLOG}" 2>/dev/null
         fi
 
         mkdir -p $(dirname $pidfile)
         chown $user: $(dirname $pidfile)
 
-	su -l repmgr -c "$exec -f $REPMGRDCONF -p $pidfile -d ->> $REPMGRDLOG 2>&1" $user # --monitoring-history --verbose
+	${SU} -l -c "${exec} -f ${REPMGR_CONF} ${REPMGRD_OPTS} -p ${pidfile} >> ${REPMGRDLOG} 2>&1" ${user} < /dev/null
+	sleep 2
         retval=$?
 	[ $retval -eq 0 ] && success 
         echo
diff --git a/rpm/redhat/9.4/repmgr/F-23/repmgr.init b/rpm/redhat/9.4/repmgr/F-23/repmgr.init
index c900170..fd0fdd2 100644
--- a/rpm/redhat/9.4/repmgr/F-23/repmgr.init
+++ b/rpm/redhat/9.4/repmgr/F-23/repmgr.init
@@ -29,32 +29,63 @@ user=repmgr
 prog=repmgrd
 pidfile=/var/run/repmgr/repmgrd-9.4.pid
 lockfile=/var/lock/subsys/$prog
+REPMGRD_ENABLED=no
+REPMGRD_OPTS=
 REPMGRDCONF=/etc/repmgr/9.4/repmgr.conf
 REPMGRDLOG=/var/log/repmgr/repmgrd-9.4.log
 
 # Get config.
 . /etc/sysconfig/network
 
+# Read configuration variable file if it is present
+[ -r /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
+
+# For SELinux we need to use 'runuser' not 'su'
+if [ -x /sbin/runuser ]
+then
+    SU=runuser
+else
+    SU=su
+fi
+
+test -x $exec || exit 0
+
+case "$REPMGRD_ENABLED" in
+    [Yy]*)
+	break
+	;;
+    *)
+	exit 0
+	;;
+esac
+
+if [ -z "${REPMGRD_OPTS}" ]
+then
+    echo "Not starting ${prog}, REPMGRD_OPTS not set in /etc/sysconfig/${prog}"
+    exit 0
+fi
+
 # Check that networking is up.
 [ "${NETWORKING}" = "no" ] && exit 6
 start(){
         [ -x $exec ] || exit 5
-        [ -f "$REPMGRDCONF" ] || exit 6
+        [ -f "${REPMGRDCONF}" ] || exit 6
         echo -n "Starting $prog: "
 
         # Make sure startup-time log file is valid
-        if [ ! -e "$REPMGRDLOG" -a ! -h "$REPMGRDLOG" ]
+        if [ ! -e "${REPMGRDLOG}" -a ! -h "${REPMGRDLOG}" ]
         then
-                touch "$REPMGRDLOG" || exit 1
-                chown $user: "$REPMGRDLOG"
-                chmod go-rwx "$REPMGRDLOG"
-                [ -x /usr/bin/chcon ] && /usr/bin/chcon -u system_u -r object_r -t postgresql_log_t "$REPMGRDLOG" 2>/dev/null
+                touch "${REPMGRDLOG}" || exit 1
+                chown $user: "${REPMGRDLOG}"
+                chmod go-rwx "${REPMGRDLOG}"
+                [ -x /usr/bin/chcon ] && /usr/bin/chcon -u system_u -r object_r -t postgresql_log_t "${REPMGRDLOG}" 2>/dev/null
         fi
 
         mkdir -p $(dirname $pidfile)
         chown $user: $(dirname $pidfile)
 
-	su -l repmgr -c "$exec -f $REPMGRDCONF -p $pidfile -d ->> $REPMGRDLOG 2>&1" $user # --monitoring-history --verbose
+	${SU} -l -c "${exec} -f ${REPMGR_CONF} ${REPMGRD_OPTS} -p ${pidfile} >> ${REPMGRDLOG} 2>&1" ${user} < /dev/null
+	sleep 2
         retval=$?
 	[ $retval -eq 0 ] && success 
         echo
diff --git a/rpm/redhat/9.5/repmgr/EL-5/repmgr.init b/rpm/redhat/9.5/repmgr/EL-5/repmgr.init
index b52ce41..f9b402d 100644
--- a/rpm/redhat/9.5/repmgr/EL-5/repmgr.init
+++ b/rpm/redhat/9.5/repmgr/EL-5/repmgr.init
@@ -29,32 +29,63 @@ user=repmgr
 prog=repmgrd
 pidfile=/var/run/repmgr/repmgrd-9.5.pid
 lockfile=/var/lock/subsys/$prog
+REPMGRD_ENABLED=no
+REPMGRD_OPTS=
 REPMGRDCONF=/etc/repmgr/9.5/repmgr.conf
 REPMGRDLOG=/var/log/repmgr/repmgrd-9.5.log
 
 # Get config.
 . /etc/sysconfig/network
 
+# Read configuration variable file if it is present
+[ -r /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
+
+# For SELinux we need to use 'runuser' not 'su'
+if [ -x /sbin/runuser ]
+then
+    SU=runuser
+else
+    SU=su
+fi
+
+test -x $exec || exit 0
+
+case "$REPMGRD_ENABLED" in
+    [Yy]*)
+	break
+	;;
+    *)
+	exit 0
+	;;
+esac
+
+if [ -z "${REPMGRD_OPTS}" ]
+then
+    echo "Not starting ${prog}, REPMGRD_OPTS not set in /etc/sysconfig/${prog}"
+    exit 0
+fi
+
 # Check that networking is up.
 [ "${NETWORKING}" = "no" ] && exit 6
 start(){
         [ -x $exec ] || exit 5
-        [ -f "$REPMGRDCONF" ] || exit 6
+        [ -f "${REPMGRDCONF}" ] || exit 6
         echo -n "Starting $prog: "
 
         # Make sure startup-time log file is valid
-        if [ ! -e "$REPMGRDLOG" -a ! -h "$REPMGRDLOG" ]
+        if [ ! -e "${REPMGRDLOG}" -a ! -h "${REPMGRDLOG}" ]
         then
-                touch "$REPMGRDLOG" || exit 1
-                chown $user: "$REPMGRDLOG"
-                chmod go-rwx "$REPMGRDLOG"
-                [ -x /usr/bin/chcon ] && /usr/bin/chcon -u system_u -r object_r -t postgresql_log_t "$REPMGRDLOG" 2>/dev/null
+                touch "${REPMGRDLOG}" || exit 1
+                chown $user: "${REPMGRDLOG}"
+                chmod go-rwx "${REPMGRDLOG}"
+                [ -x /usr/bin/chcon ] && /usr/bin/chcon -u system_u -r object_r -t postgresql_log_t "${REPMGRDLOG}" 2>/dev/null
         fi
 
         mkdir -p $(dirname $pidfile)
         chown $user: $(dirname $pidfile)
 
-	su -l $user -c "$exec -f $REPMGRDCONF -p $pidfile -d ->> $REPMGRDLOG 2>&1" $user # --monitoring-history --verbose
+	${SU} -l -c "${exec} -f ${REPMGR_CONF} ${REPMGRD_OPTS} -p ${pidfile} >> ${REPMGRDLOG} 2>&1" ${user} < /dev/null
+	sleep 2
         retval=$?
 	[ $retval -eq 0 ] && success 
         echo
diff --git a/rpm/redhat/9.5/repmgr/EL-5/repmgrd.sysconfig b/rpm/redhat/9.5/repmgr/EL-5/repmgrd.sysconfig
new file mode 100644
index 0000000..e9c5aa9
--- /dev/null
+++ b/rpm/redhat/9.5/repmgr/EL-5/repmgrd.sysconfig
@@ -0,0 +1,24 @@
+# default settings for repmgrd. This file is source by /bin/sh from
+# /etc/init.d/repmgrd
+
+# disable repmgrd by default so it won't get started upon installation
+# valid values: yes/no
+REPMGRD_ENABLED=no
+
+# Repmgr conf file
+REPMGR_CONF=/var/lib/pgsql/repmgr/repmgr.conf
+
+# Options for repmgrd (required)
+#REPMGRD_OPTS="--verbose -d "
+
+# User to run repmgrd as
+#REPMGRD_USER=postgres
+
+# repmgrd binary
+#REPMGRD_BIN=/usr/bin/repmgrd
+
+# pid file
+#REPMGRD_PIDFILE=/var/lib/pgsql/repmgr/repmgrd.pid
+
+# log file
+#REPMGRD_LOG=/var/lib/pgsql/repmgr/repmgrd.log
diff --git a/rpm/redhat/9.5/repmgr/EL-6/repmgr.init b/rpm/redhat/9.5/repmgr/EL-6/repmgr.init
index b52ce41..f9b402d 100644
--- a/rpm/redhat/9.5/repmgr/EL-6/repmgr.init
+++ b/rpm/redhat/9.5/repmgr/EL-6/repmgr.init
@@ -29,32 +29,63 @@ user=repmgr
 prog=repmgrd
 pidfile=/var/run/repmgr/repmgrd-9.5.pid
 lockfile=/var/lock/subsys/$prog
+REPMGRD_ENABLED=no
+REPMGRD_OPTS=
 REPMGRDCONF=/etc/repmgr/9.5/repmgr.conf
 REPMGRDLOG=/var/log/repmgr/repmgrd-9.5.log
 
 # Get config.
 . /etc/sysconfig/network
 
+# Read configuration variable file if it is present
+[ -r /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
+
+# For SELinux we need to use 'runuser' not 'su'
+if [ -x /sbin/runuser ]
+then
+    SU=runuser
+else
+    SU=su
+fi
+
+test -x $exec || exit 0
+
+case "$REPMGRD_ENABLED" in
+    [Yy]*)
+	break
+	;;
+    *)
+	exit 0
+	;;
+esac
+
+if [ -z "${REPMGRD_OPTS}" ]
+then
+    echo "Not starting ${prog}, REPMGRD_OPTS not set in /etc/sysconfig/${prog}"
+    exit 0
+fi
+
 # Check that networking is up.
 [ "${NETWORKING}" = "no" ] && exit 6
 start(){
         [ -x $exec ] || exit 5
-        [ -f "$REPMGRDCONF" ] || exit 6
+        [ -f "${REPMGRDCONF}" ] || exit 6
         echo -n "Starting $prog: "
 
         # Make sure startup-time log file is valid
-        if [ ! -e "$REPMGRDLOG" -a ! -h "$REPMGRDLOG" ]
+        if [ ! -e "${REPMGRDLOG}" -a ! -h "${REPMGRDLOG}" ]
         then
-                touch "$REPMGRDLOG" || exit 1
-                chown $user: "$REPMGRDLOG"
-                chmod go-rwx "$REPMGRDLOG"
-                [ -x /usr/bin/chcon ] && /usr/bin/chcon -u system_u -r object_r -t postgresql_log_t "$REPMGRDLOG" 2>/dev/null
+                touch "${REPMGRDLOG}" || exit 1
+                chown $user: "${REPMGRDLOG}"
+                chmod go-rwx "${REPMGRDLOG}"
+                [ -x /usr/bin/chcon ] && /usr/bin/chcon -u system_u -r object_r -t postgresql_log_t "${REPMGRDLOG}" 2>/dev/null
         fi
 
         mkdir -p $(dirname $pidfile)
         chown $user: $(dirname $pidfile)
 
-	su -l $user -c "$exec -f $REPMGRDCONF -p $pidfile -d ->> $REPMGRDLOG 2>&1" $user # --monitoring-history --verbose
+	${SU} -l -c "${exec} -f ${REPMGR_CONF} ${REPMGRD_OPTS} -p ${pidfile} >> ${REPMGRDLOG} 2>&1" ${user} < /dev/null
+	sleep 2
         retval=$?
 	[ $retval -eq 0 ] && success 
         echo
diff --git a/rpm/redhat/9.5/repmgr/EL-6/repmgrd.sysconfig b/rpm/redhat/9.5/repmgr/EL-6/repmgrd.sysconfig
new file mode 100644
index 0000000..e9c5aa9
--- /dev/null
+++ b/rpm/redhat/9.5/repmgr/EL-6/repmgrd.sysconfig
@@ -0,0 +1,24 @@
+# default settings for repmgrd. This file is source by /bin/sh from
+# /etc/init.d/repmgrd
+
+# disable repmgrd by default so it won't get started upon installation
+# valid values: yes/no
+REPMGRD_ENABLED=no
+
+# Repmgr conf file
+REPMGR_CONF=/var/lib/pgsql/repmgr/repmgr.conf
+
+# Options for repmgrd (required)
+#REPMGRD_OPTS="--verbose -d "
+
+# User to run repmgrd as
+#REPMGRD_USER=postgres
+
+# repmgrd binary
+#REPMGRD_BIN=/usr/bin/repmgrd
+
+# pid file
+#REPMGRD_PIDFILE=/var/lib/pgsql/repmgr/repmgrd.pid
+
+# log file
+#REPMGRD_LOG=/var/lib/pgsql/repmgr/repmgrd.log
diff --git a/rpm/redhat/9.5/repmgr/EL-7/repmgr.init b/rpm/redhat/9.5/repmgr/EL-7/repmgr.init
index b52ce41..f9b402d 100644
--- a/rpm/redhat/9.5/repmgr/EL-7/repmgr.init
+++ b/rpm/redhat/9.5/repmgr/EL-7/repmgr.init
@@ -29,32 +29,63 @@ user=repmgr
 prog=repmgrd
 pidfile=/var/run/repmgr/repmgrd-9.5.pid
 lockfile=/var/lock/subsys/$prog
+REPMGRD_ENABLED=no
+REPMGRD_OPTS=
 REPMGRDCONF=/etc/repmgr/9.5/repmgr.conf
 REPMGRDLOG=/var/log/repmgr/repmgrd-9.5.log
 
 # Get config.
 . /etc/sysconfig/network
 
+# Read configuration variable file if it is present
+[ -r /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
+
+# For SELinux we need to use 'runuser' not 'su'
+if [ -x /sbin/runuser ]
+then
+    SU=runuser
+else
+    SU=su
+fi
+
+test -x $exec || exit 0
+
+case "$REPMGRD_ENABLED" in
+    [Yy]*)
+	break
+	;;
+    *)
+	exit 0
+	;;
+esac
+
+if [ -z "${REPMGRD_OPTS}" ]
+then
+    echo "Not starting ${prog}, REPMGRD_OPTS not set in /etc/sysconfig/${prog}"
+    exit 0
+fi
+
 # Check that networking is up.
 [ "${NETWORKING}" = "no" ] && exit 6
 start(){
         [ -x $exec ] || exit 5
-        [ -f "$REPMGRDCONF" ] || exit 6
+        [ -f "${REPMGRDCONF}" ] || exit 6
         echo -n "Starting $prog: "
 
         # Make sure startup-time log file is valid
-        if [ ! -e "$REPMGRDLOG" -a ! -h "$REPMGRDLOG" ]
+        if [ ! -e "${REPMGRDLOG}" -a ! -h "${REPMGRDLOG}" ]
         then
-                touch "$REPMGRDLOG" || exit 1
-                chown $user: "$REPMGRDLOG"
-                chmod go-rwx "$REPMGRDLOG"
-                [ -x /usr/bin/chcon ] && /usr/bin/chcon -u system_u -r object_r -t postgresql_log_t "$REPMGRDLOG" 2>/dev/null
+                touch "${REPMGRDLOG}" || exit 1
+                chown $user: "${REPMGRDLOG}"
+                chmod go-rwx "${REPMGRDLOG}"
+                [ -x /usr/bin/chcon ] && /usr/bin/chcon -u system_u -r object_r -t postgresql_log_t "${REPMGRDLOG}" 2>/dev/null
         fi
 
         mkdir -p $(dirname $pidfile)
         chown $user: $(dirname $pidfile)
 
-	su -l $user -c "$exec -f $REPMGRDCONF -p $pidfile -d ->> $REPMGRDLOG 2>&1" $user # --monitoring-history --verbose
+	${SU} -l -c "${exec} -f ${REPMGR_CONF} ${REPMGRD_OPTS} -p ${pidfile} >> ${REPMGRDLOG} 2>&1" ${user} < /dev/null
+	sleep 2
         retval=$?
 	[ $retval -eq 0 ] && success 
         echo
diff --git a/rpm/redhat/9.5/repmgr/EL-7/repmgrd.sysconfig b/rpm/redhat/9.5/repmgr/EL-7/repmgrd.sysconfig
new file mode 100644
index 0000000..e9c5aa9
--- /dev/null
+++ b/rpm/redhat/9.5/repmgr/EL-7/repmgrd.sysconfig
@@ -0,0 +1,24 @@
+# default settings for repmgrd. This file is source by /bin/sh from
+# /etc/init.d/repmgrd
+
+# disable repmgrd by default so it won't get started upon installation
+# valid values: yes/no
+REPMGRD_ENABLED=no
+
+# Repmgr conf file
+REPMGR_CONF=/var/lib/pgsql/repmgr/repmgr.conf
+
+# Options for repmgrd (required)
+#REPMGRD_OPTS="--verbose -d "
+
+# User to run repmgrd as
+#REPMGRD_USER=postgres
+
+# repmgrd binary
+#REPMGRD_BIN=/usr/bin/repmgrd
+
+# pid file
+#REPMGRD_PIDFILE=/var/lib/pgsql/repmgr/repmgrd.pid
+
+# log file
+#REPMGRD_LOG=/var/lib/pgsql/repmgr/repmgrd.log
diff --git a/rpm/redhat/9.5/repmgr/F-20/repmgr.init b/rpm/redhat/9.5/repmgr/F-20/repmgr.init
index b52ce41..f9b402d 100644
--- a/rpm/redhat/9.5/repmgr/F-20/repmgr.init
+++ b/rpm/redhat/9.5/repmgr/F-20/repmgr.init
@@ -29,32 +29,63 @@ user=repmgr
 prog=repmgrd
 pidfile=/var/run/repmgr/repmgrd-9.5.pid
 lockfile=/var/lock/subsys/$prog
+REPMGRD_ENABLED=no
+REPMGRD_OPTS=
 REPMGRDCONF=/etc/repmgr/9.5/repmgr.conf
 REPMGRDLOG=/var/log/repmgr/repmgrd-9.5.log
 
 # Get config.
 . /etc/sysconfig/network
 
+# Read configuration variable file if it is present
+[ -r /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
+
+# For SELinux we need to use 'runuser' not 'su'
+if [ -x /sbin/runuser ]
+then
+    SU=runuser
+else
+    SU=su
+fi
+
+test -x $exec || exit 0
+
+case "$REPMGRD_ENABLED" in
+    [Yy]*)
+	break
+	;;
+    *)
+	exit 0
+	;;
+esac
+
+if [ -z "${REPMGRD_OPTS}" ]
+then
+    echo "Not starting ${prog}, REPMGRD_OPTS not set in /etc/sysconfig/${prog}"
+    exit 0
+fi
+
 # Check that networking is up.
 [ "${NETWORKING}" = "no" ] && exit 6
 start(){
         [ -x $exec ] || exit 5
-        [ -f "$REPMGRDCONF" ] || exit 6
+        [ -f "${REPMGRDCONF}" ] || exit 6
         echo -n "Starting $prog: "
 
         # Make sure startup-time log file is valid
-        if [ ! -e "$REPMGRDLOG" -a ! -h "$REPMGRDLOG" ]
+        if [ ! -e "${REPMGRDLOG}" -a ! -h "${REPMGRDLOG}" ]
         then
-                touch "$REPMGRDLOG" || exit 1
-                chown $user: "$REPMGRDLOG"
-                chmod go-rwx "$REPMGRDLOG"
-                [ -x /usr/bin/chcon ] && /usr/bin/chcon -u system_u -r object_r -t postgresql_log_t "$REPMGRDLOG" 2>/dev/null
+                touch "${REPMGRDLOG}" || exit 1
+                chown $user: "${REPMGRDLOG}"
+                chmod go-rwx "${REPMGRDLOG}"
+                [ -x /usr/bin/chcon ] && /usr/bin/chcon -u system_u -r object_r -t postgresql_log_t "${REPMGRDLOG}" 2>/dev/null
         fi
 
         mkdir -p $(dirname $pidfile)
         chown $user: $(dirname $pidfile)
 
-	su -l $user -c "$exec -f $REPMGRDCONF -p $pidfile -d ->> $REPMGRDLOG 2>&1" $user # --monitoring-history --verbose
+	${SU} -l -c "${exec} -f ${REPMGR_CONF} ${REPMGRD_OPTS} -p ${pidfile} >> ${REPMGRDLOG} 2>&1" ${user} < /dev/null
+	sleep 2
         retval=$?
 	[ $retval -eq 0 ] && success 
         echo
diff --git a/rpm/redhat/9.5/repmgr/F-20/repmgrd.sysconfig b/rpm/redhat/9.5/repmgr/F-20/repmgrd.sysconfig
new file mode 100644
index 0000000..e9c5aa9
--- /dev/null
+++ b/rpm/redhat/9.5/repmgr/F-20/repmgrd.sysconfig
@@ -0,0 +1,24 @@
+# default settings for repmgrd. This file is source by /bin/sh from
+# /etc/init.d/repmgrd
+
+# disable repmgrd by default so it won't get started upon installation
+# valid values: yes/no
+REPMGRD_ENABLED=no
+
+# Repmgr conf file
+REPMGR_CONF=/var/lib/pgsql/repmgr/repmgr.conf
+
+# Options for repmgrd (required)
+#REPMGRD_OPTS="--verbose -d "
+
+# User to run repmgrd as
+#REPMGRD_USER=postgres
+
+# repmgrd binary
+#REPMGRD_BIN=/usr/bin/repmgrd
+
+# pid file
+#REPMGRD_PIDFILE=/var/lib/pgsql/repmgr/repmgrd.pid
+
+# log file
+#REPMGRD_LOG=/var/lib/pgsql/repmgr/repmgrd.log
diff --git a/rpm/redhat/9.5/repmgr/F-21/repmgr.init b/rpm/redhat/9.5/repmgr/F-21/repmgr.init
index b52ce41..f9b402d 100644
--- a/rpm/redhat/9.5/repmgr/F-21/repmgr.init
+++ b/rpm/redhat/9.5/repmgr/F-21/repmgr.init
@@ -29,32 +29,63 @@ user=repmgr
 prog=repmgrd
 pidfile=/var/run/repmgr/repmgrd-9.5.pid
 lockfile=/var/lock/subsys/$prog
+REPMGRD_ENABLED=no
+REPMGRD_OPTS=
 REPMGRDCONF=/etc/repmgr/9.5/repmgr.conf
 REPMGRDLOG=/var/log/repmgr/repmgrd-9.5.log
 
 # Get config.
 . /etc/sysconfig/network
 
+# Read configuration variable file if it is present
+[ -r /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
+
+# For SELinux we need to use 'runuser' not 'su'
+if [ -x /sbin/runuser ]
+then
+    SU=runuser
+else
+    SU=su
+fi
+
+test -x $exec || exit 0
+
+case "$REPMGRD_ENABLED" in
+    [Yy]*)
+	break
+	;;
+    *)
+	exit 0
+	;;
+esac
+
+if [ -z "${REPMGRD_OPTS}" ]
+then
+    echo "Not starting ${prog}, REPMGRD_OPTS not set in /etc/sysconfig/${prog}"
+    exit 0
+fi
+
 # Check that networking is up.
 [ "${NETWORKING}" = "no" ] && exit 6
 start(){
         [ -x $exec ] || exit 5
-        [ -f "$REPMGRDCONF" ] || exit 6
+        [ -f "${REPMGRDCONF}" ] || exit 6
         echo -n "Starting $prog: "
 
         # Make sure startup-time log file is valid
-        if [ ! -e "$REPMGRDLOG" -a ! -h "$REPMGRDLOG" ]
+        if [ ! -e "${REPMGRDLOG}" -a ! -h "${REPMGRDLOG}" ]
         then
-                touch "$REPMGRDLOG" || exit 1
-                chown $user: "$REPMGRDLOG"
-                chmod go-rwx "$REPMGRDLOG"
-                [ -x /usr/bin/chcon ] && /usr/bin/chcon -u system_u -r object_r -t postgresql_log_t "$REPMGRDLOG" 2>/dev/null
+                touch "${REPMGRDLOG}" || exit 1
+                chown $user: "${REPMGRDLOG}"
+                chmod go-rwx "${REPMGRDLOG}"
+                [ -x /usr/bin/chcon ] && /usr/bin/chcon -u system_u -r object_r -t postgresql_log_t "${REPMGRDLOG}" 2>/dev/null
         fi
 
         mkdir -p $(dirname $pidfile)
         chown $user: $(dirname $pidfile)
 
-	su -l $user -c "$exec -f $REPMGRDCONF -p $pidfile -d ->> $REPMGRDLOG 2>&1" $user # --monitoring-history --verbose
+	${SU} -l -c "${exec} -f ${REPMGR_CONF} ${REPMGRD_OPTS} -p ${pidfile} >> ${REPMGRDLOG} 2>&1" ${user} < /dev/null
+	sleep 2
         retval=$?
 	[ $retval -eq 0 ] && success 
         echo
diff --git a/rpm/redhat/9.5/repmgr/F-21/repmgrd.sysconfig b/rpm/redhat/9.5/repmgr/F-21/repmgrd.sysconfig
new file mode 100644
index 0000000..e9c5aa9
--- /dev/null
+++ b/rpm/redhat/9.5/repmgr/F-21/repmgrd.sysconfig
@@ -0,0 +1,24 @@
+# default settings for repmgrd. This file is source by /bin/sh from
+# /etc/init.d/repmgrd
+
+# disable repmgrd by default so it won't get started upon installation
+# valid values: yes/no
+REPMGRD_ENABLED=no
+
+# Repmgr conf file
+REPMGR_CONF=/var/lib/pgsql/repmgr/repmgr.conf
+
+# Options for repmgrd (required)
+#REPMGRD_OPTS="--verbose -d "
+
+# User to run repmgrd as
+#REPMGRD_USER=postgres
+
+# repmgrd binary
+#REPMGRD_BIN=/usr/bin/repmgrd
+
+# pid file
+#REPMGRD_PIDFILE=/var/lib/pgsql/repmgr/repmgrd.pid
+
+# log file
+#REPMGRD_LOG=/var/lib/pgsql/repmgr/repmgrd.log
diff --git a/rpm/redhat/9.5/repmgr/F-22/repmgr.init b/rpm/redhat/9.5/repmgr/F-22/repmgr.init
index b52ce41..f9b402d 100644
--- a/rpm/redhat/9.5/repmgr/F-22/repmgr.init
+++ b/rpm/redhat/9.5/repmgr/F-22/repmgr.init
@@ -29,32 +29,63 @@ user=repmgr
 prog=repmgrd
 pidfile=/var/run/repmgr/repmgrd-9.5.pid
 lockfile=/var/lock/subsys/$prog
+REPMGRD_ENABLED=no
+REPMGRD_OPTS=
 REPMGRDCONF=/etc/repmgr/9.5/repmgr.conf
 REPMGRDLOG=/var/log/repmgr/repmgrd-9.5.log
 
 # Get config.
 . /etc/sysconfig/network
 
+# Read configuration variable file if it is present
+[ -r /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
+
+# For SELinux we need to use 'runuser' not 'su'
+if [ -x /sbin/runuser ]
+then
+    SU=runuser
+else
+    SU=su
+fi
+
+test -x $exec || exit 0
+
+case "$REPMGRD_ENABLED" in
+    [Yy]*)
+	break
+	;;
+    *)
+	exit 0
+	;;
+esac
+
+if [ -z "${REPMGRD_OPTS}" ]
+then
+    echo "Not starting ${prog}, REPMGRD_OPTS not set in /etc/sysconfig/${prog}"
+    exit 0
+fi
+
 # Check that networking is up.
 [ "${NETWORKING}" = "no" ] && exit 6
 start(){
         [ -x $exec ] || exit 5
-        [ -f "$REPMGRDCONF" ] || exit 6
+        [ -f "${REPMGRDCONF}" ] || exit 6
         echo -n "Starting $prog: "
 
         # Make sure startup-time log file is valid
-        if [ ! -e "$REPMGRDLOG" -a ! -h "$REPMGRDLOG" ]
+        if [ ! -e "${REPMGRDLOG}" -a ! -h "${REPMGRDLOG}" ]
         then
-                touch "$REPMGRDLOG" || exit 1
-                chown $user: "$REPMGRDLOG"
-                chmod go-rwx "$REPMGRDLOG"
-                [ -x /usr/bin/chcon ] && /usr/bin/chcon -u system_u -r object_r -t postgresql_log_t "$REPMGRDLOG" 2>/dev/null
+                touch "${REPMGRDLOG}" || exit 1
+                chown $user: "${REPMGRDLOG}"
+                chmod go-rwx "${REPMGRDLOG}"
+                [ -x /usr/bin/chcon ] && /usr/bin/chcon -u system_u -r object_r -t postgresql_log_t "${REPMGRDLOG}" 2>/dev/null
         fi
 
         mkdir -p $(dirname $pidfile)
         chown $user: $(dirname $pidfile)
 
-	su -l $user -c "$exec -f $REPMGRDCONF -p $pidfile -d ->> $REPMGRDLOG 2>&1" $user # --monitoring-history --verbose
+	${SU} -l -c "${exec} -f ${REPMGR_CONF} ${REPMGRD_OPTS} -p ${pidfile} >> ${REPMGRDLOG} 2>&1" ${user} < /dev/null
+	sleep 2
         retval=$?
 	[ $retval -eq 0 ] && success 
         echo
diff --git a/rpm/redhat/9.5/repmgr/F-22/repmgrd.sysconfig b/rpm/redhat/9.5/repmgr/F-22/repmgrd.sysconfig
new file mode 100644
index 0000000..e9c5aa9
--- /dev/null
+++ b/rpm/redhat/9.5/repmgr/F-22/repmgrd.sysconfig
@@ -0,0 +1,24 @@
+# default settings for repmgrd. This file is source by /bin/sh from
+# /etc/init.d/repmgrd
+
+# disable repmgrd by default so it won't get started upon installation
+# valid values: yes/no
+REPMGRD_ENABLED=no
+
+# Repmgr conf file
+REPMGR_CONF=/var/lib/pgsql/repmgr/repmgr.conf
+
+# Options for repmgrd (required)
+#REPMGRD_OPTS="--verbose -d "
+
+# User to run repmgrd as
+#REPMGRD_USER=postgres
+
+# repmgrd binary
+#REPMGRD_BIN=/usr/bin/repmgrd
+
+# pid file
+#REPMGRD_PIDFILE=/var/lib/pgsql/repmgr/repmgrd.pid
+
+# log file
+#REPMGRD_LOG=/var/lib/pgsql/repmgr/repmgrd.log
diff --git a/rpm/redhat/9.5/repmgr/F-23/repmgr.init b/rpm/redhat/9.5/repmgr/F-23/repmgr.init
index b52ce41..f9b402d 100644
--- a/rpm/redhat/9.5/repmgr/F-23/repmgr.init
+++ b/rpm/redhat/9.5/repmgr/F-23/repmgr.init
@@ -29,32 +29,63 @@ user=repmgr
 prog=repmgrd
 pidfile=/var/run/repmgr/repmgrd-9.5.pid
 lockfile=/var/lock/subsys/$prog
+REPMGRD_ENABLED=no
+REPMGRD_OPTS=
 REPMGRDCONF=/etc/repmgr/9.5/repmgr.conf
 REPMGRDLOG=/var/log/repmgr/repmgrd-9.5.log
 
 # Get config.
 . /etc/sysconfig/network
 
+# Read configuration variable file if it is present
+[ -r /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
+
+# For SELinux we need to use 'runuser' not 'su'
+if [ -x /sbin/runuser ]
+then
+    SU=runuser
+else
+    SU=su
+fi
+
+test -x $exec || exit 0
+
+case "$REPMGRD_ENABLED" in
+    [Yy]*)
+	break
+	;;
+    *)
+	exit 0
+	;;
+esac
+
+if [ -z "${REPMGRD_OPTS}" ]
+then
+    echo "Not starting ${prog}, REPMGRD_OPTS not set in /etc/sysconfig/${prog}"
+    exit 0
+fi
+
 # Check that networking is up.
 [ "${NETWORKING}" = "no" ] && exit 6
 start(){
         [ -x $exec ] || exit 5
-        [ -f "$REPMGRDCONF" ] || exit 6
+        [ -f "${REPMGRDCONF}" ] || exit 6
         echo -n "Starting $prog: "
 
         # Make sure startup-time log file is valid
-        if [ ! -e "$REPMGRDLOG" -a ! -h "$REPMGRDLOG" ]
+        if [ ! -e "${REPMGRDLOG}" -a ! -h "${REPMGRDLOG}" ]
         then
-                touch "$REPMGRDLOG" || exit 1
-                chown $user: "$REPMGRDLOG"
-                chmod go-rwx "$REPMGRDLOG"
-                [ -x /usr/bin/chcon ] && /usr/bin/chcon -u system_u -r object_r -t postgresql_log_t "$REPMGRDLOG" 2>/dev/null
+                touch "${REPMGRDLOG}" || exit 1
+                chown $user: "${REPMGRDLOG}"
+                chmod go-rwx "${REPMGRDLOG}"
+                [ -x /usr/bin/chcon ] && /usr/bin/chcon -u system_u -r object_r -t postgresql_log_t "${REPMGRDLOG}" 2>/dev/null
         fi
 
         mkdir -p $(dirname $pidfile)
         chown $user: $(dirname $pidfile)
 
-	su -l $user -c "$exec -f $REPMGRDCONF -p $pidfile -d ->> $REPMGRDLOG 2>&1" $user # --monitoring-history --verbose
+	${SU} -l -c "${exec} -f ${REPMGR_CONF} ${REPMGRD_OPTS} -p ${pidfile} >> ${REPMGRDLOG} 2>&1" ${user} < /dev/null
+	sleep 2
         retval=$?
 	[ $retval -eq 0 ] && success 
         echo
diff --git a/rpm/redhat/9.5/repmgr/F-23/repmgrd.sysconfig b/rpm/redhat/9.5/repmgr/F-23/repmgrd.sysconfig
new file mode 100644
index 0000000..e9c5aa9
--- /dev/null
+++ b/rpm/redhat/9.5/repmgr/F-23/repmgrd.sysconfig
@@ -0,0 +1,24 @@
+# default settings for repmgrd. This file is source by /bin/sh from
+# /etc/init.d/repmgrd
+
+# disable repmgrd by default so it won't get started upon installation
+# valid values: yes/no
+REPMGRD_ENABLED=no
+
+# Repmgr conf file
+REPMGR_CONF=/var/lib/pgsql/repmgr/repmgr.conf
+
+# Options for repmgrd (required)
+#REPMGRD_OPTS="--verbose -d "
+
+# User to run repmgrd as
+#REPMGRD_USER=postgres
+
+# repmgrd binary
+#REPMGRD_BIN=/usr/bin/repmgrd
+
+# pid file
+#REPMGRD_PIDFILE=/var/lib/pgsql/repmgr/repmgrd.pid
+
+# log file
+#REPMGRD_LOG=/var/lib/pgsql/repmgr/repmgrd.log
-- 
2.5.0

---

From: Martín Marqués <[email-masked]>
Date: Wed, 30 Dec 2015 18:59:41 -0300

> A patch would definitely speed us up and would be most welcome!

Last patch of the day. The one with changes to the spec file.

Please check them and if there's something to fix let me know and I'll
take care of it next week.

Regards, and happy new year!

>From e87be2010c7dab69ab77ed965f1f9ad5eacef057 Mon Sep 17 00:00:00 2001
From: Martin <[email-masked]>
Date: Wed, 30 Dec 2015 18:52:46 -0300
Subject: [PATCH] Changes to the spec file to fix a few issues: * Missing
 /var/run/repmgr directory used for the PID file * Change user from repmgr to
 postgres

---
 rpm/redhat/9.3/repmgr/EL-5/repmgr.spec | 21 +++++++++++++--------
 rpm/redhat/9.3/repmgr/EL-6/repmgr.spec | 21 +++++++++++++--------
 rpm/redhat/9.3/repmgr/EL-7/repmgr.spec | 21 +++++++++++++--------
 rpm/redhat/9.3/repmgr/F-19/repmgr.spec | 21 +++++++++++++--------
 rpm/redhat/9.3/repmgr/F-20/repmgr.spec | 21 +++++++++++++--------
 rpm/redhat/9.3/repmgr/F-21/repmgr.spec | 21 +++++++++++++--------
 rpm/redhat/9.3/repmgr/F-22/repmgr.spec | 21 +++++++++++++--------
 rpm/redhat/9.3/repmgr/F-23/repmgr.spec | 21 +++++++++++++--------
 rpm/redhat/9.4/repmgr/EL-5/repmgr.spec | 21 +++++++++++++--------
 rpm/redhat/9.4/repmgr/EL-6/repmgr.spec | 21 +++++++++++++--------
 rpm/redhat/9.4/repmgr/EL-7/repmgr.spec | 21 +++++++++++++--------
 rpm/redhat/9.4/repmgr/F-20/repmgr.spec | 21 +++++++++++++--------
 rpm/redhat/9.4/repmgr/F-21/repmgr.spec | 21 +++++++++++++--------
 rpm/redhat/9.4/repmgr/F-22/repmgr.spec | 21 +++++++++++++--------
 rpm/redhat/9.4/repmgr/F-23/repmgr.spec | 21 +++++++++++++--------
 rpm/redhat/9.5/repmgr/EL-5/repmgr.spec | 25 ++++++++++++-------------
 rpm/redhat/9.5/repmgr/EL-6/repmgr.spec | 25 ++++++++++++-------------
 rpm/redhat/9.5/repmgr/EL-7/repmgr.spec | 25 ++++++++++++-------------
 rpm/redhat/9.5/repmgr/F-20/repmgr.spec | 25 ++++++++++++-------------
 rpm/redhat/9.5/repmgr/F-21/repmgr.spec | 25 ++++++++++++-------------
 rpm/redhat/9.5/repmgr/F-22/repmgr.spec | 25 ++++++++++++-------------
 rpm/redhat/9.5/repmgr/F-23/repmgr.spec | 25 ++++++++++++-------------
 22 files changed, 279 insertions(+), 211 deletions(-)

diff --git a/rpm/redhat/9.3/repmgr/EL-5/repmgr.spec b/rpm/redhat/9.3/repmgr/EL-5/repmgr.spec
index 36985e8..9563c90 100644
--- a/rpm/redhat/9.3/repmgr/EL-5/repmgr.spec
+++ b/rpm/redhat/9.3/repmgr/EL-5/repmgr.spec
@@ -12,7 +12,7 @@
 
 Name:           %{sname}%{pgmajorversion}
 Version:        3.0.2
-Release:        1%{?dist}
+Release:        3%{?dist}
 Summary:        Replication Manager for PostgreSQL Clusters
 License:        GPLv3
 URL:            http://www.repmgr.org
@@ -20,7 +20,7 @@ Source0:        http://repmgr.org/download/%{sname}-%{version}.tar.gz
 Source1:	repmgr-%{pgpackageversion}.service
 Source2:	repmgr.init
 Patch0:		repmgr-makefile-pgxs.patch
-Patch1:		repmgr.conf.sample.patch
+#Patch1:		repmgr.conf.sample.patch
 
 %if %{systemd_enabled}
 BuildRequires:		systemd
@@ -62,7 +62,7 @@ future PostgreSQL versions.
 %prep
 %setup -q -n %{sname}-%{version}
 %patch0 -p0
-%patch1 -p0
+#%patch1 -p0
 
 %build
 USE_PGXS=1 %{__make} %{?_smp_mflags}
@@ -97,13 +97,18 @@ install -m 755 %{SOURCE2}  %{buildroot}%{_sysconfdir}/init.d/%{sname}-%{pgpackag
 %endif
 
 %pre
-groupadd -r repmgr >/dev/null 2>&1 || :
-useradd -m -g repmgr -r -s /bin/bash \
-        -c "repmgr" repmgr >/dev/null 2>&1 || :
+groupadd -r postgres >/dev/null 2>&1 || :
+useradd -m -g postgres -r -s /bin/bash \
+        -c "postgres" postgres >/dev/null 2>&1 || :
 if [ ! -x /var/log/repmgr ]
 then
 	%{__mkdir} -m 700 /var/log/repmgr
-	%{__chown} -R repmgr: /var/log/repmgr
+	%{__chown} -R postgres: /var/log/repmgr
+fi
+if [ ! -x /var/run/repmgr ]
+then
+	%{__mkdir} -m 700 /var/run/repmgr
+	%{__chown} -R postgres: /var/run/repmgr
 fi
 
 %post
@@ -115,7 +120,7 @@ fi
 # This adds the proper /etc/rc*.d links for the script
 /sbin/chkconfig --add %{sname}-%{pgpackageversion}
 %endif
-%{__chown} repmgr: %{_localstatedir}/run/%{sname}
+%{__chown} postgres: %{_localstatedir}/run/%{sname}
 
 %postun -p /sbin/ldconfig
 
diff --git a/rpm/redhat/9.3/repmgr/EL-6/repmgr.spec b/rpm/redhat/9.3/repmgr/EL-6/repmgr.spec
index 36985e8..9563c90 100644
--- a/rpm/redhat/9.3/repmgr/EL-6/repmgr.spec
+++ b/rpm/redhat/9.3/repmgr/EL-6/repmgr.spec
@@ -12,7 +12,7 @@
 
 Name:           %{sname}%{pgmajorversion}
 Version:        3.0.2
-Release:        1%{?dist}
+Release:        3%{?dist}
 Summary:        Replication Manager for PostgreSQL Clusters
 License:        GPLv3
 URL:            http://www.repmgr.org
@@ -20,7 +20,7 @@ Source0:        http://repmgr.org/download/%{sname}-%{version}.tar.gz
 Source1:	repmgr-%{pgpackageversion}.service
 Source2:	repmgr.init
 Patch0:		repmgr-makefile-pgxs.patch
-Patch1:		repmgr.conf.sample.patch
+#Patch1:		repmgr.conf.sample.patch
 
 %if %{systemd_enabled}
 BuildRequires:		systemd
@@ -62,7 +62,7 @@ future PostgreSQL versions.
 %prep
 %setup -q -n %{sname}-%{version}
 %patch0 -p0
-%patch1 -p0
+#%patch1 -p0
 
 %build
 USE_PGXS=1 %{__make} %{?_smp_mflags}
@@ -97,13 +97,18 @@ install -m 755 %{SOURCE2}  %{buildroot}%{_sysconfdir}/init.d/%{sname}-%{pgpackag
 %endif
 
 %pre
-groupadd -r repmgr >/dev/null 2>&1 || :
-useradd -m -g repmgr -r -s /bin/bash \
-        -c "repmgr" repmgr >/dev/null 2>&1 || :
+groupadd -r postgres >/dev/null 2>&1 || :
+useradd -m -g postgres -r -s /bin/bash \
+        -c "postgres" postgres >/dev/null 2>&1 || :
 if [ ! -x /var/log/repmgr ]
 then
 	%{__mkdir} -m 700 /var/log/repmgr
-	%{__chown} -R repmgr: /var/log/repmgr
+	%{__chown} -R postgres: /var/log/repmgr
+fi
+if [ ! -x /var/run/repmgr ]
+then
+	%{__mkdir} -m 700 /var/run/repmgr
+	%{__chown} -R postgres: /var/run/repmgr
 fi
 
 %post
@@ -115,7 +120,7 @@ fi
 # This adds the proper /etc/rc*.d links for the script
 /sbin/chkconfig --add %{sname}-%{pgpackageversion}
 %endif
-%{__chown} repmgr: %{_localstatedir}/run/%{sname}
+%{__chown} postgres: %{_localstatedir}/run/%{sname}
 
 %postun -p /sbin/ldconfig
 
diff --git a/rpm/redhat/9.3/repmgr/EL-7/repmgr.spec b/rpm/redhat/9.3/repmgr/EL-7/repmgr.spec
index 36985e8..9563c90 100644
--- a/rpm/redhat/9.3/repmgr/EL-7/repmgr.spec
+++ b/rpm/redhat/9.3/repmgr/EL-7/repmgr.spec
@@ -12,7 +12,7 @@
 
 Name:           %{sname}%{pgmajorversion}
 Version:        3.0.2
-Release:        1%{?dist}
+Release:        3%{?dist}
 Summary:        Replication Manager for PostgreSQL Clusters
 License:        GPLv3
 URL:            http://www.repmgr.org
@@ -20,7 +20,7 @@ Source0:        http://repmgr.org/download/%{sname}-%{version}.tar.gz
 Source1:	repmgr-%{pgpackageversion}.service
 Source2:	repmgr.init
 Patch0:		repmgr-makefile-pgxs.patch
-Patch1:		repmgr.conf.sample.patch
+#Patch1:		repmgr.conf.sample.patch
 
 %if %{systemd_enabled}
 BuildRequires:		systemd
@@ -62,7 +62,7 @@ future PostgreSQL versions.
 %prep
 %setup -q -n %{sname}-%{version}
 %patch0 -p0
-%patch1 -p0
+#%patch1 -p0
 
 %build
 USE_PGXS=1 %{__make} %{?_smp_mflags}
@@ -97,13 +97,18 @@ install -m 755 %{SOURCE2}  %{buildroot}%{_sysconfdir}/init.d/%{sname}-%{pgpackag
 %endif
 
 %pre
-groupadd -r repmgr >/dev/null 2>&1 || :
-useradd -m -g repmgr -r -s /bin/bash \
-        -c "repmgr" repmgr >/dev/null 2>&1 || :
+groupadd -r postgres >/dev/null 2>&1 || :
+useradd -m -g postgres -r -s /bin/bash \
+        -c "postgres" postgres >/dev/null 2>&1 || :
 if [ ! -x /var/log/repmgr ]
 then
 	%{__mkdir} -m 700 /var/log/repmgr
-	%{__chown} -R repmgr: /var/log/repmgr
+	%{__chown} -R postgres: /var/log/repmgr
+fi
+if [ ! -x /var/run/repmgr ]
+then
+	%{__mkdir} -m 700 /var/run/repmgr
+	%{__chown} -R postgres: /var/run/repmgr
 fi
 
 %post
@@ -115,7 +120,7 @@ fi
 # This adds the proper /etc/rc*.d links for the script
 /sbin/chkconfig --add %{sname}-%{pgpackageversion}
 %endif
-%{__chown} repmgr: %{_localstatedir}/run/%{sname}
+%{__chown} postgres: %{_localstatedir}/run/%{sname}
 
 %postun -p /sbin/ldconfig
 
diff --git a/rpm/redhat/9.3/repmgr/F-19/repmgr.spec b/rpm/redhat/9.3/repmgr/F-19/repmgr.spec
index 36985e8..9563c90 100644
--- a/rpm/redhat/9.3/repmgr/F-19/repmgr.spec
+++ b/rpm/redhat/9.3/repmgr/F-19/repmgr.spec
@@ -12,7 +12,7 @@
 
 Name:           %{sname}%{pgmajorversion}
 Version:        3.0.2
-Release:        1%{?dist}
+Release:        3%{?dist}
 Summary:        Replication Manager for PostgreSQL Clusters
 License:        GPLv3
 URL:            http://www.repmgr.org
@@ -20,7 +20,7 @@ Source0:        http://repmgr.org/download/%{sname}-%{version}.tar.gz
 Source1:	repmgr-%{pgpackageversion}.service
 Source2:	repmgr.init
 Patch0:		repmgr-makefile-pgxs.patch
-Patch1:		repmgr.conf.sample.patch
+#Patch1:		repmgr.conf.sample.patch
 
 %if %{systemd_enabled}
 BuildRequires:		systemd
@@ -62,7 +62,7 @@ future PostgreSQL versions.
 %prep
 %setup -q -n %{sname}-%{version}
 %patch0 -p0
-%patch1 -p0
+#%patch1 -p0
 
 %build
 USE_PGXS=1 %{__make} %{?_smp_mflags}
@@ -97,13 +97,18 @@ install -m 755 %{SOURCE2}  %{buildroot}%{_sysconfdir}/init.d/%{sname}-%{pgpackag
 %endif
 
 %pre
-groupadd -r repmgr >/dev/null 2>&1 || :
-useradd -m -g repmgr -r -s /bin/bash \
-        -c "repmgr" repmgr >/dev/null 2>&1 || :
+groupadd -r postgres >/dev/null 2>&1 || :
+useradd -m -g postgres -r -s /bin/bash \
+        -c "postgres" postgres >/dev/null 2>&1 || :
 if [ ! -x /var/log/repmgr ]
 then
 	%{__mkdir} -m 700 /var/log/repmgr
-	%{__chown} -R repmgr: /var/log/repmgr
+	%{__chown} -R postgres: /var/log/repmgr
+fi
+if [ ! -x /var/run/repmgr ]
+then
+	%{__mkdir} -m 700 /var/run/repmgr
+	%{__chown} -R postgres: /var/run/repmgr
 fi
 
 %post
@@ -115,7 +120,7 @@ fi
 # This adds the proper /etc/rc*.d links for the script
 /sbin/chkconfig --add %{sname}-%{pgpackageversion}
 %endif
-%{__chown} repmgr: %{_localstatedir}/run/%{sname}
+%{__chown} postgres: %{_localstatedir}/run/%{sname}
 
 %postun -p /sbin/ldconfig
 
diff --git a/rpm/redhat/9.3/repmgr/F-20/repmgr.spec b/rpm/redhat/9.3/repmgr/F-20/repmgr.spec
index 36985e8..9563c90 100644
--- a/rpm/redhat/9.3/repmgr/F-20/repmgr.spec
+++ b/rpm/redhat/9.3/repmgr/F-20/repmgr.spec
@@ -12,7 +12,7 @@
 
 Name:           %{sname}%{pgmajorversion}
 Version:        3.0.2
-Release:        1%{?dist}
+Release:        3%{?dist}
 Summary:        Replication Manager for PostgreSQL Clusters
 License:        GPLv3
 URL:            http://www.repmgr.org
@@ -20,7 +20,7 @@ Source0:        http://repmgr.org/download/%{sname}-%{version}.tar.gz
 Source1:	repmgr-%{pgpackageversion}.service
 Source2:	repmgr.init
 Patch0:		repmgr-makefile-pgxs.patch
-Patch1:		repmgr.conf.sample.patch
+#Patch1:		repmgr.conf.sample.patch
 
 %if %{systemd_enabled}
 BuildRequires:		systemd
@@ -62,7 +62,7 @@ future PostgreSQL versions.
 %prep
 %setup -q -n %{sname}-%{version}
 %patch0 -p0
-%patch1 -p0
+#%patch1 -p0
 
 %build
 USE_PGXS=1 %{__make} %{?_smp_mflags}
@@ -97,13 +97,18 @@ install -m 755 %{SOURCE2}  %{buildroot}%{_sysconfdir}/init.d/%{sname}-%{pgpackag
 %endif
 
 %pre
-groupadd -r repmgr >/dev/null 2>&1 || :
-useradd -m -g repmgr -r -s /bin/bash \
-        -c "repmgr" repmgr >/dev/null 2>&1 || :
+groupadd -r postgres >/dev/null 2>&1 || :
+useradd -m -g postgres -r -s /bin/bash \
+        -c "postgres" postgres >/dev/null 2>&1 || :
 if [ ! -x /var/log/repmgr ]
 then
 	%{__mkdir} -m 700 /var/log/repmgr
-	%{__chown} -R repmgr: /var/log/repmgr
+	%{__chown} -R postgres: /var/log/repmgr
+fi
+if [ ! -x /var/run/repmgr ]
+then
+	%{__mkdir} -m 700 /var/run/repmgr
+	%{__chown} -R postgres: /var/run/repmgr
 fi
 
 %post
@@ -115,7 +120,7 @@ fi
 # This adds the proper /etc/rc*.d links for the script
 /sbin/chkconfig --add %{sname}-%{pgpackageversion}
 %endif
-%{__chown} repmgr: %{_localstatedir}/run/%{sname}
+%{__chown} postgres: %{_localstatedir}/run/%{sname}
 
 %postun -p /sbin/ldconfig
 
diff --git a/rpm/redhat/9.3/repmgr/F-21/repmgr.spec b/rpm/redhat/9.3/repmgr/F-21/repmgr.spec
index 36985e8..9563c90 100644
--- a/rpm/redhat/9.3/repmgr/F-21/repmgr.spec
+++ b/rpm/redhat/9.3/repmgr/F-21/repmgr.spec
@@ -12,7 +12,7 @@
 
 Name:           %{sname}%{pgmajorversion}
 Version:        3.0.2
-Release:        1%{?dist}
+Release:        3%{?dist}
 Summary:        Replication Manager for PostgreSQL Clusters
 License:        GPLv3
 URL:            http://www.repmgr.org
@@ -20,7 +20,7 @@ Source0:        http://repmgr.org/download/%{sname}-%{version}.tar.gz
 Source1:	repmgr-%{pgpackageversion}.service
 Source2:	repmgr.init
 Patch0:		repmgr-makefile-pgxs.patch
-Patch1:		repmgr.conf.sample.patch
+#Patch1:		repmgr.conf.sample.patch
 
 %if %{systemd_enabled}
 BuildRequires:		systemd
@@ -62,7 +62,7 @@ future PostgreSQL versions.
 %prep
 %setup -q -n %{sname}-%{version}
 %patch0 -p0
-%patch1 -p0
+#%patch1 -p0
 
 %build
 USE_PGXS=1 %{__make} %{?_smp_mflags}
@@ -97,13 +97,18 @@ install -m 755 %{SOURCE2}  %{buildroot}%{_sysconfdir}/init.d/%{sname}-%{pgpackag
 %endif
 
 %pre
-groupadd -r repmgr >/dev/null 2>&1 || :
-useradd -m -g repmgr -r -s /bin/bash \
-        -c "repmgr" repmgr >/dev/null 2>&1 || :
+groupadd -r postgres >/dev/null 2>&1 || :
+useradd -m -g postgres -r -s /bin/bash \
+        -c "postgres" postgres >/dev/null 2>&1 || :
 if [ ! -x /var/log/repmgr ]
 then
 	%{__mkdir} -m 700 /var/log/repmgr
-	%{__chown} -R repmgr: /var/log/repmgr
+	%{__chown} -R postgres: /var/log/repmgr
+fi
+if [ ! -x /var/run/repmgr ]
+then
+	%{__mkdir} -m 700 /var/run/repmgr
+	%{__chown} -R postgres: /var/run/repmgr
 fi
 
 %post
@@ -115,7 +120,7 @@ fi
 # This adds the proper /etc/rc*.d links for the script
 /sbin/chkconfig --add %{sname}-%{pgpackageversion}
 %endif
-%{__chown} repmgr: %{_localstatedir}/run/%{sname}
+%{__chown} postgres: %{_localstatedir}/run/%{sname}
 
 %postun -p /sbin/ldconfig
 
diff --git a/rpm/redhat/9.3/repmgr/F-22/repmgr.spec b/rpm/redhat/9.3/repmgr/F-22/repmgr.spec
index 36985e8..9563c90 100644
--- a/rpm/redhat/9.3/repmgr/F-22/repmgr.spec
+++ b/rpm/redhat/9.3/repmgr/F-22/repmgr.spec
@@ -12,7 +12,7 @@
 
 Name:           %{sname}%{pgmajorversion}
 Version:        3.0.2
-Release:        1%{?dist}
+Release:        3%{?dist}
 Summary:        Replication Manager for PostgreSQL Clusters
 License:        GPLv3
 URL:            http://www.repmgr.org
@@ -20,7 +20,7 @@ Source0:        http://repmgr.org/download/%{sname}-%{version}.tar.gz
 Source1:	repmgr-%{pgpackageversion}.service
 Source2:	repmgr.init
 Patch0:		repmgr-makefile-pgxs.patch
-Patch1:		repmgr.conf.sample.patch
+#Patch1:		repmgr.conf.sample.patch
 
 %if %{systemd_enabled}
 BuildRequires:		systemd
@@ -62,7 +62,7 @@ future PostgreSQL versions.
 %prep
 %setup -q -n %{sname}-%{version}
 %patch0 -p0
-%patch1 -p0
+#%patch1 -p0
 
 %build
 USE_PGXS=1 %{__make} %{?_smp_mflags}
@@ -97,13 +97,18 @@ install -m 755 %{SOURCE2}  %{buildroot}%{_sysconfdir}/init.d/%{sname}-%{pgpackag
 %endif
 
 %pre
-groupadd -r repmgr >/dev/null 2>&1 || :
-useradd -m -g repmgr -r -s /bin/bash \
-        -c "repmgr" repmgr >/dev/null 2>&1 || :
+groupadd -r postgres >/dev/null 2>&1 || :
+useradd -m -g postgres -r -s /bin/bash \
+        -c "postgres" postgres >/dev/null 2>&1 || :
 if [ ! -x /var/log/repmgr ]
 then
 	%{__mkdir} -m 700 /var/log/repmgr
-	%{__chown} -R repmgr: /var/log/repmgr
+	%{__chown} -R postgres: /var/log/repmgr
+fi
+if [ ! -x /var/run/repmgr ]
+then
+	%{__mkdir} -m 700 /var/run/repmgr
+	%{__chown} -R postgres: /var/run/repmgr
 fi
 
 %post
@@ -115,7 +120,7 @@ fi
 # This adds the proper /etc/rc*.d links for the script
 /sbin/chkconfig --add %{sname}-%{pgpackageversion}
 %endif
-%{__chown} repmgr: %{_localstatedir}/run/%{sname}
+%{__chown} postgres: %{_localstatedir}/run/%{sname}
 
 %postun -p /sbin/ldconfig
 
diff --git a/rpm/redhat/9.3/repmgr/F-23/repmgr.spec b/rpm/redhat/9.3/repmgr/F-23/repmgr.spec
index 36985e8..9563c90 100644
--- a/rpm/redhat/9.3/repmgr/F-23/repmgr.spec
+++ b/rpm/redhat/9.3/repmgr/F-23/repmgr.spec
@@ -12,7 +12,7 @@
 
 Name:           %{sname}%{pgmajorversion}
 Version:        3.0.2
-Release:        1%{?dist}
+Release:        3%{?dist}
 Summary:        Replication Manager for PostgreSQL Clusters
 License:        GPLv3
 URL:            http://www.repmgr.org
@@ -20,7 +20,7 @@ Source0:        http://repmgr.org/download/%{sname}-%{version}.tar.gz
 Source1:	repmgr-%{pgpackageversion}.service
 Source2:	repmgr.init
 Patch0:		repmgr-makefile-pgxs.patch
-Patch1:		repmgr.conf.sample.patch
+#Patch1:		repmgr.conf.sample.patch
 
 %if %{systemd_enabled}
 BuildRequires:		systemd
@@ -62,7 +62,7 @@ future PostgreSQL versions.
 %prep
 %setup -q -n %{sname}-%{version}
 %patch0 -p0
-%patch1 -p0
+#%patch1 -p0
 
 %build
 USE_PGXS=1 %{__make} %{?_smp_mflags}
@@ -97,13 +97,18 @@ install -m 755 %{SOURCE2}  %{buildroot}%{_sysconfdir}/init.d/%{sname}-%{pgpackag
 %endif
 
 %pre
-groupadd -r repmgr >/dev/null 2>&1 || :
-useradd -m -g repmgr -r -s /bin/bash \
-        -c "repmgr" repmgr >/dev/null 2>&1 || :
+groupadd -r postgres >/dev/null 2>&1 || :
+useradd -m -g postgres -r -s /bin/bash \
+        -c "postgres" postgres >/dev/null 2>&1 || :
 if [ ! -x /var/log/repmgr ]
 then
 	%{__mkdir} -m 700 /var/log/repmgr
-	%{__chown} -R repmgr: /var/log/repmgr
+	%{__chown} -R postgres: /var/log/repmgr
+fi
+if [ ! -x /var/run/repmgr ]
+then
+	%{__mkdir} -m 700 /var/run/repmgr
+	%{__chown} -R postgres: /var/run/repmgr
 fi
 
 %post
@@ -115,7 +120,7 @@ fi
 # This adds the proper /etc/rc*.d links for the script
 /sbin/chkconfig --add %{sname}-%{pgpackageversion}
 %endif
-%{__chown} repmgr: %{_localstatedir}/run/%{sname}
+%{__chown} postgres: %{_localstatedir}/run/%{sname}
 
 %postun -p /sbin/ldconfig
 
diff --git a/rpm/redhat/9.4/repmgr/EL-5/repmgr.spec b/rpm/redhat/9.4/repmgr/EL-5/repmgr.spec
index aba8b39..7397199 100644
--- a/rpm/redhat/9.4/repmgr/EL-5/repmgr.spec
+++ b/rpm/redhat/9.4/repmgr/EL-5/repmgr.spec
@@ -12,7 +12,7 @@
 
 Name:           %{sname}%{pgmajorversion}
 Version:        3.0.2
-Release:        1%{?dist}
+Release:        3%{?dist}
 Summary:        Replication Manager for PostgreSQL Clusters
 License:        GPLv3
 URL:            http://www.repmgr.org
@@ -20,7 +20,7 @@ Source0:        http://repmgr.org/download/%{sname}-%{version}.tar.gz
 Source1:	repmgr-%{pgpackageversion}.service
 Source2:	repmgr.init
 Patch0:		repmgr-makefile-pgxs.patch
-Patch1:		repmgr.conf.sample.patch
+#Patch1:		repmgr.conf.sample.patch
 
 %if %{systemd_enabled}
 BuildRequires:		systemd
@@ -62,7 +62,7 @@ future PostgreSQL versions.
 %prep
 %setup -q -n %{sname}-%{version}
 %patch0 -p0
-%patch1 -p0
+#%patch1 -p0
 
 %build
 USE_PGXS=1 %{__make} %{?_smp_mflags}
@@ -97,13 +97,18 @@ install -m 755 %{SOURCE2}  %{buildroot}%{_sysconfdir}/init.d/%{sname}-%{pgpackag
 %endif
 
 %pre
-groupadd -r repmgr >/dev/null 2>&1 || :
-useradd -m -g repmgr -r -s /bin/bash \
-        -c "repmgr" repmgr >/dev/null 2>&1 || :
+groupadd -r postgres >/dev/null 2>&1 || :
+useradd -m -g postgres -r -s /bin/bash \
+        -c "postgres" postgres >/dev/null 2>&1 || :
 if [ ! -x /var/log/repmgr ]
 then
 	%{__mkdir} -m 700 /var/log/repmgr
-	%{__chown} -R repmgr: /var/log/repmgr
+	%{__chown} -R postgres: /var/log/repmgr
+fi
+if [ ! -x /var/run/repmgr ]
+then
+	%{__mkdir} -m 700 /var/run/repmgr
+	%{__chown} -R postgres: /var/run/repmgr
 fi
 
 %post
@@ -115,7 +120,7 @@ fi
 # This adds the proper /etc/rc*.d links for the script
 /sbin/chkconfig --add %{sname}-%{pgpackageversion}
 %endif
-%{__chown} repmgr: %{_localstatedir}/run/%{sname}
+%{__chown} postgres: %{_localstatedir}/run/%{sname}
 
 %postun -p /sbin/ldconfig
 
diff --git a/rpm/redhat/9.4/repmgr/EL-6/repmgr.spec b/rpm/redhat/9.4/repmgr/EL-6/repmgr.spec
index aba8b39..7397199 100644
--- a/rpm/redhat/9.4/repmgr/EL-6/repmgr.spec
+++ b/rpm/redhat/9.4/repmgr/EL-6/repmgr.spec
@@ -12,7 +12,7 @@
 
 Name:           %{sname}%{pgmajorversion}
 Version:        3.0.2
-Release:        1%{?dist}
+Release:        3%{?dist}
 Summary:        Replication Manager for PostgreSQL Clusters
 License:        GPLv3
 URL:            http://www.repmgr.org
@@ -20,7 +20,7 @@ Source0:        http://repmgr.org/download/%{sname}-%{version}.tar.gz
 Source1:	repmgr-%{pgpackageversion}.service
 Source2:	repmgr.init
 Patch0:		repmgr-makefile-pgxs.patch
-Patch1:		repmgr.conf.sample.patch
+#Patch1:		repmgr.conf.sample.patch
 
 %if %{systemd_enabled}
 BuildRequires:		systemd
@@ -62,7 +62,7 @@ future PostgreSQL versions.
 %prep
 %setup -q -n %{sname}-%{version}
 %patch0 -p0
-%patch1 -p0
+#%patch1 -p0
 
 %build
 USE_PGXS=1 %{__make} %{?_smp_mflags}
@@ -97,13 +97,18 @@ install -m 755 %{SOURCE2}  %{buildroot}%{_sysconfdir}/init.d/%{sname}-%{pgpackag
 %endif
 
 %pre
-groupadd -r repmgr >/dev/null 2>&1 || :
-useradd -m -g repmgr -r -s /bin/bash \
-        -c "repmgr" repmgr >/dev/null 2>&1 || :
+groupadd -r postgres >/dev/null 2>&1 || :
+useradd -m -g postgres -r -s /bin/bash \
+        -c "postgres" postgres >/dev/null 2>&1 || :
 if [ ! -x /var/log/repmgr ]
 then
 	%{__mkdir} -m 700 /var/log/repmgr
-	%{__chown} -R repmgr: /var/log/repmgr
+	%{__chown} -R postgres: /var/log/repmgr
+fi
+if [ ! -x /var/run/repmgr ]
+then
+	%{__mkdir} -m 700 /var/run/repmgr
+	%{__chown} -R postgres: /var/run/repmgr
 fi
 
 %post
@@ -115,7 +120,7 @@ fi
 # This adds the proper /etc/rc*.d links for the script
 /sbin/chkconfig --add %{sname}-%{pgpackageversion}
 %endif
-%{__chown} repmgr: %{_localstatedir}/run/%{sname}
+%{__chown} postgres: %{_localstatedir}/run/%{sname}
 
 %postun -p /sbin/ldconfig
 
diff --git a/rpm/redhat/9.4/repmgr/EL-7/repmgr.spec b/rpm/redhat/9.4/repmgr/EL-7/repmgr.spec
index aba8b39..7397199 100644
--- a/rpm/redhat/9.4/repmgr/EL-7/repmgr.spec
+++ b/rpm/redhat/9.4/repmgr/EL-7/repmgr.spec
@@ -12,7 +12,7 @@
 
 Name:           %{sname}%{pgmajorversion}
 Version:        3.0.2
-Release:        1%{?dist}
+Release:        3%{?dist}
 Summary:        Replication Manager for PostgreSQL Clusters
 License:        GPLv3
 URL:            http://www.repmgr.org
@@ -20,7 +20,7 @@ Source0:        http://repmgr.org/download/%{sname}-%{version}.tar.gz
 Source1:	repmgr-%{pgpackageversion}.service
 Source2:	repmgr.init
 Patch0:		repmgr-makefile-pgxs.patch
-Patch1:		repmgr.conf.sample.patch
+#Patch1:		repmgr.conf.sample.patch
 
 %if %{systemd_enabled}
 BuildRequires:		systemd
@@ -62,7 +62,7 @@ future PostgreSQL versions.
 %prep
 %setup -q -n %{sname}-%{version}
 %patch0 -p0
-%patch1 -p0
+#%patch1 -p0
 
 %build
 USE_PGXS=1 %{__make} %{?_smp_mflags}
@@ -97,13 +97,18 @@ install -m 755 %{SOURCE2}  %{buildroot}%{_sysconfdir}/init.d/%{sname}-%{pgpackag
 %endif
 
 %pre
-groupadd -r repmgr >/dev/null 2>&1 || :
-useradd -m -g repmgr -r -s /bin/bash \
-        -c "repmgr" repmgr >/dev/null 2>&1 || :
+groupadd -r postgres >/dev/null 2>&1 || :
+useradd -m -g postgres -r -s /bin/bash \
+        -c "postgres" postgres >/dev/null 2>&1 || :
 if [ ! -x /var/log/repmgr ]
 then
 	%{__mkdir} -m 700 /var/log/repmgr
-	%{__chown} -R repmgr: /var/log/repmgr
+	%{__chown} -R postgres: /var/log/repmgr
+fi
+if [ ! -x /var/run/repmgr ]
+then
+	%{__mkdir} -m 700 /var/run/repmgr
+	%{__chown} -R postgres: /var/run/repmgr
 fi
 
 %post
@@ -115,7 +120,7 @@ fi
 # This adds the proper /etc/rc*.d links for the script
 /sbin/chkconfig --add %{sname}-%{pgpackageversion}
 %endif
-%{__chown} repmgr: %{_localstatedir}/run/%{sname}
+%{__chown} postgres: %{_localstatedir}/run/%{sname}
 
 %postun -p /sbin/ldconfig
 
diff --git a/rpm/redhat/9.4/repmgr/F-20/repmgr.spec b/rpm/redhat/9.4/repmgr/F-20/repmgr.spec
index aba8b39..7397199 100644
--- a/rpm/redhat/9.4/repmgr/F-20/repmgr.spec
+++ b/rpm/redhat/9.4/repmgr/F-20/repmgr.spec
@@ -12,7 +12,7 @@
 
 Name:           %{sname}%{pgmajorversion}
 Version:        3.0.2
-Release:        1%{?dist}
+Release:        3%{?dist}
 Summary:        Replication Manager for PostgreSQL Clusters
 License:        GPLv3
 URL:            http://www.repmgr.org
@@ -20,7 +20,7 @@ Source0:        http://repmgr.org/download/%{sname}-%{version}.tar.gz
 Source1:	repmgr-%{pgpackageversion}.service
 Source2:	repmgr.init
 Patch0:		repmgr-makefile-pgxs.patch
-Patch1:		repmgr.conf.sample.patch
+#Patch1:		repmgr.conf.sample.patch
 
 %if %{systemd_enabled}
 BuildRequires:		systemd
@@ -62,7 +62,7 @@ future PostgreSQL versions.
 %prep
 %setup -q -n %{sname}-%{version}
 %patch0 -p0
-%patch1 -p0
+#%patch1 -p0
 
 %build
 USE_PGXS=1 %{__make} %{?_smp_mflags}
@@ -97,13 +97,18 @@ install -m 755 %{SOURCE2}  %{buildroot}%{_sysconfdir}/init.d/%{sname}-%{pgpackag
 %endif
 
 %pre
-groupadd -r repmgr >/dev/null 2>&1 || :
-useradd -m -g repmgr -r -s /bin/bash \
-        -c "repmgr" repmgr >/dev/null 2>&1 || :
+groupadd -r postgres >/dev/null 2>&1 || :
+useradd -m -g postgres -r -s /bin/bash \
+        -c "postgres" postgres >/dev/null 2>&1 || :
 if [ ! -x /var/log/repmgr ]
 then
 	%{__mkdir} -m 700 /var/log/repmgr
-	%{__chown} -R repmgr: /var/log/repmgr
+	%{__chown} -R postgres: /var/log/repmgr
+fi
+if [ ! -x /var/run/repmgr ]
+then
+	%{__mkdir} -m 700 /var/run/repmgr
+	%{__chown} -R postgres: /var/run/repmgr
 fi
 
 %post
@@ -115,7 +120,7 @@ fi
 # This adds the proper /etc/rc*.d links for the script
 /sbin/chkconfig --add %{sname}-%{pgpackageversion}
 %endif
-%{__chown} repmgr: %{_localstatedir}/run/%{sname}
+%{__chown} postgres: %{_localstatedir}/run/%{sname}
 
 %postun -p /sbin/ldconfig
 
diff --git a/rpm/redhat/9.4/repmgr/F-21/repmgr.spec b/rpm/redhat/9.4/repmgr/F-21/repmgr.spec
index aba8b39..7397199 100644
--- a/rpm/redhat/9.4/repmgr/F-21/repmgr.spec
+++ b/rpm/redhat/9.4/repmgr/F-21/repmgr.spec
@@ -12,7 +12,7 @@
 
 Name:           %{sname}%{pgmajorversion}
 Version:        3.0.2
-Release:        1%{?dist}
+Release:        3%{?dist}
 Summary:        Replication Manager for PostgreSQL Clusters
 License:        GPLv3
 URL:            http://www.repmgr.org
@@ -20,7 +20,7 @@ Source0:        http://repmgr.org/download/%{sname}-%{version}.tar.gz
 Source1:	repmgr-%{pgpackageversion}.service
 Source2:	repmgr.init
 Patch0:		repmgr-makefile-pgxs.patch
-Patch1:		repmgr.conf.sample.patch
+#Patch1:		repmgr.conf.sample.patch
 
 %if %{systemd_enabled}
 BuildRequires:		systemd
@@ -62,7 +62,7 @@ future PostgreSQL versions.
 %prep
 %setup -q -n %{sname}-%{version}
 %patch0 -p0
-%patch1 -p0
+#%patch1 -p0
 
 %build
 USE_PGXS=1 %{__make} %{?_smp_mflags}
@@ -97,13 +97,18 @@ install -m 755 %{SOURCE2}  %{buildroot}%{_sysconfdir}/init.d/%{sname}-%{pgpackag
 %endif
 
 %pre
-groupadd -r repmgr >/dev/null 2>&1 || :
-useradd -m -g repmgr -r -s /bin/bash \
-        -c "repmgr" repmgr >/dev/null 2>&1 || :
+groupadd -r postgres >/dev/null 2>&1 || :
+useradd -m -g postgres -r -s /bin/bash \
+        -c "postgres" postgres >/dev/null 2>&1 || :
 if [ ! -x /var/log/repmgr ]
 then
 	%{__mkdir} -m 700 /var/log/repmgr
-	%{__chown} -R repmgr: /var/log/repmgr
+	%{__chown} -R postgres: /var/log/repmgr
+fi
+if [ ! -x /var/run/repmgr ]
+then
+	%{__mkdir} -m 700 /var/run/repmgr
+	%{__chown} -R postgres: /var/run/repmgr
 fi
 
 %post
@@ -115,7 +120,7 @@ fi
 # This adds the proper /etc/rc*.d links for the script
 /sbin/chkconfig --add %{sname}-%{pgpackageversion}
 %endif
-%{__chown} repmgr: %{_localstatedir}/run/%{sname}
+%{__chown} postgres: %{_localstatedir}/run/%{sname}
 
 %postun -p /sbin/ldconfig
 
diff --git a/rpm/redhat/9.4/repmgr/F-22/repmgr.spec b/rpm/redhat/9.4/repmgr/F-22/repmgr.spec
index aba8b39..7397199 100644
--- a/rpm/redhat/9.4/repmgr/F-22/repmgr.spec
+++ b/rpm/redhat/9.4/repmgr/F-22/repmgr.spec
@@ -12,7 +12,7 @@
 
 Name:           %{sname}%{pgmajorversion}
 Version:        3.0.2
-Release:        1%{?dist}
+Release:        3%{?dist}
 Summary:        Replication Manager for PostgreSQL Clusters
 License:        GPLv3
 URL:            http://www.repmgr.org
@@ -20,7 +20,7 @@ Source0:        http://repmgr.org/download/%{sname}-%{version}.tar.gz
 Source1:	repmgr-%{pgpackageversion}.service
 Source2:	repmgr.init
 Patch0:		repmgr-makefile-pgxs.patch
-Patch1:		repmgr.conf.sample.patch
+#Patch1:		repmgr.conf.sample.patch
 
 %if %{systemd_enabled}
 BuildRequires:		systemd
@@ -62,7 +62,7 @@ future PostgreSQL versions.
 %prep
 %setup -q -n %{sname}-%{version}
 %patch0 -p0
-%patch1 -p0
+#%patch1 -p0
 
 %build
 USE_PGXS=1 %{__make} %{?_smp_mflags}
@@ -97,13 +97,18 @@ install -m 755 %{SOURCE2}  %{buildroot}%{_sysconfdir}/init.d/%{sname}-%{pgpackag
 %endif
 
 %pre
-groupadd -r repmgr >/dev/null 2>&1 || :
-useradd -m -g repmgr -r -s /bin/bash \
-        -c "repmgr" repmgr >/dev/null 2>&1 || :
+groupadd -r postgres >/dev/null 2>&1 || :
+useradd -m -g postgres -r -s /bin/bash \
+        -c "postgres" postgres >/dev/null 2>&1 || :
 if [ ! -x /var/log/repmgr ]
 then
 	%{__mkdir} -m 700 /var/log/repmgr
-	%{__chown} -R repmgr: /var/log/repmgr
+	%{__chown} -R postgres: /var/log/repmgr
+fi
+if [ ! -x /var/run/repmgr ]
+then
+	%{__mkdir} -m 700 /var/run/repmgr
+	%{__chown} -R postgres: /var/run/repmgr
 fi
 
 %post
@@ -115,7 +120,7 @@ fi
 # This adds the proper /etc/rc*.d links for the script
 /sbin/chkconfig --add %{sname}-%{pgpackageversion}
 %endif
-%{__chown} repmgr: %{_localstatedir}/run/%{sname}
+%{__chown} postgres: %{_localstatedir}/run/%{sname}
 
 %postun -p /sbin/ldconfig
 
diff --git a/rpm/redhat/9.4/repmgr/F-23/repmgr.spec b/rpm/redhat/9.4/repmgr/F-23/repmgr.spec
index aba8b39..7397199 100644
--- a/rpm/redhat/9.4/repmgr/F-23/repmgr.spec
+++ b/rpm/redhat/9.4/repmgr/F-23/repmgr.spec
@@ -12,7 +12,7 @@
 
 Name:           %{sname}%{pgmajorversion}
 Version:        3.0.2
-Release:        1%{?dist}
+Release:        3%{?dist}
 Summary:        Replication Manager for PostgreSQL Clusters
 License:        GPLv3
 URL:            http://www.repmgr.org
@@ -20,7 +20,7 @@ Source0:        http://repmgr.org/download/%{sname}-%{version}.tar.gz
 Source1:	repmgr-%{pgpackageversion}.service
 Source2:	repmgr.init
 Patch0:		repmgr-makefile-pgxs.patch
-Patch1:		repmgr.conf.sample.patch
+#Patch1:		repmgr.conf.sample.patch
 
 %if %{systemd_enabled}
 BuildRequires:		systemd
@@ -62,7 +62,7 @@ future PostgreSQL versions.
 %prep
 %setup -q -n %{sname}-%{version}
 %patch0 -p0
-%patch1 -p0
+#%patch1 -p0
 
 %build
 USE_PGXS=1 %{__make} %{?_smp_mflags}
@@ -97,13 +97,18 @@ install -m 755 %{SOURCE2}  %{buildroot}%{_sysconfdir}/init.d/%{sname}-%{pgpackag
 %endif
 
 %pre
-groupadd -r repmgr >/dev/null 2>&1 || :
-useradd -m -g repmgr -r -s /bin/bash \
-        -c "repmgr" repmgr >/dev/null 2>&1 || :
+groupadd -r postgres >/dev/null 2>&1 || :
+useradd -m -g postgres -r -s /bin/bash \
+        -c "postgres" postgres >/dev/null 2>&1 || :
 if [ ! -x /var/log/repmgr ]
 then
 	%{__mkdir} -m 700 /var/log/repmgr
-	%{__chown} -R repmgr: /var/log/repmgr
+	%{__chown} -R postgres: /var/log/repmgr
+fi
+if [ ! -x /var/run/repmgr ]
+then
+	%{__mkdir} -m 700 /var/run/repmgr
+	%{__chown} -R postgres: /var/run/repmgr
 fi
 
 %post
@@ -115,7 +120,7 @@ fi
 # This adds the proper /etc/rc*.d links for the script
 /sbin/chkconfig --add %{sname}-%{pgpackageversion}
 %endif
-%{__chown} repmgr: %{_localstatedir}/run/%{sname}
+%{__chown} postgres: %{_localstatedir}/run/%{sname}
 
 %postun -p /sbin/ldconfig
 
diff --git a/rpm/redhat/9.5/repmgr/EL-5/repmgr.spec b/rpm/redhat/9.5/repmgr/EL-5/repmgr.spec
index 224c6bf..774c08d 100644
--- a/rpm/redhat/9.5/repmgr/EL-5/repmgr.spec
+++ b/rpm/redhat/9.5/repmgr/EL-5/repmgr.spec
@@ -12,7 +12,7 @@
 
 Name:           %{sname}%{pgmajorversion}
 Version:        3.0.2
-Release:        2%{?dist}
+Release:        3%{?dist}
 Summary:        Replication Manager for PostgreSQL Clusters
 License:        GPLv3
 URL:            http://www.repmgr.org
@@ -20,7 +20,7 @@ Source0:        http://repmgr.org/download/%{sname}-%{version}.tar.gz
 Source1:	repmgr-%{pgpackageversion}.service
 Source2:	repmgr.init
 Patch0:		repmgr-makefile-pgxs.patch
-Patch1:		repmgr.conf.sample.patch
+#Patch1:		repmgr.conf.sample.patch
 
 %if %{systemd_enabled}
 BuildRequires:		systemd
@@ -62,7 +62,7 @@ future PostgreSQL versions.
 %prep
 %setup -q -n %{sname}-%{version}
 %patch0 -p0
-%patch1 -p0
+#%patch1 -p0
 
 %build
 USE_PGXS=1 %{__make} %{?_smp_mflags}
@@ -97,11 +97,19 @@ install -m 755 %{SOURCE2}  %{buildroot}%{_sysconfdir}/init.d/%{sname}-%{pgpackag
 %endif
 
 %pre
+groupadd -r postgres >/dev/null 2>&1 || :
+useradd -m -g postgres -r -s /bin/bash \
+        -c "postgres" postgres >/dev/null 2>&1 || :
 if [ ! -x /var/log/repmgr ]
 then
 	%{__mkdir} -m 700 /var/log/repmgr
 	%{__chown} -R postgres: /var/log/repmgr
 fi
+if [ ! -x /var/run/repmgr ]
+then
+	%{__mkdir} -m 700 /var/run/repmgr
+	%{__chown} -R postgres: /var/run/repmgr
+fi
 
 %post
 /sbin/ldconfig
@@ -112,11 +120,7 @@ fi
 # This adds the proper /etc/rc*.d links for the script
 /sbin/chkconfig --add %{sname}-%{pgpackageversion}
 %endif
-if [ ! -x %{_varrundir} ]
-then
-	%{__mkdir} -m 700 %{_varrundir}
-	%{__chown} -R postgres: %{_varrundir}
-fi
+%{__chown} postgres: %{_localstatedir}/run/%{sname}
 
 %postun -p /sbin/ldconfig
 
@@ -147,11 +151,6 @@ fi
 %endif
 
 %changelog
-* Mon Nov 9 2015 - Devrim Gündüz <[email-masked]> 3.0.2-2
-- Ensure that /var/run/repmgr exists. Per Guillaume Lelarge.
-- Switch to postgres user while running the deamon, instead of
-  repmgr user. Per recent complaints from Guillaume and Justin King.
-
 * Tue Oct 6 2015 - Devrim Gündüz <[email-masked]> 3.0.2-1
 - Update to 3.0.2
 
diff --git a/rpm/redhat/9.5/repmgr/EL-6/repmgr.spec b/rpm/redhat/9.5/repmgr/EL-6/repmgr.spec
index 224c6bf..774c08d 100644
--- a/rpm/redhat/9.5/repmgr/EL-6/repmgr.spec
+++ b/rpm/redhat/9.5/repmgr/EL-6/repmgr.spec
@@ -12,7 +12,7 @@
 
 Name:           %{sname}%{pgmajorversion}
 Version:        3.0.2
-Release:        2%{?dist}
+Release:        3%{?dist}
 Summary:        Replication Manager for PostgreSQL Clusters
 License:        GPLv3
 URL:            http://www.repmgr.org
@@ -20,7 +20,7 @@ Source0:        http://repmgr.org/download/%{sname}-%{version}.tar.gz
 Source1:	repmgr-%{pgpackageversion}.service
 Source2:	repmgr.init
 Patch0:		repmgr-makefile-pgxs.patch
-Patch1:		repmgr.conf.sample.patch
+#Patch1:		repmgr.conf.sample.patch
 
 %if %{systemd_enabled}
 BuildRequires:		systemd
@@ -62,7 +62,7 @@ future PostgreSQL versions.
 %prep
 %setup -q -n %{sname}-%{version}
 %patch0 -p0
-%patch1 -p0
+#%patch1 -p0
 
 %build
 USE_PGXS=1 %{__make} %{?_smp_mflags}
@@ -97,11 +97,19 @@ install -m 755 %{SOURCE2}  %{buildroot}%{_sysconfdir}/init.d/%{sname}-%{pgpackag
 %endif
 
 %pre
+groupadd -r postgres >/dev/null 2>&1 || :
+useradd -m -g postgres -r -s /bin/bash \
+        -c "postgres" postgres >/dev/null 2>&1 || :
 if [ ! -x /var/log/repmgr ]
 then
 	%{__mkdir} -m 700 /var/log/repmgr
 	%{__chown} -R postgres: /var/log/repmgr
 fi
+if [ ! -x /var/run/repmgr ]
+then
+	%{__mkdir} -m 700 /var/run/repmgr
+	%{__chown} -R postgres: /var/run/repmgr
+fi
 
 %post
 /sbin/ldconfig
@@ -112,11 +120,7 @@ fi
 # This adds the proper /etc/rc*.d links for the script
 /sbin/chkconfig --add %{sname}-%{pgpackageversion}
 %endif
-if [ ! -x %{_varrundir} ]
-then
-	%{__mkdir} -m 700 %{_varrundir}
-	%{__chown} -R postgres: %{_varrundir}
-fi
+%{__chown} postgres: %{_localstatedir}/run/%{sname}
 
 %postun -p /sbin/ldconfig
 
@@ -147,11 +151,6 @@ fi
 %endif
 
 %changelog
-* Mon Nov 9 2015 - Devrim Gündüz <[email-masked]> 3.0.2-2
-- Ensure that /var/run/repmgr exists. Per Guillaume Lelarge.
-- Switch to postgres user while running the deamon, instead of
-  repmgr user. Per recent complaints from Guillaume and Justin King.
-
 * Tue Oct 6 2015 - Devrim Gündüz <[email-masked]> 3.0.2-1
 - Update to 3.0.2
 
diff --git a/rpm/redhat/9.5/repmgr/EL-7/repmgr.spec b/rpm/redhat/9.5/repmgr/EL-7/repmgr.spec
index 224c6bf..774c08d 100644
--- a/rpm/redhat/9.5/repmgr/EL-7/repmgr.spec
+++ b/rpm/redhat/9.5/repmgr/EL-7/repmgr.spec
@@ -12,7 +12,7 @@
 
 Name:           %{sname}%{pgmajorversion}
 Version:        3.0.2
-Release:        2%{?dist}
+Release:        3%{?dist}
 Summary:        Replication Manager for PostgreSQL Clusters
 License:        GPLv3
 URL:            http://www.repmgr.org
@@ -20,7 +20,7 @@ Source0:        http://repmgr.org/download/%{sname}-%{version}.tar.gz
 Source1:	repmgr-%{pgpackageversion}.service
 Source2:	repmgr.init
 Patch0:		repmgr-makefile-pgxs.patch
-Patch1:		repmgr.conf.sample.patch
+#Patch1:		repmgr.conf.sample.patch
 
 %if %{systemd_enabled}
 BuildRequires:		systemd
@@ -62,7 +62,7 @@ future PostgreSQL versions.
 %prep
 %setup -q -n %{sname}-%{version}
 %patch0 -p0
-%patch1 -p0
+#%patch1 -p0
 
 %build
 USE_PGXS=1 %{__make} %{?_smp_mflags}
@@ -97,11 +97,19 @@ install -m 755 %{SOURCE2}  %{buildroot}%{_sysconfdir}/init.d/%{sname}-%{pgpackag
 %endif
 
 %pre
+groupadd -r postgres >/dev/null 2>&1 || :
+useradd -m -g postgres -r -s /bin/bash \
+        -c "postgres" postgres >/dev/null 2>&1 || :
 if [ ! -x /var/log/repmgr ]
 then
 	%{__mkdir} -m 700 /var/log/repmgr
 	%{__chown} -R postgres: /var/log/repmgr
 fi
+if [ ! -x /var/run/repmgr ]
+then
+	%{__mkdir} -m 700 /var/run/repmgr
+	%{__chown} -R postgres: /var/run/repmgr
+fi
 
 %post
 /sbin/ldconfig
@@ -112,11 +120,7 @@ fi
 # This adds the proper /etc/rc*.d links for the script
 /sbin/chkconfig --add %{sname}-%{pgpackageversion}
 %endif
-if [ ! -x %{_varrundir} ]
-then
-	%{__mkdir} -m 700 %{_varrundir}
-	%{__chown} -R postgres: %{_varrundir}
-fi
+%{__chown} postgres: %{_localstatedir}/run/%{sname}
 
 %postun -p /sbin/ldconfig
 
@@ -147,11 +151,6 @@ fi
 %endif
 
 %changelog
-* Mon Nov 9 2015 - Devrim Gündüz <[email-masked]> 3.0.2-2
-- Ensure that /var/run/repmgr exists. Per Guillaume Lelarge.
-- Switch to postgres user while running the deamon, instead of
-  repmgr user. Per recent complaints from Guillaume and Justin King.
-
 * Tue Oct 6 2015 - Devrim Gündüz <[email-masked]> 3.0.2-1
 - Update to 3.0.2
 
diff --git a/rpm/redhat/9.5/repmgr/F-20/repmgr.spec b/rpm/redhat/9.5/repmgr/F-20/repmgr.spec
index 224c6bf..774c08d 100644
--- a/rpm/redhat/9.5/repmgr/F-20/repmgr.spec
+++ b/rpm/redhat/9.5/repmgr/F-20/repmgr.spec
@@ -12,7 +12,7 @@
 
 Name:           %{sname}%{pgmajorversion}
 Version:        3.0.2
-Release:        2%{?dist}
+Release:        3%{?dist}
 Summary:        Replication Manager for PostgreSQL Clusters
 License:        GPLv3
 URL:            http://www.repmgr.org
@@ -20,7 +20,7 @@ Source0:        http://repmgr.org/download/%{sname}-%{version}.tar.gz
 Source1:	repmgr-%{pgpackageversion}.service
 Source2:	repmgr.init
 Patch0:		repmgr-makefile-pgxs.patch
-Patch1:		repmgr.conf.sample.patch
+#Patch1:		repmgr.conf.sample.patch
 
 %if %{systemd_enabled}
 BuildRequires:		systemd
@@ -62,7 +62,7 @@ future PostgreSQL versions.
 %prep
 %setup -q -n %{sname}-%{version}
 %patch0 -p0
-%patch1 -p0
+#%patch1 -p0
 
 %build
 USE_PGXS=1 %{__make} %{?_smp_mflags}
@@ -97,11 +97,19 @@ install -m 755 %{SOURCE2}  %{buildroot}%{_sysconfdir}/init.d/%{sname}-%{pgpackag
 %endif
 
 %pre
+groupadd -r postgres >/dev/null 2>&1 || :
+useradd -m -g postgres -r -s /bin/bash \
+        -c "postgres" postgres >/dev/null 2>&1 || :
 if [ ! -x /var/log/repmgr ]
 then
 	%{__mkdir} -m 700 /var/log/repmgr
 	%{__chown} -R postgres: /var/log/repmgr
 fi
+if [ ! -x /var/run/repmgr ]
+then
+	%{__mkdir} -m 700 /var/run/repmgr
+	%{__chown} -R postgres: /var/run/repmgr
+fi
 
 %post
 /sbin/ldconfig
@@ -112,11 +120,7 @@ fi
 # This adds the proper /etc/rc*.d links for the script
 /sbin/chkconfig --add %{sname}-%{pgpackageversion}
 %endif
-if [ ! -x %{_varrundir} ]
-then
-	%{__mkdir} -m 700 %{_varrundir}
-	%{__chown} -R postgres: %{_varrundir}
-fi
+%{__chown} postgres: %{_localstatedir}/run/%{sname}
 
 %postun -p /sbin/ldconfig
 
@@ -147,11 +151,6 @@ fi
 %endif
 
 %changelog
-* Mon Nov 9 2015 - Devrim Gündüz <[email-masked]> 3.0.2-2
-- Ensure that /var/run/repmgr exists. Per Guillaume Lelarge.
-- Switch to postgres user while running the deamon, instead of
-  repmgr user. Per recent complaints from Guillaume and Justin King.
-
 * Tue Oct 6 2015 - Devrim Gündüz <[email-masked]> 3.0.2-1
 - Update to 3.0.2
 
diff --git a/rpm/redhat/9.5/repmgr/F-21/repmgr.spec b/rpm/redhat/9.5/repmgr/F-21/repmgr.spec
index 224c6bf..774c08d 100644
--- a/rpm/redhat/9.5/repmgr/F-21/repmgr.spec
+++ b/rpm/redhat/9.5/repmgr/F-21/repmgr.spec
@@ -12,7 +12,7 @@
 
 Name:           %{sname}%{pgmajorversion}
 Version:        3.0.2
-Release:        2%{?dist}
+Release:        3%{?dist}
 Summary:        Replication Manager for PostgreSQL Clusters
 License:        GPLv3
 URL:            http://www.repmgr.org
@@ -20,7 +20,7 @@ Source0:        http://repmgr.org/download/%{sname}-%{version}.tar.gz
 Source1:	repmgr-%{pgpackageversion}.service
 Source2:	repmgr.init
 Patch0:		repmgr-makefile-pgxs.patch
-Patch1:		repmgr.conf.sample.patch
+#Patch1:		repmgr.conf.sample.patch
 
 %if %{systemd_enabled}
 BuildRequires:		systemd
@@ -62,7 +62,7 @@ future PostgreSQL versions.
 %prep
 %setup -q -n %{sname}-%{version}
 %patch0 -p0
-%patch1 -p0
+#%patch1 -p0
 
 %build
 USE_PGXS=1 %{__make} %{?_smp_mflags}
@@ -97,11 +97,19 @@ install -m 755 %{SOURCE2}  %{buildroot}%{_sysconfdir}/init.d/%{sname}-%{pgpackag
 %endif
 
 %pre
+groupadd -r postgres >/dev/null 2>&1 || :
+useradd -m -g postgres -r -s /bin/bash \
+        -c "postgres" postgres >/dev/null 2>&1 || :
 if [ ! -x /var/log/repmgr ]
 then
 	%{__mkdir} -m 700 /var/log/repmgr
 	%{__chown} -R postgres: /var/log/repmgr
 fi
+if [ ! -x /var/run/repmgr ]
+then
+	%{__mkdir} -m 700 /var/run/repmgr
+	%{__chown} -R postgres: /var/run/repmgr
+fi
 
 %post
 /sbin/ldconfig
@@ -112,11 +120,7 @@ fi
 # This adds the proper /etc/rc*.d links for the script
 /sbin/chkconfig --add %{sname}-%{pgpackageversion}
 %endif
-if [ ! -x %{_varrundir} ]
-then
-	%{__mkdir} -m 700 %{_varrundir}
-	%{__chown} -R postgres: %{_varrundir}
-fi
+%{__chown} postgres: %{_localstatedir}/run/%{sname}
 
 %postun -p /sbin/ldconfig
 
@@ -147,11 +151,6 @@ fi
 %endif
 
 %changelog
-* Mon Nov 9 2015 - Devrim Gündüz <[email-masked]> 3.0.2-2
-- Ensure that /var/run/repmgr exists. Per Guillaume Lelarge.
-- Switch to postgres user while running the deamon, instead of
-  repmgr user. Per recent complaints from Guillaume and Justin King.
-
 * Tue Oct 6 2015 - Devrim Gündüz <[email-masked]> 3.0.2-1
 - Update to 3.0.2
 
diff --git a/rpm/redhat/9.5/repmgr/F-22/repmgr.spec b/rpm/redhat/9.5/repmgr/F-22/repmgr.spec
index 224c6bf..774c08d 100644
--- a/rpm/redhat/9.5/repmgr/F-22/repmgr.spec
+++ b/rpm/redhat/9.5/repmgr/F-22/repmgr.spec
@@ -12,7 +12,7 @@
 
 Name:           %{sname}%{pgmajorversion}
 Version:        3.0.2
-Release:        2%{?dist}
+Release:        3%{?dist}
 Summary:        Replication Manager for PostgreSQL Clusters
 License:        GPLv3
 URL:            http://www.repmgr.org
@@ -20,7 +20,7 @@ Source0:        http://repmgr.org/download/%{sname}-%{version}.tar.gz
 Source1:	repmgr-%{pgpackageversion}.service
 Source2:	repmgr.init
 Patch0:		repmgr-makefile-pgxs.patch
-Patch1:		repmgr.conf.sample.patch
+#Patch1:		repmgr.conf.sample.patch
 
 %if %{systemd_enabled}
 BuildRequires:		systemd
@@ -62,7 +62,7 @@ future PostgreSQL versions.
 %prep
 %setup -q -n %{sname}-%{version}
 %patch0 -p0
-%patch1 -p0
+#%patch1 -p0
 
 %build
 USE_PGXS=1 %{__make} %{?_smp_mflags}
@@ -97,11 +97,19 @@ install -m 755 %{SOURCE2}  %{buildroot}%{_sysconfdir}/init.d/%{sname}-%{pgpackag
 %endif
 
 %pre
+groupadd -r postgres >/dev/null 2>&1 || :
+useradd -m -g postgres -r -s /bin/bash \
+        -c "postgres" postgres >/dev/null 2>&1 || :
 if [ ! -x /var/log/repmgr ]
 then
 	%{__mkdir} -m 700 /var/log/repmgr
 	%{__chown} -R postgres: /var/log/repmgr
 fi
+if [ ! -x /var/run/repmgr ]
+then
+	%{__mkdir} -m 700 /var/run/repmgr
+	%{__chown} -R postgres: /var/run/repmgr
+fi
 
 %post
 /sbin/ldconfig
@@ -112,11 +120,7 @@ fi
 # This adds the proper /etc/rc*.d links for the script
 /sbin/chkconfig --add %{sname}-%{pgpackageversion}
 %endif
-if [ ! -x %{_varrundir} ]
-then
-	%{__mkdir} -m 700 %{_varrundir}
-	%{__chown} -R postgres: %{_varrundir}
-fi
+%{__chown} postgres: %{_localstatedir}/run/%{sname}
 
 %postun -p /sbin/ldconfig
 
@@ -147,11 +151,6 @@ fi
 %endif
 
 %changelog
-* Mon Nov 9 2015 - Devrim Gündüz <[email-masked]> 3.0.2-2
-- Ensure that /var/run/repmgr exists. Per Guillaume Lelarge.
-- Switch to postgres user while running the deamon, instead of
-  repmgr user. Per recent complaints from Guillaume and Justin King.
-
 * Tue Oct 6 2015 - Devrim Gündüz <[email-masked]> 3.0.2-1
 - Update to 3.0.2
 
diff --git a/rpm/redhat/9.5/repmgr/F-23/repmgr.spec b/rpm/redhat/9.5/repmgr/F-23/repmgr.spec
index 224c6bf..774c08d 100644
--- a/rpm/redhat/9.5/repmgr/F-23/repmgr.spec
+++ b/rpm/redhat/9.5/repmgr/F-23/repmgr.spec
@@ -12,7 +12,7 @@
 
 Name:           %{sname}%{pgmajorversion}
 Version:        3.0.2
-Release:        2%{?dist}
+Release:        3%{?dist}
 Summary:        Replication Manager for PostgreSQL Clusters
 License:        GPLv3
 URL:            http://www.repmgr.org
@@ -20,7 +20,7 @@ Source0:        http://repmgr.org/download/%{sname}-%{version}.tar.gz
 Source1:	repmgr-%{pgpackageversion}.service
 Source2:	repmgr.init
 Patch0:		repmgr-makefile-pgxs.patch
-Patch1:		repmgr.conf.sample.patch
+#Patch1:		repmgr.conf.sample.patch
 
 %if %{systemd_enabled}
 BuildRequires:		systemd
@@ -62,7 +62,7 @@ future PostgreSQL versions.
 %prep
 %setup -q -n %{sname}-%{version}
 %patch0 -p0
-%patch1 -p0
+#%patch1 -p0
 
 %build
 USE_PGXS=1 %{__make} %{?_smp_mflags}
@@ -97,11 +97,19 @@ install -m 755 %{SOURCE2}  %{buildroot}%{_sysconfdir}/init.d/%{sname}-%{pgpackag
 %endif
 
 %pre
+groupadd -r postgres >/dev/null 2>&1 || :
+useradd -m -g postgres -r -s /bin/bash \
+        -c "postgres" postgres >/dev/null 2>&1 || :
 if [ ! -x /var/log/repmgr ]
 then
 	%{__mkdir} -m 700 /var/log/repmgr
 	%{__chown} -R postgres: /var/log/repmgr
 fi
+if [ ! -x /var/run/repmgr ]
+then
+	%{__mkdir} -m 700 /var/run/repmgr
+	%{__chown} -R postgres: /var/run/repmgr
+fi
 
 %post
 /sbin/ldconfig
@@ -112,11 +120,7 @@ fi
 # This adds the proper /etc/rc*.d links for the script
 /sbin/chkconfig --add %{sname}-%{pgpackageversion}
 %endif
-if [ ! -x %{_varrundir} ]
-then
-	%{__mkdir} -m 700 %{_varrundir}
-	%{__chown} -R postgres: %{_varrundir}
-fi
+%{__chown} postgres: %{_localstatedir}/run/%{sname}
 
 %postun -p /sbin/ldconfig
 
@@ -147,11 +151,6 @@ fi
 %endif
 
 %changelog
-* Mon Nov 9 2015 - Devrim Gündüz <[email-masked]> 3.0.2-2
-- Ensure that /var/run/repmgr exists. Per Guillaume Lelarge.
-- Switch to postgres user while running the deamon, instead of
-  repmgr user. Per recent complaints from Guillaume and Justin King.
-
 * Tue Oct 6 2015 - Devrim Gündüz <[email-masked]> 3.0.2-1
 - Update to 3.0.2
 
-- 
2.5.0

---

From: Devrim GÜNDÜZ <[email-masked]>
Date: Tue, 05 Jan 2016 16:08:52 +0200

Hi,

On Wed, 2015-12-30 at 18:59 -0300, Martín Marqués wrote:

> Please check them and if there's something to fix let me know and
> I'll take care of it next week.

I checked this today. Some parts of this patch is already committed.
Why did you add postgres user with repmgr? That is done as a part of
PostgreSQL RPMs, which is a Requires: part.

Regards,
-- 
Devrim GÜNDÜZ
Principal Systems Engineer @ EnterpriseDB: http://www.enterprisedb.com
PostgreSQL Danışmanı/Consultant, Red Hat Certified Engineer
Twitter: @DevrimGunduz , @DevrimGunduzTR

---

From: Devrim GÜNDÜZ <[email-masked]>
Date: Tue, 05 Jan 2016 17:15:16 +0200

Hi,

> improvements to the old sysV init scripts.

Thanks for the patch! I applied this to 9.5 branch with some changes,
and built packages. 

Can you please check this commit, and let me know if you see any
issues?

http://git.postgresql.org/gitweb/?p=pgrpms.git;a=commit;h=bd9ecc3831f73c8f72e9dde8cb569fb81425ad4b

Thanks!

Regards,

---

From: Devrim GÜNDÜZ <[email-masked]>
Date: Tue, 05 Jan 2016 17:18:42 +0200

Hi,

> Promised patch. Let me know if there's something to fix.

I think this patch needs an update -- what is MAINPID variable? I don't
think it is defined elsewhere. Am I wrong?

Still, this patch already seems to be applied to 9.5. Can you please
confirm? If 9.5 branch looks good, I'll push it to other releases as
well.

Regards,

---

From: Martín Marqués <[email-masked]>
Date: Tue, 5 Jan 2016 12:20:06 -0300

Hi,

> I checked this today. Some parts of this patch is already committed.

Hum, I recall doing a git pull before applying the changes. Anyway, I
don't think I'll be able too go through the whole patching again now.
I can send you 1 patch for 1 file if that suffices.

> PostgreSQL RPMs, which is a Requires: part.

I was think what you meant with this, and now I understand. Yes,
adding the postgres user again is completely useless. My bad there.

We *do* want to use postgres instead of a separate repmgr OS user, as
we need this to be able to perform the promote and follow commands.

Regards,

---

From: Martín Marqués <[email-masked]>
Date: Tue, 5 Jan 2016 12:26:18 -0300

Hi,

$MAINPID is a systemd special environment variable

http://www.freedesktop.org/software/systemd/man/systemd.service.html

====
One additional, special environment variable is set: if known,
$MAINPID is set to the main process of the daemon, and may be used for
command lines like the following:

/bin/kill -HUP $MAINPID
===

We tell systemd how to get the PID with PIDFile=

Regards,