summaryrefslogtreecommitdiff
blob: f2a90ef55d09593d9708cd7454ea66ccae8c30da (plain)
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
#!/sbin/runscript
# Copyright 1999-2007 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

opts="${opts} reload"

depend() {
	use net
	if [ -L /etc/eselect/postgresql/service ] ; then 
		local p_service="$(for f in /etc/eselect/postgresql/service/* ; do source $f ; done ; echo $postgres_service )"
		test "${p_service}" = "${SVCNAME}" && provide postgresql
	fi
}

checkconfig() {
	if [ ! -d "$PGDATA" ] ; then
		eerror "Directory not found: $PGDATA"
		eerror "Please make sure that PGDATA points to the right path."
		eerror "You can run 'emerge postgresql-server --config' to setup a new database cluster."
		return 1
	fi
}

start() {
	checkconfig || return 1

	ebegin "Starting PostgreSQL"

	if [ -f "$PGDATA/postmaster.pid" ] ; then
		rm -f "$PGDATA/postmaster.pid"
	fi

	start-stop-daemon --start \
		--pidfile "${PGDATA}/postmaster.pid" \
		--chuid ${PGUSER}:${PGGROUP} \
		--exec /usr/lib/postgresql-8.3/bin/postmaster \
		-- \
		-D "${PGDATA}" \
		--silent-mode=true \
		${PGOPTS}

	eend $?
}

stop() {
	ebegin "Stopping PostgreSQL"
	# Note: we have to do --oknodo here, otherwise it will always fail
	#       when there are open transactions. This bug has been corrected
	#       in baselayout-1.13.0_alpha8.
	start-stop-daemon --stop --pidfile "${PGDATA}/postmaster.pid" \
		--retry -TERM/${WAIT_FOR_DISCONNECT}/-INT/${WAIT_FOR_CLEANUP}/-QUIT --oknodo
	eend $?
}

reload() {
	ebegin "Reloading PostgreSQL configuration"
	start-stop-daemon --stop --pidfile "${PGDATA}/postmaster.pid" --signal HUP --oknodo
	eend $?
}