This discussion is archived
6 Replies Latest reply: Mar 22, 2013 11:29 AM by TimHall RSS

About dead service (oracle 11g automatic startup)

Nick2005 Newbie
Currently Being Moderated
Hi to All,
I have installed Oracle enterprise Server Linux 6.3 and Oracle DB 11g R2.
In order to start automatically the oracle services I have created in etc/init.d a dbora file:
#!/bin/sh
# chkconfig: 345 99 10
# description: Oracle auto start-stop script.

# Set ORA_OWNER to the user id of the owner of the
# Oracle database in ORA_HOME.

ORA_OWNER=oracle
RETVAL=0

case "$1" in
    'start')
        # Start the Oracle databases:
        # The following command assumes that the oracle login
        # will not prompt the user for any values
        su - $ORA_OWNER -c "/home/oracle/scripts/ora_start.sh"
        touch /var/lock/subsys/oracle
        ;;
    '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 "/home/oracle/scripts/ora_stop.sh"
        rm -f /var/lock/subsys/oracle
        ;;
    *)
        echo $"Usage: $0 {start|stop}"
        RETVAL=1
esac
exit $RETVAL
Next
$ chmod 750 /etc/init.d/dbora
$ chkconfig --add dbora
In /home/oracle/scripts I have create 2 files (ora_start.sh and ora_stop.sh)
#!/bin/bash

# script to start the Oracle database, listener and dbconsole

. ~/.bash_profile
#ORACLE_HOME=/u01/app/oracle/product/11.2.0/eclipsedb_1
#export ORACLE_HOME
# start the listener and the database
$ORACLE_HOME/bin/dbstart $ORACLE_HOME

# start the Enterprise Manager db console
$ORACLE_HOME/bin/emctl start dbconsole

exit 0
#!/bin/bash

# script to stop the Oracle database, listener and dbconsole

. ~/.bash_profile

# stop the Enterprise Manager db console
$ORACLE_HOME/bin/emctl stop dbconsole

# stop the listener and the database
$ORACLE_HOME/bin/dbshut $ORACLE_HOME

exit 0
Next I have execute
$ chmod u+x ora_start.sh ora_stop.sh
Now If I have tested from terminal
$ service oradb start
$ service oradb stop
and all work fine.

But from Menu->System->Administration-Services, the file dbora is marked with exclamation point and the message is: this service is dead.

Can someone help me ?
Thank You and Best Regards
Gaetano
  • 1. Re: About dead service
    rukbat Guru Moderator
    Currently Being Moderated
    Moderator Action:
    Post moved from the Oracle Linux forum,
    to the Database Installation forum, hopefully for closer topic alignment.
  • 2. Re: About dead service
    Dude! Guru
    Currently Being Moderated
    Most of the script examples you will find were created for Oracle 9i and previous OS versions.

    Your script has several issues:

    - The header is missing information.
    - The use of su - (dash) resets the ORACLE_HOME environment variables you set in the script.
    - There is also no need to export some of variables.
    - There was no need to execute a separate script and run your bash profile.
    - There is a terminator (;;) missing for the case default.
    - As of Oracle 10g, the listener is started with the dbstart script.

    The following script should work:
    #!/bin/bash
    # filename:    /etc/init.d/oradb
    # oracle       Startup/Shutdown Oracle 11g services.
    # chkconfig:   35 99 01
    # description: Startup/Shutdown Oracle 11g databases according to \
    #              /etc/oratab, including Database Console and Listener.
    # 
    ### BEGIN INIT INFO
    # Provides: oracle
    # Default-Start: 3 5
    # Default-Stop: 0 1 6
    # Short-Description: Startup/Shutdown Oracle 11g services.
    # Description: Startup/Shutdown Oracle 11g databases according to \
    #              /etc/oratab, including Database Console and Listener.     
    ### END INIT INFO
    
    # Source execute init.d function library
    # . /etc/rc.d/init.d/functions
    
    # Modify to match your installation 
    ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1
    export ORACLE_UNQNAME=orcl
    #
    if [ ! -f $ORACLE_HOME/bin/dbstart ]; then
       echo "/etc/init.d/dbora - Invalid \$ORACLE_HOME, aborting."
       exit 0
    fi
    
    case "$1" in
       start)
          echo "$0: Starting Oracle Database."
          su oracle -c "$ORACLE_HOME/bin/dbstart $ORACLE_HOME &"
          su oracle -c "$ORACLE_HOME/bin/emctl start dbconsole"
          touch /var/lock/subsys/dbora
          ;;
       stop)
          echo "$0: Oracle Database."
          su oracle -c "$ORACLE_HOME/bin/dbshut $ORACLE_HOME"
          su oracle -c "$ORACLE_HOME/bin/emctl stop dbconsole"
          rm -f /var/lock/subsys/dbora
          ;;
       restart)
          $0 stop
          sleep 90
          $0 start
          ;;
       *)
          echo "usage: dbora {start|stop|restart}"
          exit 
          ;;
    esac
    chmod 755 /etc/init.d/dbora
    chown root:root /etc/init.d/dbora
    chkconfig --add dbora
    I recommend to change the subject line to something more meaningful.
  • 3. Re: About dead service (oracle 11g automatic startup)
    Nick2005 Newbie
    Currently Being Moderated
    Thank You.
    All work Fine.
    Gaetano
  • 4. Re: About dead service
    TimHall Oracle ACE Director
    Currently Being Moderated
    Hi.

    Just a couple of thoughts:

    1) dbstart and dbshut are deprecated in 11.2. They are still there, but it makes sense to consider alternatives since they may be gone soon.

    2) Using the "su -" is only a mistake if you don't want the profile run. If you are reliant on the contents of the profile, then you sure do need "su -". :)

    Cheers

    Tim...
  • 5. Re: About dead service
    Dude! Guru
    Currently Being Moderated
    Regarding 2) by all means, but it is not standard to include the Oracle environment in the bash login profile. If you use "su -" you actually will have to set ORACLE_HOME and ORACLE_SID in your login profile as these variables will be reset. This can all be avoided by simply not using the dash (-) and set the required Oracle variables in the startup script. It also eliminates the risk of a bad login profile/script. If I remember correctly, dbstart runs the oraenv script, which in turn uses the Oracle osh utility to set the appropriate software resource shell limits, so the login profile is not required.
  • 6. Re: About dead service
    TimHall Oracle ACE Director
    Currently Being Moderated
    Hi.

    I concede, it is more prone to error using the "su -" if people don't perform the correct profile setup, or do something like put a dodgy login.sql in the home directory. :)

    I will revise my article to prevent people making mistakes like this.

    Cheers

    Tim...

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points