How To Create A Service

BACKGROUND

There may be occasions where it is necessary to create a service on the database server that is controlled by the clusterware software (OHAS). A good reason for which can be found here.

This document shows a simple worked example fo what needs to be done. From this basic setup, more complex solutions can then be developed.

PRE-REQUISITES & ASSUMPTIONS

The worked example that follows will assume that a fully installed and working database, listener, ohasd and ASM software stack exists on single server environment, instructions on how this can be achieved can be found here.

The listing below shows the output from a formatted crs_stat -t command:

HA Resource                                   Target     State
-----------                                   ------     -----
ora.DATA00.dg                                 ONLINE     ONLINE on hostname
ora.LISTENER.lsnr                             ONLINE     ONLINE on hostname
ora.REC00.dg                                  ONLINE     ONLINE on hostname
ora.asm                                       ONLINE     ONLINE on hostname
ora.cssd                                      ONLINE     ONLINE on hostname
ora.diskmon                                   ONLINE     ONLINE on hostname
ora.SID.db                                    ONLINE     ONLINE on hostname

The following host and SID names are used:

RDBMS : SID
ASM : +ASM
Host Name : hostname
Script Location : /usr/local/bin
Service Name : new_service

STEP-BY-STEP GUIDE

  • Create the new_service control script - new_service.ksh - in /usr/local/bin.
    • Note: The script only needs to be a case statement which takes a start, stop, or check parameter.
  • Set ORACLE_SID to +ASM.
    • . oraenv
      • +ASM
  • Add the new_service to the clusterware stack with the following command:
    • This command should be entered as a single line command.
    • The CHECK_INTERVAL attribute configures how frequently clusterware should check to see if the new_service is running.
    • The START_DEPENDENCIES attribute ensures that the SID RDBMS is running before the new_service can start.
    • The STOP_DEPENDENCIES attribute ensures that the new_service is stopped if the SID RDBMS is stopped.
    • The /tmp/new_service.flag file is used purely to track the Unix process id of the new_service script.
    • The /tmp/new_service.log file is the full extent of the application, i.e. writing a simple message every 60 seconds.
    • A full list of all configurable attributes can be found here.
         crsctl add resource new_service -type local_resource \
         -attr "ACTION_SCRIPT=/usr/local/bin/new_service.ksh,CHECK_INTERVAL=30, \
         START_DEPENDENCIES=hard(ora.SID.db),STOP_DEPENDENCIES=hard(ora.SID.db)"
  • Start the new_service with the following command:
         crsctl start resource new_service
  • Confirm that the new_service is working (or check for any errors) in the following log location:
         $ASM_HOME/log/<hostname>/agent/ohasd/local_oraagent_oracle/local_oraagent_oracle.log

EXAMPLE SCRIPTS

new_service.ksh

#!/bin/ksh

case $1 in
 'start')
 /users/local/bin/new_service_start.ksh &
 RET=$?
 ;;
 'stop')
 /users/local/bin/new_service_stop.ksh
 kill -9 `cat /tmp/new_service.flag`
 RET=$?
 ;;
 'check')
 ps -ef | grep `cat /tmp/new_service.flag` | grep -v grep
 RET=$?
 ;;
 esac
 exit $RET

new_service_start.ksh

#!/bin/ksh

MYPID=$$

echo $MYPID > /tmp/new_service.flag

while [ 1 = 1 ]
do
echo "start message from new_service - "`date` >> /tmp/new_service.log
sleep 60
done

new_service_stop.ksh

#!/bin/ksh

echo "stop  message from new_service - "`date` >> /tmp/new_service.log
© copyright 2001-2014 ABCdba.com | all rights reserved