Oracle Standard System Service script for Redhat Linux

Source: Internet
Author: User

Sender: Wwashington (Jacky), email area: NewSoftware
Question: Oracle Standard System Service script for Redhat Linux
Mailing station: BBS shuimu Tsinghua station (Sat Oct 16 22:08:19 2004), within the station

Author: Wwashington AT smth bbs
Time: 2004/10/16

You are welcome to repost it, but you must keep all the information in the original article, including the author and time.

I. This is similar to the dbids I posted before the National Day. It uses the database as a standard service.
Linux installation script. This is also original and shared with frog netizens.

2. The so-called Standard System Service should be a background running program that meets the following standards.
1) install chkconfig -- add and check the status with chkconfig -- list.
2) use ntsysv to define whether a service is automatically started along with the startup of the machine.
3) In graphic mode, you can use serviceconf to start, stop, and restart services.
4) The system service displays starting and shutting down as the system service does.

3. The following is a specific dbora script, which is passed on Redhat 7.3.
It has been verified dozens of times to ensure it can run. If your system cannot run, please let us know.

Note: When starting lsnrctl, you do not need to use su instead of su. Otherwise, the operation fails and
The BASH_ENV of the oracle user is required. ORA_xxx at the beginning of the script
The parameters must be written according to the actual situation. Otherwise, the Oracle program or pid cannot be found.
The DOS format is convenient for publishing documents. After copying it, convert it to the Unix format using UltraEdit.

------------------------------------------------------------------------
Code:

#! /Bin/bash
#
#/Etc/rc. d/init. d/dbora
#
# Starts the dbora daemon
#
# Chkconfig: 345 94 6
# Description: Runs commands scheduled by the at command at the time
# Specified when at was run, and runs batch commands when the load
# Average is low enough.
# Processname: dbora
#
# Copyright: Written by Wwashington AT smth bbs, free to distribute.
# You must keep everything in this file, including the copyright
# Announcement. Study demo: atd & postgresql in/etc/rc. d/init. d

# Source function library.
INITD =/etc/rc. d/init. d
. $ INITD/functions

# Source system profile.
If [-r/etc/profile]; then./etc/profile; fi

ORA_SID = udb01
ORA_USER = oracle
ORA_BASE =/udb01/app/oracle
ORA_HOME =/udb01/app/oracle/product/8.1.7
BASH_ENV = $ ORA_BASE/. bashrc

Test-x $ ORA_HOME/bin/dbstart | exit 0
RETVAL = 0

GREP_UNIX = 'uname | awk {if ($1 ~ /(^ SunOS | ^ HP-UX)/) print $1 }'
If! ["$ GREP_UNIX" = ""]
Then
GREP_FLAG = ef
Else
GREP_FLAG = efw
Fi

RUNLEVEL = 'runlevel | awk {print $2 }'
# RUNLEVEL = 6

Case "$ RUNLEVEL" in
3)
SH_FLAG = 1
;;
4)
SH_FLAG = 1
;;
5)
SH_FLAG = 1
;;
*)
SH_FLAG = 0
;;
Esac

# Below is a debug info to display Show Flag
# Echo RUNLEVEL = $ RUNLEVEL, SH_FLAG = $ SH_FLAG

#
# See how we were called.
#

Prog = "dbora"

Start (){
# Check flag, if dbora already started, quit dbora
If [! -F/var/lock/subsys/dbora]; then
Echo-n $ "Starting $ prog :"

# This is the background exec which can work under
# Both CLI (dbora) and GUI mode (serviceconf). We
# Must forward stderr to a file or null, otherwise
# Dbora wont start with a return code in GUI mode
Echo ""
Echo "[oralog] ----->"
Echo "Starting Oracle8i :"
Echo "-------------------------------------------------------------------------"
# Please note that forward stderr (2) to/dev/null or &-means close stderr
Su-$ ORA_USER-c "$ ORA_HOME/bin/dbstart>/tmp/ORA-dbuplog" 2>/dev/null
If [$ SH_FLAG-eq 1]; then
Cat/tmp/ORA-dbuplog
Fi
Echo
Echo "Starting TNS Listener :"
Echo "-------------------------------------------------------------------------"
Su $ ORA_USER-c "$ ORACLE_HOME/bin/lsnrctl start>/tmp/ORA-lsnrlog" 2> &-
If [$ SH_FLAG-eq 1]; then
Cat/tmp/ORA-lsnrlog
Fi

Pid = 'pidof-s ora_pmon _ $ ORA_SID'
If ["$ pid" = ""]; then
RETVAL = 1;
Else
RETVAL = 0;
Fi

[$ RETVAL-eq 0] & touch/var/lock/subsys/dbora
Echo
Fi
Return $ RETVAL
}

Stop (){
Echo-n $ "Stopping $ prog :"

# In order to use database local cmd to keep safe,
# We use dbshut instead of simply kill ora _ proc.
# When we reboot (runlevel = 0 or 6), no verbose.
# Force remove/var/lock/subsys/dbora to activate
If [$ SH_FLAG-eq 1]; then
Echo ""
Echo "[oralog] ----->"
Echo "Shutting down TNS Listener :"
Echo "-------------------------------------------------------------------------"
Su $ ORA_USER-c "$ ORACLE_HOME/bin/lsnrctl stop"
Else
Su $ ORA_USER-c "$ ORACLE_HOME/bin/lsnrctl stop>/dev/null"
Fi
If [$ SH_FLAG-eq 1]; then
Echo
Fi
If [$ SH_FLAG-eq 1]; then
Echo "Shutting down Oracle8i :"
Echo "-------------------------------------------------------------------------"
Su-$ ORA_USER-c "$ ORA_HOME/bin/dbshut"
Else
Su-$ ORA_USER-c "$ ORA_HOME/bin/dbshut>/dev/null"
Fi

Pid = 'ps-$ GREP_FLAG | grep-e ora _-e lsnr | grep-v grep | awk {print $2 }'
# Show pids when shutdown failed, to see debug info
# Echo $ pid

If [$ pid]; then
Failure ""
Else
Success ""
Fi
Echo ""
Rm-f/var/lock/subsys/dbora
Return $ RETVAL
}

Restart (){
Echo "Restarting Oracle8i and Listener :"
Echo "============================================== ========================================"
Stop
Start
}

Reload (){
Restart
}

Status_ol (){
Echo "Checking Oracle8i and Listener :"
Echo "============================================== ========================================"
Su-$ ORA_USER-c "$ ORA_HOME/bin/dbstat"
}

Case "$1" in
Start)
Start
;;
Stop)
Stop
;;
Reload | restart)
Restart
;;
Condrestart)
If [-f/var/lock/subsys/dbora]; then
Restart
Fi
;;
Status)
Status_ol
;;
*)
Echo $ "Usage: $0 {start | stop | restart | condrestart | status }"
Exit 1
Esac

Exit $?
Exit $ RETVAL
 
The file is/etc/rc. d/init. d/dbora. Add one now, $ ORACLE_HOME/bin/dbstat

GREP_UNIX = 'uname | awk {if ($1 ~ /(^ SunOS | ^ HP-UX)/) print $1 }'

If! ["$ GREP_UNIX" = ""]
Then
GREP_FILE =/usr/xpg4/bin/grep
GREP_FLAG = ef
Else
GREP_FILE =/bin/grep
GREP_FLAG = efw
Fi
Echo
Echo "#

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.