mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-23 15:16:29 +00:00
134 lines
2.7 KiB
Bash
Executable File
134 lines
2.7 KiB
Bash
Executable File
#!/bin/sh
|
|
#
|
|
# chkconfig: - 75 16
|
|
# description: Enable repmgrd replication management and monitoring daemon for PostgreSQL
|
|
# processname: repmgrd
|
|
# pidfile="/var/run/${NAME}.pid"
|
|
|
|
# Source function library.
|
|
INITD=/etc/rc.d/init.d
|
|
. $INITD/functions
|
|
|
|
# Get function listing for cross-distribution logic.
|
|
TYPESET=`typeset -f|grep "declare"`
|
|
|
|
# Get network config.
|
|
. /etc/sysconfig/network
|
|
|
|
DESC="PostgreSQL replication management and monitoring daemon"
|
|
NAME=repmgrd
|
|
|
|
REPMGRD_ENABLED=no
|
|
REPMGRD_OPTS=
|
|
REPMGRD_USER=postgres
|
|
REPMGRD_BIN=/usr/pgsql-9.3/bin/repmgrd
|
|
REPMGRD_PIDFILE=/var/run/repmgrd.pid
|
|
REPMGRD_LOCK=/var/lock/subsys/${NAME}
|
|
REPMGRD_LOG=/var/lib/pgsql/9.3/data/pg_log/repmgrd.log
|
|
|
|
# Read configuration variable file if it is present
|
|
[ -r /etc/sysconfig/$NAME ] && . /etc/sysconfig/$NAME
|
|
|
|
# For SELinux we need to use 'runuser' not 'su'
|
|
if [ -x /sbin/runuser ]
|
|
then
|
|
SU=runuser
|
|
else
|
|
SU=su
|
|
fi
|
|
|
|
test -x $REPMGRD_BIN || exit 0
|
|
|
|
case "$REPMGRD_ENABLED" in
|
|
[Yy]*)
|
|
break
|
|
;;
|
|
*)
|
|
exit 0
|
|
;;
|
|
esac
|
|
|
|
|
|
if [ -z "${REPMGRD_OPTS}" ]
|
|
then
|
|
echo "Not starting ${NAME}, REPMGRD_OPTS not set in /etc/sysconfig/${NAME}"
|
|
exit 0
|
|
fi
|
|
|
|
start()
|
|
{
|
|
REPMGRD_START=$"Starting ${NAME} service: "
|
|
|
|
# Make sure startup-time log file is valid
|
|
if [ ! -e "${REPMGRD_LOG}" -a ! -h "${REPMGRD_LOG}" ]
|
|
then
|
|
touch "${REPMGRD_LOG}" || exit 1
|
|
chown ${REPMGRD_USER}:postgres "${REPMGRD_LOG}"
|
|
chmod go-rwx "${REPMGRD_LOG}"
|
|
[ -x /sbin/restorecon ] && /sbin/restorecon "${REPMGRD_LOG}"
|
|
fi
|
|
|
|
echo -n "${REPMGRD_START}"
|
|
$SU -l $REPMGRD_USER -c "${REPMGRD_BIN} ${REPMGRD_OPTS} -p ${REPMGRD_PIDFILE} &" >> "${REPMGRD_LOG}" 2>&1 < /dev/null
|
|
sleep 2
|
|
pid=`head -n 1 "${REPMGRD_PIDFILE}" 2>/dev/null`
|
|
if [ "x${pid}" != "x" ]
|
|
then
|
|
success "${REPMGRD_START}"
|
|
touch "${REPMGRD_LOCK}"
|
|
echo $pid > "${REPMGRD_PIDFILE}"
|
|
echo
|
|
else
|
|
failure "${REPMGRD_START}"
|
|
echo
|
|
script_result=1
|
|
fi
|
|
}
|
|
|
|
stop()
|
|
{
|
|
echo -n $"Stopping ${NAME} service: "
|
|
if [ -e "${REPMGRD_LOCK}" ]
|
|
then
|
|
killproc ${NAME}
|
|
ret=$?
|
|
if [ $ret -eq 0 ]
|
|
then
|
|
echo_success
|
|
rm -f "${REPMGRD_PIDFILE}"
|
|
rm -f "${REPMGRD_LOCK}"
|
|
else
|
|
echo_failure
|
|
script_result=1
|
|
fi
|
|
else
|
|
# not running; per LSB standards this is "ok"
|
|
echo_success
|
|
fi
|
|
echo
|
|
}
|
|
|
|
|
|
# See how we were called.
|
|
case "$1" in
|
|
start)
|
|
start
|
|
;;
|
|
stop)
|
|
stop
|
|
;;
|
|
status)
|
|
status -p $REPMGRD_PIDFILE $NAME
|
|
script_result=$?
|
|
;;
|
|
restart)
|
|
stop
|
|
start
|
|
;;
|
|
*)
|
|
echo $"Usage: $0 {start|stop|status|restart}"
|
|
exit 2
|
|
esac
|
|
|
|
exit $script_result
|