#!/bin/sh
#
# Script for starting and stoping pg_autovacuum.
#
# Writen by Olivier Thauvin <nanardon@mandrake.org>
#
# chkconfig: 345 86 14
# description: Automatically run vacuum on PostgreSQL database.
#       PostgreSQL database need to having ran periodically VACUUM to reset
#       internal index and recovering disk space. pg_autovacuum monitor the
#       database periodically and run VACUUM when need.

# Source function library.
. /etc/rc.d/init.d/functions

[ -f /etc/sysconfig/pg_autovacuum ] && . /etc/sysconfig/pg_autovacuum

[ -z "$PGAV_USER" ] && PGAV_USER="postgres"

# See how we were called.
case "$1" in
  start)
        echo -n "Starting pg_autovacuum: "
        daemon --user "$PGAV_USER" pg_autovacuum -D $PGAV_OPTION
        echo
        touch /var/lock/subsys/pg_autovacuum
        ;;
  stop)
        echo -n "Stopping pg_autovacuum: "
        killproc pg_autovacuum
        echo
        rm -f /var/lock/subsys/pg_autovacuum
        ;;
  restart|reload)
        $0 stop
        $0 start
        ;;
  status)
        status pg_autovacuum
        ;;
  *)
        echo "Usage: pg_autovacuum {start|stop|restart|status}"
        exit 1
esac

exit 0
