NOTE: You should disable your init scripts in /etc/rc2.d /etc/rc3.d AND make sure you have a setup/working pgdata directory somewhere. REVIEW These files before you add them to make sure they suit your needs!
First we must create a:
/var/svc/manifest/site/pgsql.xml
file that contains the following:
<?xml version='1.0'?>
<!DOCTYPE service_bundle SYSTEM '/usr/share/lib/xml/dtd/service_bundle.dtd.1'>
<!--
William Pool (Puddle) 06/05
e-mail: rotaecho@yahoo.com
Service manifest for pgsql
-->
<service_bundle type='manifest' name='pgsql`:default'>
<service
name='site/pgsql'
type='service'
version='1'>
<create_default_instance enabled='false' />
<single_instance />
<dependency name='fs'
grouping='require_all'
restart_on='none'
type='service'>
<service_fmri value='svc:/system/filesystem/local' />
</dependency>
<dependency name='net'
grouping='require_all'
restart_on='none'
type='service'>
<service_fmri value='svc:/network/loopback' />
</dependency>
<exec_method
type='method'
name='start'
exec='/lib/svc/method/svc-pgsql start'
timeout_seconds='-1'>
<method_context>
<method_credential user='pgsql' group='pgsql' />
</method_context>
</exec_method>
<exec_method
type='method'
name='stop'
exec='/lib/svc/method/svc-pgsql stop'
timeout_seconds='-1'>
</exec_method>
<exec_method
type='method'
name='restart'
exec='/lib/svc/method/svc-pgsql restart'
timeout_seconds='-1'>
</exec_method>
<exec_method
type='method'
name='refresh'
exec='/lib/svc/method/svc-pgsql8 refresh'
timeout_seconds='-1'>
</exec_method>
</service>
</service_bundle>
Now, we need to create a method file:
/lib/svc/method/svc-pgsql
which contains:
#!/bin/ksh
# PostgreSQL startup script
# Date: 05/06
# William Pool
# rotaecho@yahoo.com
. /lib/svc/share/smf_include.sh
# Read in the user configuration file
[ -s /var/pgdata/postgresql.conf ] && . /var/pgdata/postgresql.conf
# Defaults
[ -z "$PGDATA" ] && PGDATA=/var/pgdata
[ -z "$PGCTL" ] && PGCTL=/opt/sfw/pgsql8/bin/pg_ctl
[ -z "$PGINIT" ] && PGINIT=/opt/sfw/pgsql8/bin/initdb
# Exit if postgres user hasn't been created.
grep '^pgsql:' /etc/passwd >/dev/null
if [ $? -ne 0 ] ; then
getent passwd pgsql >/dev/null
if [ $? -ne 0 ] ; then
exit 0
fi
fi
# Change to a directory that pg_ctl etc. can read - startup fails
# otherwise
cd /var/tmp
case "$1" in
start)
if [ -d $PGDATA -a `ls -l $PGDATA 2> /dev/null | wc -l` -gt 1 ]; then
# PostgreSQL data directory exists and is populated
echo "Starting PostgreSQL..."
$PGCTL start -D $PGDATA -l $PGDATA/postgresql.log $SERVEROPTS
fi
;;
stop)
echo "Stopping PostgreSQL database..."
su pgsql -c "$PGCTL stop -D $PGDATA -m f"
;;
restart)
echo "Restarting PostgreSQL database..."
su pgsql -c "$PGCTL restart -D $PGDATA -m f $SERVEROPTS"
;;
refresh)
echo "Reloading PostgreSQL database..."
su pgsql -c "$PGCTL reload -D $PGDATA"
;;
status)
su pgsql -c "$PGCTL status -D $PGDATA"
;;
init)
# create and initialise data directory
echo "Creating PostgreSQL data directory at $PGDATA..."
# Create it, unless it's already there and empty
[ -d $PGDATA -a `ls -l $PGDATA 2> /dev/null | wc -l` -eq 1 ] || mkdir -p $PGDATA
chown pgsql $PGDATA
echo "Initialising PostgreSQL database..."
su pgsql -c "$PGINIT -D $PGDATA > /dev/null"
;;
*)
echo "Usage: $0 (init|start|stop|restart|reload|status)"
;;
esac
exit 0
Change permissions of the files:
chmod 555 /lib/svc/method/svc-pgsql chown root:bin /lib/svc/method/svc-pgsql chmod 444 /var/svc/manifest/site/pgsql.xml chown root:sys /var/svc/manifest/site/pgsql.xml
Install the PostgreSQL SMF
/usr/sbin/svccfg import /var/svc/manifest/site/pgsql.xml /usr/sbin/svcadm -v enable|disable|restart pgsql
