Hi!
If you have a Oracle database, and want to start it and shut it down, together wit the start/shutdown of the OS, follow the steps below. In my case, i am using Oracle Linux.
Create a file, for example "ora_start_sid" in the folder "/etc/init.d":
vim /etc/init.d/ora_start_sid
Enter the content to this file, configuring the path of the log, the path of the sh scripts, and the SID, that complements the user name:
#!/bin/sh
#
# oracle shell script to startup oracle.
#
# chkconfig: 2345 95 25
# description: Oracle DataBase.
#./etc/rc.d/init.d/functions
SLOG=/var/log/oralog #Path of the log
SID=sid #case sensitive
case "$1" in
start)
# Startup .
echo -n "Starting Oracle Database:" &
echo "----------------------------------------------------" >> $SLOG
date +"! %T %a %D : Starting Oracle Databases as part of system up." >> $SLOG
echo "----------------------------------------------------" >> $SLOG
su - ora$SID -c /oracle/SID/script/start_sid.sh>> $SLOG
echo -e "\n -------- End database started. ------- " >> $SLOG
touch /var/lock/subsys/service_ora
echo -e " [ OK ]"
;;
stop)
echo -n "Stopping Database:" &
echo "----------------------------------------------------" >> $SLOG
date +"! %T %a %D : Stoping Oracle Databases as part of system down." >> $SLOG
echo "----------------------------------------------------" >> $SLOG
su - ora$SID -c /oracle/SID/script/stop_sid.sh>> $SLOG
echo -e "\n -------- End shutdown database. ------- " >> $SLOG
rm -f /var/lock/subsys/service_ora
echo -e " [ OK ]"
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
;;
esac
Change the permissions of the file:
chmod +x /etc/init.d/ora_start_sid
chmod 777 /etc/init.d/ora_start_sid
Add to services in OS:
chkconfig --add ora_start_sid
Checking:
chkconfig --list |grep ora_
Now, you must see the service.
Create the file start_sid.sh:
vim /oracle/SID/script/start_sid.sh
Content:
#!/bin/sh
. bash
lsnrctl start
sqlplus / as sysdba <<ENDOFSQL
startup;
quit
ENDOFSQL
exit;
Change permissions:
chown oraSID:dba /oracle/SID/script/start_sid.sh
chmod +x /oracle/SID/script/start_sid.sh
Create the file stop_sid.sh:
vim /oracle/SID/script/stop_sid.sh
Content:
#!/bin/sh
. bash
lsnrctl stop
sqlplus / as sysdba <<ENDOFSQL
shut immediate;
quit
ENDOFSQL
exit;
Change permissions:
chown oraSID:dba /oracle/SID/script/stop_sid.sh
chmod +x oracle/SID/script/stop_sid.sh
To test, execute the commands bellow, and check the log /var/log/oralog (or the path you chosen)
service ora_start_ec1 stop
service ora_start_ec1 start
If everything is Ok, you can now reboot your OS, and see working.
Regards,
Richard W. L. Brehmer