init 1.99 KB
Newer Older
Bernd Zeimetz's avatar
Bernd Zeimetz committed
1
#!/bin/bash
2

3
### BEGIN INIT INFO
4 5 6 7
# Provides:          pgbouncer
# Required-Start:    $syslog $remote_fs
# Required-Stop:     $syslog $remote_fs
# Should-Start:      postgresql
8 9
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
10 11
# Short-Description: start pgbouncer
# Description: pgbouncer is a connection pool server and replication
12
#              proxy for PostgreSQL.
13 14 15
### END INIT INFO


16 17 18
PATH=/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/sbin/pgbouncer
PIDFILE=/var/run/postgresql/pgbouncer.pid
19
OPTS="-d /etc/pgbouncer/pgbouncer.ini"
20

21
test -x $DAEMON || exit 5
22

23 24 25 26
# Include pgbouncer defaults if available
if [ -f /etc/default/pgbouncer ] ; then
	. /etc/default/pgbouncer
fi
27 28 29 30 31


. /lib/lsb/init-functions


32 33
is_running() {
	pidofproc -p $PIDFILE $DAEMON >/dev/null
34 35
}

36 37 38 39 40

d_start() {
	if is_running; then
		:
	else
41
		su -c "$DAEMON $OPTS 2> /dev/null &" - postgres
42
	fi
43 44
}

Bernd Zeimetz's avatar
Bernd Zeimetz committed
45 46 47 48
d_reload() {
    is_running || return 0

    killproc -p $PIDFILE $DAEMON HUP
49 50
}

Bernd Zeimetz's avatar
Bernd Zeimetz committed
51 52 53 54 55 56 57 58 59 60 61
d_stop() {
    SIGS='INT TERM KILL'

    for sig in $SIGS
    do
	is_running || return 0

	killproc -p $PIDFILE $DAEMON $sig
	sleep 1
    done
}
62

63
case "$1" in
64
    start)
65
        if [ ${START} -eq 1 ]; then
Bernd Zeimetz's avatar
Bernd Zeimetz committed
66
		log_daemon_msg Starting pgbouncer
67 68 69 70 71
		d_start
		log_end_msg $?
	else
		log_warning_msg "pgbouncer daemon disabled in /etc/default/pgbouncer"
	fi
72
	;;
73
    stop)
Bernd Zeimetz's avatar
Bernd Zeimetz committed
74
	log_daemon_msg Stopping pgbouncer
75 76
	d_stop
	log_end_msg $?
77
	;;
78 79 80 81
    status)
	is_running
	status=$?
	if [ $status -eq 0 ]; then
82
		log_success_msg "pgbouncer is running."
83
	else
84
		log_failure_msg "pgbouncer is not running."
85 86 87
	fi
	exit $status
	;;
88
    restart)
89
	log_daemon_msg "Restarting pgbouncer" pgbouncer
Bernd Zeimetz's avatar
Bernd Zeimetz committed
90 91
	d_stop
	d_start
92 93 94 95 96 97 98 99
	log_end_msg $?
	;;
    try-restart)
	if $0 status >/dev/null; then
		$0 restart
	else
		exit 0
	fi
100
	;;
101
    reload|force-reload)
Bernd Zeimetz's avatar
Bernd Zeimetz committed
102 103
	if is_running; then
		log_daemon_msg "Reloading configuration" pgbouncer
Bernd Zeimetz's avatar
Bernd Zeimetz committed
104
		d_reload
Bernd Zeimetz's avatar
Bernd Zeimetz committed
105 106 107 108
		log_end_msg $?
	else
		log_failure_msg "pgbouncer is not running."
	fi
109
	;;
110 111 112 113
    *)
	log_failure_msg "Usage: $0 {start|stop|status|restart|try-restart|reload|force-reload}"
	exit 2
	;;
114
esac