Managing System Services in Oracle® Solaris 11.2

Exit Print View

Updated: July 2014
 
 

Creating a Service to Start or Stop an Oracle Database Instance

This example presents the following services that help manage the Oracle Database:

  • A database service that starts or stops an Oracle Database instance

  • A listener service that starts the listener, which is a process that manages the incoming traffic of client connection requests to the database instance

This example uses file-backed storage. An alternative to using file-backed storage is to use the Automatic Storage Management (ASM) feature. ASM is a volume manager and a file system for Oracle Database files.

The following environment variables must be set for each installation of the Oracle Database:

ORACLE_HOME

The location where the database is installed. In the example in this section, the location of the database installation is /opt/oracle/product/home.

ORACLE_SID

The systems ID to uniquely identify a particular database on a system.

In this example, these environment variables are set in the service manifests and then used in the method scripts.

Database Start and Stop Service

This section shows the Oracle Database instance control service manifest, /lib/svc/manifest/site/oracle.xml. The following are some features to note about this service manifest:

  • One service instance is defined, named svc:/site/application/database/oracle:default. This instance is enabled by default.

    This example shows two ways to define the default instance. In this example, the default instance is defined in the create_default_instance element at the top of the manifest. The instance element at the bottom of the manifest shows the other way to do this.

  • This service requires all local file systems to be mounted and all network interfaces to be initialized.

    If you are using a file-backed database, the database service should depend on the local filesystem. If you are using ASM, the database service should depend on the service that manages ASM. The database service should depend on networking to allow for remote client connections.

  • The method_environment element in the method_context element defines the ORACLE_HOME and ORACLE_SID environment variables, which identify the database instance to start or stop. These values are then available for the method script to use.

    If you create multiple instances of this service (see the instance element at the bottom of the manifest), then each instance might need its own method_context element to define the unique ORACLE_HOME and ORACLE_SID values for that particular database.

  • Attributes of the method_context element can define a resource pool in addition to the project and working directory shown in this example. You can also define either a method_profile or method_credential element in the method_context element. The method_credential element can specify supp_groups and limit_privileges values in addition to the user, group, and privileges values shown in this example. See the DTD for more information.

  • The start/stop method script is /lib/svc/method/oracle. The number of seconds before the method times out is increased from the default.

  • A user must be assigned the solaris.smf.manage.oracle authorization to enable or disable this service instance. In this example, the user oracle is assigned the solaris.smf.manage.oracle authorization.

<?xml version="1.0"?>

<!--
 Define a service to control the startup and shutdown of a database instance.
-->

<!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">

<service_bundle type="manifest" name="oracle">
<service name="site/application/database/oracle" type="service" version="1">
    <create_default_instance enabled="true" />

    <!--
         Wait for all local file systems to be mounted.
         Wait for all network interfaces to be initialized.
    -->

    <dependency type="service"
        name="fs-local"
        grouping="require_all"
        restart_on="none">
        <service_fmri value="svc:/system/filesystem/local" />
    </dependency>

    <dependency type="service"
        name="network"
        grouping="require_all"
        restart_on="none">
        <service_fmri value="svc:/milestone/network:default" />
    </dependency>

    <!-- Define the methods. -->

    <method_context project=":default" working_directory=":default">
        <method_credential user="oracle" group="dba" privileges=":default" />
        <method_environment>
            <envvar name="ORACLE_HOME" value="/opt/oracle/product/home" />
            <envvar name="ORACLE_SID" value="oracle" />
        </method_environment>
    </method_context>

    <exec_method type="method"
        name="start"
        exec="/lib/svc/method/oracle start"
        timeout_seconds="120"/>

    <exec_method type="method"
        name="stop"
        exec="/lib/svc/method/oracle stop"
        timeout_seconds="120" />

    <!--
         What authorization is needed to allow the framework
         general/enabled property to be changed when performing the
         action (enable, disable, etc) on the service.
    -->

    <property_group name="general" type="framework">
        <propval type="astring"
            name="action_authorization"
            value="solaris.smf.manage.oracle" />
    </property_group>

    <!-- Define an instance of the database. -->

    <!--<instance name="default" enabled="true" />-->

    <stability value="Evolving" />
</service>
</service_bundle>

Add name and description metadata to the manifest so that users can get information about this service from the svcs and svccfg describe commands. See the template element in the DTD.

Use the svccfg validate command to make sure the service manifest is valid.

The following is the start/stop method script, /lib/svc/method/oracle, for the Oracle Database instance control service. This method calls the database dbstart and dbshut commands.

#!/bin/ksh -p

. /lib/svc/share/smf_include.sh

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/lib
export PATH=$PATH:$ORACLE_HOME/bin

function startup
{
        dbstart $ORACLE_HOME
}

