# $Id: Portfile,v 1.1 2006/05/23 21:55:44 mww Exp $

PortSystem 1.0

name			postgresql81-server
version			8.1.4
categories		databases
platforms		darwin
maintainers		mww@opendarwin.org
description		run postgresql81 as server
long_description	${description}

homepage		http://www.postgresql.org/
master_sites	postgresql

depends_run		port:postgresql81

fetch	{}
checksum	{}
extract	{}
configure	{}
build	{}

set libdir		${prefix}/lib/postgresql81
set dbdir		${prefix}/var/db/postgresql81/defaultdb
set logdir		${prefix}/var/log/postgresql81
set dbuser		postgres81
set dbgrp		postgres

startupitem.create	yes
startupitem.init	\
	"PGCTL=${libdir}/bin/pg_ctl"
startupitem.start	\
	"su ${dbuser} -c \"\${PGCTL} -D \${POSTGRESQL81DATA:=${dbdir}} start -l ${logdir}/postgres.log\""
startupitem.stop	\
"su ${dbuser} -c \"\${PGCTL} -D \${POSTGRESQL81DATA:=${dbdir}} stop -s -m fast\""

destroot {
	addgroup ${dbgrp}
	set gid [existsgroup ${dbgrp}]
	adduser ${dbuser} shell=/bin/sh gid=${gid} \
		home=${prefix}/var/db/postgresql81 \
		realname=PostgreSQL-81\ Server
	xinstall -m 755 -d ${destroot}${logdir}
	system "touch ${destroot}${logdir}/postgres.log"
	system "chown ${dbuser}:${dbgrp} ${destroot}${logdir}/postgres.log"
}

post-install {
	ui_msg "\nTo create a database instance, after install do\n\
		sudo mkdir -p ${dbdir}\n\
		sudo chown ${dbuser}:${dbgrp} ${dbdir}\n\
		sudo su ${dbuser} -c \'${libdir}/bin/initdb -D ${dbdir}\'"
	ui_msg "\nTo tweak your DBMS, consider increasing kern.sysv.shmmax\
		by adding an increased kern.sysv.shmmax .. to /etc/sysctl.conf"
}

