Manage Oracle Database and Listener under Solaris SMF service

At OmniTi, we support various databases i.e oracle,postgresql,mysql etc.. Most of the databases are on Solaris servers.  Solaris has many cool features for easy database management, one of them is SMF services.


We manage all the databases under Solaris SMF service. Today, I am going to provide details to do so for oracle.
Needed Files for  Database Service:

1.  oracle.xml
2.  startup.sql
2.  shutdown.sql      

$cat oracle.xml

<?xml version='1.0'?>

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

<service_bundle type='manifest' name='export'>

  <service name='database/oracle' type='service' version='0'>

    <create_default_instance enabled='false'/>

    <single_instance/>

    <dependency name='fs-local' grouping='require_all' restart_on='none' type='service'>

      <service_fmri value='svc:/system/filesystem/local'/>

    </dependency>

    <dependency name='network-service' grouping='require_all' restart_on='none' type='service'>

      <service_fmri value='svc:/network/service'/>

    </dependency>

    <dependency name='name-services' grouping='require_all' restart_on='none' type='service'>

      <service_fmri value='svc:/milestone/name-services'/>

    </dependency>

    <dependency name='identity' grouping='optional_all' restart_on='none' type='service'>

      <service_fmri value='svc:/system/identity:domain'/>

    </dependency>

    <dependency name='system-log' grouping='optional_all' restart_on='none' type='service'>

      <service_fmri value='svc:/system/system-log'/>

    </dependency>

    <dependency name='autofs' grouping='optional_all' restart_on='none' type='service'>

      <service_fmri value='svc:/system/filesystem/autofs'/>

    </dependency>

    <method_context project=':default' resource_pool=':default' working_directory=':default'>

      <method_credential group='oinstall' limit_privileges=':default' privileges=':default' supp_groups=':default' user='oracle'/>

      <method_environment>

        <envvar name='TNS_ADMIN' value='/opt/app/oracle/network/admin'/>

        <envvar name='ORACLE_SID' value='TEST'/>

        <envvar name='ORACLE_BASE' value='/opt/app/oracle'/>

        <envvar name='ORACLE_HOME' value='/opt/app/oracle/102'/>

        <envvar name='LD_LIBRARY_PATH' value='/opt/app/oracle/102/lib'/>

        <envvar name='PFILE' value='/opt/app/oracle/admin/TEST/pfile/initTEST.ora'/>

      </method_environment>

    </method_context>

    <exec_method name='start' type='method' exec='$ORACLE_HOME/bin/sqlplus @/export/home/oracle/smf/startup.sql' timeout_seconds='500'>

      <method_context/>

    </exec_method>

    <exec_method name='stop' type='method' exec='$ORACLE_HOME/bin/sqlplus @/export/home/oracle/smf/shutdown.sql' timeout_seconds='900'>

      <method_context/>

    </exec_method>

 <property_group name='general' type='framework'>

      <propval name='action_authorization' type='astring' value='oracle.smf.manage.oracle'/>

    </property_group>

    <property_group name='dependents' type='framework'>

      <propval name='db-oracle_multi-user' type='fmri' value='svc:/milestone/multi-user'/>

    </property_group>

    <property_group name='startd' type='framework'>

      <propval name='ignore_error' type='astring' value='core,signal'/>

    </property_group>

    <stability value='Unstable'/>

    <template>

      <common_name>

        <loctext xml:lang='C'>Oracle Database Server</loctext>

      </common_name>

    </template>

  </service>

</service_bundle>


2. $cat startup.sql
/ as sysdba
startup;
exit
3.$cat shutdown.sql 
/ as sysdba
shutdown immediate;
exit

$sudo svccfg -V import oracle.xml
$sudo svcadm enable oracle
$sudo svcamd disable oracle

For Listener Service:

$cat oralistener.xml

<?xml version='1.0'?>

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

<service_bundle type='manifest' name='export'>

  <service name='database/oralistener' type='service' version='0'>

    <create_default_instance enabled='false'/>

    <single_instance/>

    <dependency name='fs-local' grouping='require_all' restart_on='none' type='service'>

      <service_fmri value='svc:/system/filesystem/local'/>

    </dependency>

    <dependency name='network-service' grouping='require_all' restart_on='none' type='service'>

      <service_fmri value='svc:/network/service'/>

    </dependency>

    <dependency name='name-services' grouping='require_all' restart_on='none' type='service'>

      <service_fmri value='svc:/milestone/name-services'/>

    </dependency>

    <dependency name='identity' grouping='optional_all' restart_on='none' type='service'>

      <service_fmri value='svc:/system/identity:domain'/>

    </dependency>

    <dependency name='system-log' grouping='optional_all' restart_on='none' type='service'>

      <service_fmri value='svc:/system/system-log'/>

    </dependency>

    <dependency name='autofs' grouping='optional_all' restart_on='none' type='service'>

      <service_fmri value='svc:/system/filesystem/autofs'/>

    </dependency>

    <method_context project=':default' resource_pool=':default' working_directory=':default'>

      <method_credential group='oinstall' limit_privileges=':default' privileges=':default' supp_groups=':default' user='oracle'/>

      <method_environment>

        <envvar name='TNS_ADMIN' value='/opt/app/oracle/network/admin'/>

        <envvar name='ORACLE_SID' value='TEST'/>

        <envvar name='ORACLE_BASE' value='/opt/app/oracle'/>

        <envvar name='ORACLE_HOME' value='/opt/app/oracle/102'/>

        <envvar name='LD_LIBRARY_PATH' value='/opt/app/oracle/102/lib'/>

      </method_environment>

    </method_context>

    <exec_method name='start' type='method' exec='$ORACLE_HOME/bin/lsnrctl start LISTENER' timeout_seconds='50'>

      <method_context/>

    </exec_method>

    <exec_method name='stop' type='method' exec='/home/oracle/smf/stop_listener.sh' timeout_seconds='50'>

      <method_context/>

    </exec_method>

 <property_group name='general' type='framework'>

      <propval name='action_authorization' type='astring' value='oralistener.smf.manage.oralistener'/>

    </property_group>

    <property_group name='dependents' type='framework'>

      <propval name='db-oracle_multi-user' type='fmri' value='svc:/milestone/multi-user'/>

    </property_group>

    <property_group name='startd' type='framework'>

      <propval name='ignore_error' type='astring' value='core,signal'/>

    </property_group>

    <stability value='Unstable'/>

    <template>

      <common_name>

        <loctext xml:lang='C'>Oracle Database Listener</loctext>

      </common_name>

    </template>

  </service>

</service_bundle>


$cat stop_listener.sh 
#!/bin/sh
ORACLE_HOME=/opt/app/oracle/102
ENCRYPTED_PASSWORD=`grep -i password /opt/app/oracle/network/admin/listener.ora | awk -F= ‘{print $2}’|sed ‘s/ //g’`
$ORACLE_HOME/bin/lsnrctl <
set password $ENCRYPTED_PASSWORD
stop
quit
END_LISTENER
exit 0
$sudo svccfg -V import oralistener.xm
$sudo svcadm enable oralistener
$sudo svcadm disable oralistener

Now, you have oracle database and listener under SMF service. 
Enjoy!

One thought on “Manage Oracle Database and Listener under Solaris SMF service”

Comments are closed.