PostgreSql veritabanı sunucusunun servis olarak çalıştırılması

NOT: Konfigürasyon 64-bit Solaris 10 işletim sistemi üzerinde yapılmıştır.

1. Svc konfigürasyon dosyalarının olduğu klasöre (/var/svc/manifest/application/database) aşağıdaki xml dosyası postgresql_84.xml ismi ile kaydedilir.

<?xml version="1.0"?>
<!DOCTYPE service_bundle SYSTEM"/usr/share/lib/xml/dtd/service_bundle.dtd.1">
<!-- Copyright 2006 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms. CDDL HEADER START The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License. You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License. When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner] CDDL HEADER END ident "%Z%%M% %I% %E SMI" NOTE: This service manifest is not editable; its contents will be overwritten by package or patch operations, including operating system upgrade. Make customizations in a different file. -->
<service_bundle type='manifest' name='postgresql_84'>
      <service name='application/database/postgresql_84' type='service' version='1'>
            <!-- Wait for network interfaces to be initialized. -->
            <dependency name='network' grouping='require_all' restart_on='none' type='service'>
                  <service_fmri value='svc:/milestone/network:default' />
            </dependency>
            <!-- Wait for all local filesystems to be mounted. -->
            <dependency name='filesystem-local' grouping='require_all' restart_on='none' type='service'>
                  <service_fmri value='svc:/system/filesystem/local:default' />
            </dependency>
            <exec_method type='method' name='start' exec='/lib/svc/method/postgresql_84 start' timeout_seconds='300' />
            <exec_method type='method' name='stop' exec='/lib/svc/method/postgresql_84 stop' timeout_seconds='300' />
            <exec_method type='method' name='refresh' exec='/lib/svc/method/postgresql_84 refresh' timeout_seconds='60' />
            <!-- We define two instances of PostgreSQL as examples. -->
            <instance name='default' enabled='false'>
                  <method_context>
                        <method_credential user='postgres' group='postgres' />
                  </method_context>
                  <!-- Make sure the data configurable property points to the appropriate database directory. -->
                  <property_group name='postgresql_84' type='application'>
                        <propval name="bin" type="astring" value="/usr/postgres/8.4-community/bin/64"/>
                        <propval name='data' type='astring' value='/var/lib/pgsql/data' />
                        <propval name='log' type='astring' value='/var/lib/pgsql/data/postmaster.log' />
                  </property_group>
            </instance>
            <stability value='Evolving' />
            <template>
                  <common_name>
                        <loctext xml:lang='C'> PostgreSQL RDBMS </loctext>
                  </common_name>
                  <documentation>
                        <manpage title='postgres' section='1M' />
                        <doc_link name='postgresql.org' uri='http://postgresql.org' />
                  </documentation>
            </template>
      </service>
</service_bundle>

2. Aşağıdaki shell script /lib/svc/method klasörü altına postgresql_84 ismi ile kaydedilir

#!/sbin/sh
#
# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#
#ident	"@(#)postgresql	1.3	08/02/08 SMI"

. /lib/svc/share/smf_include.sh

# SMF_FMRI is the name of the target service. This allows multiple instances
# to use the same script.

getproparg() {
        val=`svcprop -p $1 $SMF_FMRI`
        [ -n "$val" ] && echo $val
}

check_data_dir() {
	if [ ! -d $PGDATA ]; then
		echo "Error: postgresql/data directory $PGDATA does not exist"
		exit $SMF_EXIT_ERR_CONFIG
	fi

	if [ ! -w $PGDATA ]; then
		echo "Error: postgresql/data directory $PGDATA is not writable by postgres"
		exit $SMF_EXIT_ERR_CONFIG
	fi

	if [ ! -d $PGDATA/base -o ! -d $PGDATA/global -o ! -f $PGDATA/PG_VERSION ]; then
		# If the directory is empty we can create the database files
		# on behalf of the user using initdb
		if [ `ls -a $PGDATA | wc -w` -le 2 ]; then
			echo "Notice: postgresql/data directory $PGDATA is empty"
			echo "Calling '$PGBIN/initdb -D $PGDATA' to initialize"

			$PGBIN/initdb -D $PGDATA
			if [ $? -ne 0 ]; then
				echo "Error: initdb failed"
				exit $SMF_EXIT_ERR
			fi
		else
			echo "Error: postgresql/data directory $PGDATA is not empty, nor is it a valid PostgreSQL data directory"
			exit $SMF_EXIT_ERR_CONFIG
		fi
	fi
}

PGBIN=`getproparg postgresql/bin`
PGDATA=`getproparg postgresql/data`
PGLOG=`getproparg postgresql/log`

if [ -z $SMF_FMRI ]; then
	echo "Error: SMF framework variables are not initialized"
	exit $SMF_EXIT_ERR
fi

if [ -z $PGDATA ]; then
        echo "Error: postgresql/data property not set"
        exit $SMF_EXIT_ERR_CONFIG
fi

if [ -z $PGLOG ]; then
        echo "Error: postgresql/log property not set"
        exit $SMF_EXIT_ERR_CONFIG
fi

case "$1" in
'start')
	check_data_dir
        $PGBIN/pg_ctl -D $PGDATA -l $PGDATA/$PGLOG start
        ;;

'stop')
        $PGBIN/pg_ctl -D $PGDATA stop
        ;;

'refresh')
        $PGBIN/pg_ctl -D $PGDATA reload
        ;;

*)
        echo "Usage: $0 {start|stop|refresh}"
        exit 1
        ;;

esac
exit $SMF_EXIT_OK

3. postgresql_84 dosyasına gerekli dosya nitelikleri verilir

chmod 555 /lib/svc/method/postgresql_84

4. Aşağıdaki komutlar çalıştırılarak SMF Manifest içine postgresql_84.xml import edilir

# cd /var/svc/manifest/application/database
# /usr/sbin/svccfg import postgresql_84.xml

5. Öntanımlı olarak import edilen servis “disabled” durumdadır. Servisin durumunu görmek için aşağıdaki komut çalıştırılır

# svcs postgresql

6. Servisi çalıştırmak için aşağıdaki komut çalıştırılır

# /usr/sbin/svcadm enable postgresql:postgresql_84

7. Servisi durdurmak için aşağıdaki komut çalıştırılır

# /usr/sbin/svcadm disable postgresql:postgresql_84
  1. Henüz yorum yapılmamış.
  1. No trackbacks yet.

Yorum bırakın