Go to main content

Developing System Services in Oracle® Solaris 11.3

Exit Print View

Updated: September 2018

Creating a Service to Start or Stop an Oracle Database Instance

This section describes the Oracle Database instance control service manifest and the start/stop method script that is used in that manifest.

Database Instance Control Service Manifest

The following are some features to note about the Oracle Database instance control service. See the service manifest following this list.

  • In this example, the service name and manifest name are the same. The service is named site/oracle/db/database. The manifest file name is database.xml and is located at /lib/svc/manifest/site/oracle/db/database.xml.

  • No default instance is defined for this service. Add instances by using the svccfg add command. The name of each instance must match the name of an Oracle Database instance.

  • Two dependencies are defined.

    • The dependency on svc:/system/filesystem/local requires all local file systems to be mounted. 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 dependency on svc:/milestone/multi-user requires the system to reach the multi-user milestone before this database service starts.

  • The method_context element specifies credentials and resources required to run the method script. In addition to the attributes shown in this example, the method_context element can specify attributes such as project, working_directory, and resource_pool. See the smf_method(5) man page and the DTD for more information.

    • The method_credential element in the method_context element specifies that, except for the super user, only the user oracle in the group oinstall can execute the methods of this service. The method_credential element can specify other attributes such as supp_groups and limit_privileges. You can also define a method_profile element instead of the method_credential element shown in this example.

    • The method_environment element in the method_context element sets the ORACLE_HOME environment variable. This value is used in the method script to find Oracle libraries and commands.

  • The start/stop method script is /lib/svc/method/svc-oracle-database.

    • db specifies to call the database start or stop function instead of the listener start or stop function. This same method script is used by the listener service.

    • %m is the name of the method: either start or stop. This specifies whether to call the start function or the stop function in the method script.

    • %i is the service instance name. This value is assigned to ORACLE_SID in the method script, so be sure to give the service instance the same name as the database instance.

    • timeout_seconds="0" means this method execution has no time constraint.

    See the smf_method(5) man page for more information about %m, %i, and timeout_seconds.

  • The action_authorization property requires that a user must be assigned the solaris.smf.manage.oracle authorization to perform tasks such as enable this service or modify properties. See the smf_security(5) man page for more information.

<?xml version="1.0"?>
<!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">
	Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.

	Define a service to start or stop an Oracle Database instance.

<service_bundle type="manifest" name="site/oracle/db/database">
  <service name="site/oracle/db/database" type="service" version="1">

    <dependency type="service"
        <service_fmri value="svc:/system/filesystem/local"/>

    <dependency type="service"
        <service_fmri value="svc:/milestone/multi-user"/>

      <method_credential user="oracle" group="oinstall" />
        <envvar name="ORACLE_HOME" value="/opt/oracle/product/home" />

    <exec_method type="method"
        exec="/lib/svc/method/svc-oracle-database db %m %i"

    <exec_method type="method"
        exec="/lib/svc/method/svc-oracle-database db %m %i"

    <property_group name="general" type="framework">
      <propval type="astring"

    <stability value="Evolving"/>

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.

Ensure the service manifest is valid:

# svccfg validate database.xml

To install the service, copy the manifest to /lib/svc/manifest and restart the manifest-import service:

# mkdir -p /lib/svc/manifest/site/oracle/db
# cp database.xml /lib/svc/manifest/site/oracle/db
# svcadm restart manifest-import

Note -  Before you enable the service, create and install the method script (Start/Stop Method Script for the Oracle Database Instance Control Service) and add service instances (Add Database Service Instances).

Start/Stop Method Script for the Oracle Database Instance Control Service

The following is the start/stop method script, svc-oracle-database, for both the database service and the listener service. This method uses the sqlplus command to start and stop database service instances, and uses the lsnrctl command to start and stop listener service instances.

# Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.

# Load SMF constants and functions
. /lib/svc/share/smf_include.sh

if [[ -z "$SMF_FMRI" ]]; then
	echo "this script can only be invoked by smf(5)"

[[ -d "$ORACLE_HOME" || -d "$ORACLE_HOME/lib" ]] || \
	smf_method_exit $SMF_EXIT_ERR_CONFIG dir_failed "ORACLE_HOME: $ORACLE_HOME: directory is not set properly"


	"$ORACLE_HOME/bin/lsnrctl" stop "$1" || exit $SMF_EXIT_ERR_FATAL

	if "$ORACLE_HOME/bin/lsnrctl" status "$1" >/dev/null; then
		echo "Listener '$1' has already been started - restart it now ..."
		"$ORACLE_HOME/bin/lsnrctl" stop "$1" || exit $SMF_EXIT_ERR_FATAL

	"$ORACLE_HOME/bin/lsnrctl" start "$1" || exit $SMF_EXIT_ERR_FATAL

	export ORACLE_SID="$1"

	"$ORACLE_HOME/bin/sqlplus" /nolog <<-EOF || exit $SMF_EXIT_ERR_FATAL
		connect / as sysdba
		shutdown immediate

	export ORACLE_SID="$1"

	"$ORACLE_HOME/bin/sqlplus" /nolog <<-EOF || exit $SMF_EXIT_ERR_FATAL
		connect / as sysdba

case "$1:$2" in
	"listener:start") start_listener "$3";;
	"listener:stop") stop_listener "$3";;
	"db:start") start_database "$3";;
	"db:stop") stop_database "$3";;
		echo "Usage: $0 {db|listener} {start|stop} {ORACLE_SID}"

Install the method script:

# cp svc-oracle-database /lib/svc/method

Typically, method scripts have the following ownership:

# chown root:bin /lib/svc/method/svc-oracle-database

Ensure the script is executable. Typically, method scripts have the following access:

# chmod 555 /lib/svc/method/svc-oracle-database

Add Database Service Instances

Verify that the start/stop method script is installed and executable.

Add instances by using the svccfg add command and specifying the name of a database instance as the name of the service instance. In the following example, sales_db is the name of an Oracle Database instance:

$ svccfg -s site/oracle/db/database add sales_db
$ svccfg -s database:sales_db
svc:/site/oracle/db/database:sales_db> addpropvalue general/complete astring: dev
svc:/site/oracle/db/database:sales_db> addpropvalue general/enabled boolean: true
svc:/site/oracle/db/database:sales_db> refresh
svc:/site/oracle/db/database:sales_db> exit

The service method uses the service instance name to select the Oracle Database on which to operate. In this example, the following command starts the sales_db Oracle Database instance:

# svcadm enable database:sales_db

Note that the preceding svccfg command set this service instance to be enabled by default.

Verify that the database service is installed and the sales_db instance is online:

# svcs database

The following command stops the sales_db Oracle Database instance:

# svcadm disable database:sales_db