File: init

package info (click to toggle)
pgbouncer 1.3.3-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 932 kB
  • ctags: 1,085
  • sloc: ansic: 8,710; sh: 490; makefile: 213; python: 99
file content (114 lines) | stat: -rw-r--r-- 2,037 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/bin/bash

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


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

test -x $DAEMON || exit 5

# Include pgbouncer defaults if available
if [ -f /etc/default/pgbouncer ] ; then
	. /etc/default/pgbouncer
fi


. /lib/lsb/init-functions


is_running() {
	pidofproc -p $PIDFILE $DAEMON >/dev/null
}


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

d_reload() {
    is_running || return 0

    killproc -p $PIDFILE $DAEMON HUP
}

d_stop() {
    SIGS='INT TERM KILL'

    for sig in $SIGS
    do
	is_running || return 0

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

case "$1" in
    start)
        if [ ${START} -eq 1 ]; then
		log_daemon_msg Starting pgbouncer
		d_start
		log_end_msg $?
	else
		log_warning_msg "pgbouncer daemon disabled in /etc/default/pgbouncer"
	fi
	;;
    stop)
	log_daemon_msg Stopping pgbouncer
	d_stop
	log_end_msg $?
	;;
    status)
	is_running
	status=$?
	if [ $status -eq 0 ]; then
		log_success_msg "pgbouncer is running"
	else
		log_failure_msg "pgbouncer is not running"
	fi
	exit $status
	;;
    restart)
	log_daemon_msg "Restarting pgbouncer" pgbouncer
	d_stop
	d_start
	log_end_msg $?
	;;
    try-restart)
	if $0 status >/dev/null; then
		$0 restart
	else
		exit 0
	fi
	;;
    reload|force-reload)
	if is_running; then
		log_daemon_msg "Reloading configuration" pgbouncer
		d_reload
		log_end_msg $?
	else
		log_failure_msg "pgbouncer is not running."
	fi
	;;
    *)
	log_failure_msg "Usage: $0 {start|stop|status|restart|try-restart|reload|force-reload}"
	exit 2
	;;
esac