Subject: postgresql question [ bit OT ]
To: None <netbsd-help@netbsd.org>
From: Rasputin <rasputin@idoru.mine.nu>
List: netbsd-help
Date: 05/17/2002 11:17:29
--lrZ03NoBR/3+SXJZ
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline


Hi there, this is maybe a bit off-topic, but it's a rc question really.

I've just setup postgresql and given a password to
the pgsql Postgres superuser.

Problem now is it prompts for a password before it starts up, which means
I  need to be there whe nthe machine boots. Bummer.

All I need to do (probably) is pipe the password into the startup command;
trouble is I can't make head nor tail of the rc script
(attached)

What variables should I change - any clues?

Thanks, and sorry again for asking here.
-- 
Rasputin :: Jack of All Trades - Master of Nuns

--lrZ03NoBR/3+SXJZ
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=pgsql

#!/bin/sh
#
# $NetBSD: pgsql.sh,v 1.9 2002/04/05 16:23:23 jlam Exp $
#
# PostgreSQL database rc.d control script
#
# PROVIDE: pgsql
# REQUIRE: DAEMON
# KEYWORD: shutdown
#
# You will need to set some variables in /etc/rc.conf to start PostgreSQL:
#
# pgsql=YES
#	pgsql_flags="-i"	# allows TCP/IP connections
#	pgsql_flags="-i -l"	# enables SSL connections (TCP/IP required)
#
# "pgsql_flags" contains options for the PostgreSQL postmaster.  See
# postmaster(1) for possible options.

PGHOME="/usr/pkg/pgsql"

if [ -f /etc/rc.subr ]
then
	. /etc/rc.subr
fi

rcd_dir=`/usr/bin/dirname $0`

name="pgsql"
rcvar=$name
pgsql_user="pgsql"
command="/usr/pkg/bin/postmaster"
ctl_command="/usr/pkg/bin/pg_ctl"
pidfile="${PGHOME}/data/postmaster.pid"
extra_commands="initdb"

command_args="-D ${PGHOME}/data"
start_command_args="-w -s -l ${PGHOME}/errlog"
stop_command_args="-s -m fast"

initdb_cmd="pgsql_initdb"
start_precmd="pgsql_precmd"
start_cmd="pgsql_doit start"
restart_cmd="pgsql_doit restart"
stop_cmd="pgsql_doit stop"

pgsql_precmd()
{
	if [ ! -f ${PGHOME}/data/base/1/PG_VERSION ]
	then
		$rcd_dir/pgsql initdb
	fi
}

pgsql_initdb()
{
	initdb="/usr/pkg/bin/initdb"

	if [ ! -x ${initdb} ]
	then
		return
	fi
	if [ -f ${PGHOME}/data/base/1/PG_VERSION ]
	then
		echo "The PostgreSQL template databases have already been initialized."
		echo "Skipping database initialization."
	else
		echo "Initializing PostgreSQL databases."
		/usr/bin/su -m ${pgsql_user} -c "${initdb} ${command_args} ${flags}"
	fi
}

pgsql_doit()
{
	action=$1

	case ${action} in
	start|restart)
		command_args="${command_args} ${start_command_args}"
		if [ -n "${pgsql_flags}" ]
		then
			command_args="${command_args} -o \"${pgsql_flags}\""
		fi
		;;
	stop)
		command_args="${command_args} ${stop_command_args}"
		;;
	esac

	if [ ! -x ${ctl_command} ]
	then
		return
	fi

	case ${action} in
	start)		echo "Starting ${name}." ;;
	stop)		echo "Stopping ${name}." ;;
	restart)	echo "Restarting ${name}." ;;
	esac

	/usr/bin/su -m ${pgsql_user} -c "${ctl_command} ${action} ${command_args}"
}

if [ -f /etc/rc.subr ]
then
	load_rc_config $name
	run_rc_command "$1"
else
	if [ -f /etc/rc.conf ]
	then
		. /etc/rc.conf
	fi
	case "$1" in
	initdb)
		eval ${initdb_cmd}
		;;
	restart)
		eval ${restart_cmd}
		;;
	stop)
		eval ${stop_cmd}
		;;
	*)
		eval ${start_precmd}
		eval ${start_cmd}
		;;
	esac
fi

--lrZ03NoBR/3+SXJZ--