Sophie

Sophie

distrib > Mandriva > 2010.1 > i586 > by-pkgid > 9238952a3334eba77c7691696483b160 > files > 7

postgresql-pgpool-II-2.3.3-1mdv2010.1.i586.rpm

#!/bin/sh
# Author: Per Øyvind Karlsen <peroyvind@mandriva.org>
# 	  (c) 2010 - Linus AS (http://www.linus.no)
# Inspired by Fedora init script by Devrim GUNDUZ <devrim@CommandPrompt.com>
#
# chkconfig:      345 95 33
# pidfile:        /var/run/pgpool/pgpool.pid

### BEGIN INIT INFO
# Provides:       pgpool
# Required-Start: $local_fs $network $postgresql
# Required-Stop:  $local_fs $network $postgresql
# Default-Start:        3 4 5
# Default-Stop:   0 1 2       6
# Short-Description: PostgreSQL pgpool-II daemon
# Description:    pgpool-II is a connection pooling/replication server for PostgreSQL.
### END INIT INFO

. /etc/init.d/functions

if [ -r /etc/sysconfig/pgpool ]; then
    . /etc/sysconfig/pgpool
fi

# Get config.
. /etc/sysconfig/network

# Set defaults for configuration variables
PGPOOLDAEMON=/usr/bin/pgpool
PGPOOLCONF=/etc/pgpool-II/pgpool.conf

NAME=pgpool-II
BASEBIN="$(basename $PGPOOLDAEMON)"
LOCK_FILE="/var/lock/subsys/${BASEBIN}"
PID_FILE="/var/run/pgpool/${BASEBIN}.pid"

if [ ! -x "$PGPOOLDAEMON" ]; then
    [ "$1" = "stop" ] && exit 0
    gprintf "%s needs to exist and be executable\n" "$PGPOOLDAEMON"
    exit 5
fi

# Check whether the config file exists or not
if [ ! -r "$PGPOOLCONF" ]; then
    [ "$1" = "stop" ] && exit 0
    gprintf "%s needs to exist and be readable\n" "$PGPOOLCONF"
    exit 6
fi

RETVAL=0

start(){
	gprintf "Starting %s service: " "${NAME}"
	daemon --check ${PGPOOLDAEMON} --pidfile ${PID_FILE} --user postgres "${PGPOOLDAEMON} ${PGPOOLOPTS}"
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && touch $LOCK_FILE
	return $RETVAL
}

stop(){
	gprintf "Shutting down %s service: " "${NAME}"
	${PGPOOLDAEMON} stop 2>&1|tr -d "\n" >&2
	RETVAL=${PIPESTATUS[0]}
	if [ $RETVAL -eq 0 ]; then
		echo_success
		rm -f $LOCK_FILE
	else
		echo_failure
	fi
	echo
	return $RETVAL
}

reload(){
	gprintf "Reloading %s: " "${NAME}"
	rh_status_q

	if [ $RETVAL -eq 0 ]; then
		$PGPOOLDAEMON reload
		RETVAL=$?
	else
		rh_status
	fi
	if [ $RETVAL -eq 0 ]; then
		echo_success
	else
		echo_failure
	fi
	echo
	return $RETVAL
}

rh_status() {
	rh_status_q
        RETVAL=$?
	status $BASEBIN
	return $RETVAL
}

rh_status_q() {
	# -l argument doesn't exist on MES 5, but is automatically set
	# to /var/lock/$BASEBIN anyways..
	#status -p $PID_FILE -l $LOCK_FILE $BASEBIN &&
	status -p $PID_FILE $BASEBIN >/dev/null 2>&1

	RETVAL=$?
	return $RETVAL
}

# See how we were called.
case "$1" in
  start)
	rh_status_q && exit 0
        $1
        ;;
  stop)
        $1
        ;;
  status)
	rh_status
        ;;
  restart)
	stop
        start
        ;;
  reload|force-reload)
        reload
        ;;
  condrestart|try-restart)
	rh_status_q || exit 0
	stop
	start
        ;;
  condstop)
	rh_status_q || exit 0  
        stop
        ;;
  *)
        gprintf "Usage: %s {start|stop|status|restart|condrestart|condstop|reload|force-reload}\n" $0
	RETVAL=2
esac

exit $RETVAL