function shutdown
{
        dbshut $ORACLE_HOME
}

case $1 in
    start) startup ;;
    stop)  shutdown ;;

    *) echo "Usage: $0 { start | stop }" >&2
       exit $SMF_EXIT_ERR_FATAL
       ;;
esac

exit $SMF_EXIT_OK

Database Listener Service

The listener is a process that manages the incoming traffic of client connection requests to the database instance. The listener service depends on the database service instance whose client connections it is managing.

This section shows the Oracle Database instance listener service manifest, /lib/svc/manifest/site/listener.xml. The following are some features to note about this service manifest:

  • One service instance is defined, named svc:/site/application/database/listener:default. This instance is enabled by default.

  • This service requires the Oracle Database instance control service, svc:/site/application/database/oracle, to be started. If the database instance is restarted for any reason, the listener will also be restarted.

  • The method_environment element in the method_context element defines the ORACLE_HOME and ORACLE_SID environment variables, which identify the database instance to start or stop. These values are then available for the method script to use.

    If you create multiple instances of this service (see the instance element at the bottom of the manifest), then each instance might need its own method_context element to define the unique ORACLE_HOME and ORACLE_SID values for that particular database.

  • Attributes of the method_context element can define a resource pool in addition to the project and working directory shown in this example. You can also define either a method_profile or method_credential element in the method_context element. The method_credential element can specify supp_groups and limit_privileges values in addition to the user, group, and privileges values shown in this example. See the DTD for more information.

  • The start/stop method script is /lib/svc/method/listener. The number of seconds before the method times out is increased from the default.

  • A user must be assigned the solaris.smf.manage.oracle authorization to enable or disable this service instance.

  • The service is transient. See Service Models.

<?xml version="1.0"?>

<!--
 Define a service to control the startup and shutdown of a database listener.
-->

<!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">

<service_bundle type="manifest" name="listener">
<service name="site/application/database/listener" type="service" version="1">
    <create_default_instance enabled="true" />
    <!--<single_instance />-->

    <!-- Wait for the database to be started. -->

    <dependency type="service"
        name="oracle"
        grouping="require_all"
        restart_on="refresh">
        <service_fmri value="svc:/site/application/database/oracle" />
    </dependency>

    <!-- Define the methods. -->

    <method_context project=":default" working_directory=":default">
        <method_credential user="oracle" group="dba" privileges=":default" />
        <method_environment>
            <envvar name="ORACLE_HOME" value="/opt/oracle/product/home" />
            <envvar name="ORACLE_SID" value="oracle" />
        </method_environment>
    </method_context>

    <exec_method type="method"
        name="start"
        exec="/lib/svc/method/listener start"
        timeout_seconds="150"/>

    <exec_method type="method"
        name="stop"
        exec="/lib/svc/method/listener stop"
        timeout_seconds="30" />

    <!--
         What authorization is needed to allow the framework
         general/enabled property to be changed when performing the
         action (enable, disable, etc) on the service.
    -->

    <property_group name="general" type="framework">
        <propval type="astring"
            name="action_authorization"
            value="solaris.smf.manage.oracle" />
    </property_group>

    <!-- Make the instance transient (since it backgrounds itself). -->

    <property_group name="startd" type="framework">
        <propval name="duration" type="astring" value="transient" />
    </property_group>

    <!-- Define an instance of the listener. -->

    <!--<instance name="default" enabled="true" />-->

    <stability value="Evolving" />
</service>
</service_bundle>

Add name and description metadata to the manifest so that users can get information about this service from the svcs and svccfg describe commands. See the template element in the DTD.

The following is the start/stop method script, /lib/svc/method/listener, for the Oracle Database instance listener service. This method starts or stop a listener process, lsnrctl. When lsnrctl starts, it tests the status of the database service.

#!/bin/ksh -p

. /lib/svc/share/smf_include.sh

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/lib
export PATH=$PATH:$ORACLE_HOME/bin

function startup
{
        lsnrctl start

        # Wait for the listener to report ready.

        i=0
        while ! lsnrctl status | grep -i ready ; do
                ((i = i+1))
                if (( $i == 120 )) ; then
                        # It's been *at least* 2 minutes, time to give up.
                        echo "The listener failed to report ready." >&2
                        exit $SMF_EXIT_ERR_FATAL
                fi

                sleep 1
        done

        # Ping the database once to prove it is now available.

        if ! tnsping $ORACLE_SID ; then
                exit $SMF_EXIT_ERR_FATAL
        fi
}

function shutdown
{
        lsnrctl stop
}

case $1 in
    start) startup ;;
    stop)  shutdown ;;

    *) echo "Usage: $0 { start | stop }" >&2
       exit $SMF_EXIT_ERR_FATAL
       ;;
esac

exit $SMF_EXIT_OK