miércoles, 12 de agosto de 2009

Inicio automático Oracle en Linux

En este post "intentaré" explicar cómo configurar el inicio automático de Oracle 10 en un S.O. Linux (Red Hat en mi caso particular).

Luego de instalado Oracle, debemos editar el archivo /etc/oratab, donde dice algo similar a:

$ORACLE_SID:$ORACLE_HOME:N

Cambiamos la "N" por "Y" -- o sea le decimos que sí! :) --

Quedaría:

$ORACLE_SID:$ORACLE_HOME:Y

En mi caso particular quedó:

orcl10:/u01/app/oracle/product/10.2.0/db_1:Y

Luego creamos el archivo /etc/init.d/dbora con el usuario root, con el siguiente contenido:
(espero que haya quedado bien el copy & paste!)

#!/bin/bash
#
# chkconfig: 35 99 10
# description: Starts and stops Oracle processes
#
# Set ORA_HOME to be equivalent to the $ORACLE_HOME
# from which you wish to execute dbstart and dbshut;
#
# Set ORA_OWNER to the user id of the owner of the
# Oracle database in ORA_HOME.
#
ORA_HOME=/u01/app/oracle/product/10.2.0/db_1ORA_OWNER=oracle
case "$1" in
'start')
su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl start"

if [ -f $ORA_HOME/bin/oemctl ]; then
su - $ORA_OWNER -c "$ORA_HOME/bin/emctl start dbconsole"
fi

su - $ORA_OWNER -c $ORA_HOME/bin/dbstart

# Start the Intelligent Agent
#if [ -f $ORA_HOME/bin/agentctl ]; then
# su - $ORA_OWNER -c "$ORA_HOME/bin/agentctl start"
#else
# su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl dbsnmp_start"
#fi
# Start Enterprise Management Console
#if [ -f $ORA_HOME/bin/oemctl ]; then
# su - $ORA_OWNER -c "$ORA_HOME/bin/emctl start dbconsole"
#fi
# Start HTTP Server
#if [ -f $ORA_HOME/Apache/Apache/bin/apachectl ]; then
# su - $ORA_OWNER -c "$ORA_HOME/Apache/Apache/bin/apachectl start"
#fi
touch /var/lock/subsys/dbora
;;
'stop')
# Stop HTTP Server
#if [ -f $ORA_HOME/Apache/Apache/bin/apachectl ]; then
# su - $ORA_OWNER -c "$ORA_HOME/Apache/Apache/bin/apachectl stop"
#fi
# Stop Enterprise Management Console
if [ -f $ORA_HOME/bin/oemctl ]; then
su - $ORA_OWNER -c "$ORA_HOME/bin/emctl stop dbconsole"
fi
# Stop the Intelligent Agent
#if [ -f $ORA_HOME/bin/agentctl ]; then
# su - $ORA_OWNER -c "$ORA_HOME/bin/agentctl stop"
#else
# su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl dbsnmp_stop"
#fi
# Stop the TNS Listener su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl stop"
# Stop the Oracle databases:
# The following command assumes that the oracle login
# will not prompt the user for any values
su - $ORA_OWNER -c $ORA_HOME/bin/dbshut
rm -f /var/lock/subsys/dbora
;;
esac

# End of script dbora

A continuación (seguimos con root) seteamos los privilegios sobre el archivo dbora:

chmod 750 /etc/init.d/dbora

Y asociamos al servicio con los runlevels apropiados:

chkconfig --level 345 dbora on

La instancia ahora debería iniciarse automáticamente al reinicio de nuestro servidor Oracle. Hay un bug conocido que nos puede complicar al reinicio, pero no preocuparse, porque por suerte "es conocido" y tiene solución!

Si nos encontramos con este error:

Failed to auto-start Oracle Net Listener
using /ade/vikrkuma_new/bin/tnslsnr

Se debe a un path hard-coded en el script dbstart. Para solucionarlo editamos el archivo $ORACLE_HOME/bin/dbstart y reemplazamos la siguiente línea (línea 78 aprox.):

ORACLE_HOME_LISTENER=/ade/vikrkuma_new/oracle

Con ésto:

ORACLE_HOME_LISTENER=$ORACLE_HOME

Ahora sí, con esta modificación el listener debería iniciar automáticamente sin problema alguno.

Espero que este post les sea de utilidad!

2 comentarios:

  1. Hola estado revisando tu scripts y esta interesante una consulta cambia algo si lo quiero para Oracle11gR2 es lo que instale en centos, gracias por tu apoyo

    ResponderEliminar
  2. hols
    a mi me ha fncionado cambiando el path que tienes en /etc/oratab dentro del script creado y ademas en ese script le modifico el nombre de la instancia, en mi caso orcl

    ResponderEliminar