Appreciations accepted

Vladlen Litvinov, the author: If you have some job offer for me, I'm ready to discuss it. View Vladlen Litvinov's profile on LinkedIn

Password

Friday, March 28, 2014

How to use SMF for creating a service for start and stop Oracle DB on Solaris 10

So I often became use Solaris for our environments, I was interested in controlling of our services, particularly Oracle DB. I know well how to do this in Linux but there my experience was weak.

I've found the good article by Max Lam (Thanks!) here
But i have some troubles during this way so I want to share my experience.



It's my edition.

1. As root cd /var/opt/oracle/oratab and change it.

oracledb:/u01/app/oracle/product/11.2.0/db_1:NY

2. Create the file /etc/oracle11gR2.server. Set our vaues here.

#!/bin/bash
ORACLE_BASE=/u01/app/oracle
ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
ORACLE_HOME_LISTENER=$ORACLE_HOME
ORACLE_SID=oracledb
ORACLE_UNQNAME=oracledb

export ORACLE_BASE
export ORACLE_HOME
export ORACLE_HOME_LISTENER
export ORACLE_SID
export ORACLE_UNQNAME

if [ ! -f $ORACLE_HOME/bin/dbstart -o ! -d $ORACLE_HOME ]
then
    echo "The Oracle Startup file (dbstart) was not found"
    exit
fi

if [ ! -f $ORACLE_HOME/bin/emctl -o ! -d $ORACLE_HOME ]
then
    echo "The Oracle Enterprise Manager Controller (emctl) was not found"
    exit
fi

case "$1" in
    'start')
    # start Oracle databases and the enterprise manager console
    su oracle -c "$ORACLE_HOME/bin/dbstart $ORACLE_HOME $ORACLE_HOME_LISTENER"
    su oracle -c "$ORACLE_HOME/bin/emctl start dbconsole"
;;
    'stop')
    # stop Oracle enterprise manager first, then the databases
    su oracle -c "$ORACLE_HOME/bin/emctl stop dbconsole"
    su oracle -c "$ORACLE_HOME/bin/dbshut $ORACLE_HOME $ORACLE_HOME_LISTENER"
;;
    'restart')
    su oracle -c "$ORACLE_HOME/bin/emctl stop dbconsole"
    su oracle -c "$ORACLE_HOME/bin/dbshut $ORACLE_HOME $ORACLE_HOME_LISTENER"
    su oracle -c "$ORACLE_HOME/bin/dbstart $ORACLE_HOME $ORACLE_HOME_LISTENER"
    su oracle -c "$ORACLE_HOME/bin/emctl start dbconsole"
;;
esac


3. Then I try to check my script as was written in article and get this message:

-bash-3.00# sh oracle11gR2.server start
oracle11gR2.server: ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1: is not an identifier



You must login under oracle user and edit files $ORACLE_HOME/bin/dbshut and $ORACLE_HOME/bin/dbstart (1st string).

#!/bin/shbash
#
# $Id: dbshut.sh 22-may-2008.05:19:31 arogers Exp $
# Copyright (c) 1991, 2008, Oracle. All rights reserved. 
#


After that the error disappears.

4. Then as root
cd /usr
mkdir files 
cd files
and create in this folder the file oracle_smf.xml as was written:

<?xml version="1.0"?>
<!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">

<service_bundle type="manifest" name="Oracle11gR2">
    <service name="application/oracle11gR2" type="service" version="1">

        <!-- Initial setup and configuration of paths -->
        <dependency name="filesystem" grouping="require_all" restart_on="none" type="service">
            <service_fmri value="svc:/system/filesystem/local" />
        </dependency>
        <dependent name="mysql-runlevel" grouping="require_all" restart_on="none">
            <service_fmri value="svc:/milestone/multi-user-server" />
        </dependent>

        <!-- Execution method for start, stop and restart -->
        <!-- if you need longer time to start, just change the timeout_seconds value -->
        <exec_method type="method" name="start" exec="/etc/oracle11gR2.server %m" timeout_seconds="500" />
        <exec_method type="method" name="stop" exec="/etc/oracle11gR2.server %m" timeout_seconds="500" />
        <exec_method type="method" name="restart" exec="/etc/oracle11gR2.server %m" timeout_seconds="500" />

        <!-- Other properties and configs -->
        <property_group name="general" type="framework">
            <propval name="action_authorization" type="astring" value="oracle.operator" />
            <propval name="value_authorization" type="astring" value="oracle.administrator" />
        </property_group>
    <instance name="default" enabled="true" />
        <stability value="Unstable" />
        <template>
            <common_name>
                <loctext xml:lang="C">Oracle 11g R2 Database Server</loctext>
            </common_name>
        </template>

    </service>
</service_bundle>


Then:

-bash-3.00# svccfg -v import oracle_smf.xml
svccfg: Taking "initial" snapshot for svc:/application/oracle11gR2:default.
svccfg: Taking "last-import" snapshot for svc:/application/oracle11gR2:default.
svccfg: Refreshed svc:/application/oracle11gR2:default.
svccfg: Refreshed svc:/milestone/multi-user-server:default.
svccfg: Successful import.
-bash-3.00# svcadm enable oracle11gR2
-bash-3.00# svccfg list | grep oracle11gR2
application/oracle11gR2
-bash-3.00# svcs | grep oracle11gR2
maintenance 10:39:29 svc:/application/oracle11gR2:default


There is some error here because the service in maintenance mode. Look at the log:

-bash-3.00# cat /var/svc/log/application-oracle11gR2\:default.log
...
[ марта 28 11:04:11 Enabled. ]
[ марта 28 11:04:12 Executing start method ("/etc/oracle11gR2.server start") ]
/sbin/sh: /etc/oracle11gR2.server: cannot execute
[ марта 28 11:04:12 Method "start" exited with status 1 ]



I look at the permissions of our command file:


-bash-3.00# ls -l /etc/oracle11gR2.server
-rw-r--r-- 1 root root 1247 марта 28 10:50 /etc/oracle11gR2.server


Certainly root is the root of the problem :)

I do:

svccfg -v import oracle_smf.xml


-bash-3.00# chmod 744 /etc/oracle11gR2.server

-bash-3.00# chown oracle:dba /etc/oracle11gR2.server

Now:

-bash-3.00# ls -l /etc/oracle11gR2.server

-rwxr--r--   1 oracle   dba         1247 марта 28 10:50 /etc/oracle11gR2.server
  
I clear the status.

-bash-3.00# svcadm clear oracle11gR2
-bash-3.00# svcs oracle11gR2
STATE          STIME    FMRI
offline*       11:18:24 svc:/application/oracle11gR2:default

Sometime later:

-bash-3.00# svcs oracle11gR2
STATE          STIME    FMRI
online         11:20:24 svc:/application/oracle11gR2:default




sh oracle11gR2.server start
sh oracle11gR2.server star
sh oracle11gR2.server start
sh oracle11gR2.server s

sh oracle11gR2.server sta

No comments:

Post a Comment