Premise: Oracle_base=/u01/app/oracle oracle_home=/u01/app/oracle/product/11.2.0/dbhome_1
1. Modify the Oracle System configuration file:/etc/oratab, only then can Oracle's own Dbstart and Dbshut work.
# Vi/etc/oratab
Orcl:/opt/oracle/102:y
2. Under/etc/init.d/, create the file Oracle with the following content:
#!/bin/bash
#chkconfig: 345 61
#description: apache
#
# Set Ora_home to is equivalent to The $ORACLE _home
# from which your 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/11.2.0/dbhome_1
Ora_owner=oracle
If [!-f $ORA _home/bin/dbstart]
Then
Echo "Oracle Startup:cannot Start"
Exit
Fi
Case "$" in
' start ')
# Start the Oracle databases:
echo "Starting Oracle Databases ... "
Echo"-------------------------------------------------">>/var/log/oracle
Date +"%T%a%d:starting Oracle Databases as part of the system up. ">>/var/log/oracle
Echo"--------------------------------------------- ---->>/var/log/oracle
su-$ORA _owner-c "$ORA _home/bin/dbstart" >>/var/log/oracle
Echo "Done"
# Start The Listener:
echo "Starting Oracle Listeners ... "
Echo"-------------------------------------------------">>/var/log/oracle
Date +"%T%a%d:starting Oracle Listeners as part of the system up. ">>/var/log/oracle
Echo"--------------------------------------------- ---->>/var/log/oracle
su-$ORA _owner-c "$ORA _home/bin/lsnrctl start" >>/var/log/oracle
Echo " Done. "
Echo------------------------------------------------->>/var/log/oracle
Date + "%T%a%d:finished." & gt;>/var/log/oracle
Echo "-------------------------------------------------" >>/var/log/oracle
Touch/var/lock/subsys/oracle
;;
' Stop ')
# Stop The Oracle Listener:
echo "Stoping Oracle Listeners ... "
Echo"-------------------------------------------------">>/var/log/oracle
Date +"%T%a%d:stoping Oracle Listener as part of the system down. ">>/var/log/oracle
Echo"-------------------------------------------- ----->>/var/log/oracle
su-$ORA _owner-c "$ORA _home/bin/lsnrctl stop" >>/var/log/oracle
Echo " Done. "
Rm-f/var/lock/subsys/oracle
# Stop the Oracle Database:
echo "Stoping Oracle Databases ... "
echo "-------------------------------------------------" >>/var/log/oracle
Date + "%T%a%d:stoping Oracle Databases as part of the system down." >>/var/log/oracle
echo "-------------------------------------------------" >>/var/log/oracle
su-$ORA _owner-c "$ORA _home/bin/dbshut" >>/var/log/oracle
echo "Done."
echo ""
echo "-------------------------------------------------" >>/var/log/oracle
Date + "%T%a%d:finished." >>/var/log/oracle
echo "-------------------------------------------------" >>/var/log/oracle
;;
' Restart ')
$ stop
$ start
;;
Esac
3. Change file permissions
# chmod 755/etc/init.d/oracle
4. Add a service
# chkconfig--level Oracle on
5. Need to stop the database before shutting down or restarting the machine and doing the operation
# ln-s/etc/init.d/oracle/etc/rc0.d/k01oracle//shutdown
# ln-s/etc/init.d/oracle/etc/rc6.d/k01oracle//restart
6. How to use
# service Oracle Start//Launch Oracle
# Service Oracle Stop//Turn off Oracle
# Service Oracle Restart//Restart Oracle
7. Testing
Linux Oracle Services Start & Stop scripts and boot from boot