Skip to content

Instantly share code, notes, and snippets.

@sytkov
Created November 7, 2012 12:26
Show Gist options
  • Save sytkov/4031302 to your computer and use it in GitHub Desktop.
Save sytkov/4031302 to your computer and use it in GitHub Desktop.
/etc/init.d/oracle
#!/bin/sh
# description: Starts and stops the Oracle database and listeners
# processname: oracle
# chkconfig: 2345 20 80
export ORACLE_BASE=/opt/oracle/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/10.2.0/db_1
export ORACLE_SID=vo2
export PATH=$ORACLE_HOME/bin:$PATH
case $1 in
start)
echo -n "Starting Oracle Databases: "
echo "----------------------------------------------" >> /var/log/oracle
date +"! %T %a %D : Starting Oracle Databases." >> /var/log/oracle
echo "----------------------------------------------" >> /var/log/oracle
su - oracle -c dbstart >> /var/log/oracle
echo "Done."
echo -n "Starting Oracle Listeners: "
su - oracle -c "lsnrctl start" >> /var/log/oracle
echo "Done."
echo ""
echo "----------------------------------------------" >> /var/log/oracle
date +"! %T %a %D : Finished." >> /var/log/oracle
echo "----------------------------------------------" >> /var/log/oracle
touch /var/lock/subsys/oracle
;;
stop)
echo -n "Shutting Down Oracle Listeners: "
echo "----------------------------------------------" >> /var/log/oracle
date +"! %T %a %D : Shutting Down Oracle Databases." >> /var/log/oracle
echo "----------------------------------------------" >> /var/log/oracle
su - oracle -c "lsnrctl stop" >> /var/log/oracle
echo "Done."
rm -f /var/lock/subsys/oracle
echo -n "Shutting Down Oracle Databases: "
su - oracle -c dbshut >> /var/log/oracle
echo "Done."
echo ""
echo "----------------------------------------------" >> /var/log/oracle
date +"! %T %a %D : Finished." >> /var/log/oracle
echo "----------------------------------------------" >> /var/log/oracle
;;
restart)
echo -n "Restarting Oracle Databases: "
echo "----------------------------------------------" >> /var/log/oracle
date +"! %T %a %D : Restarting Oracle Databases." >> /var/log/oracle
echo "----------------------------------------------" >> /var/log/oracle
su - oracle -c dbstop >> /var/log/oracle
su - oracle -c dbstart >> /var/log/oracle
echo "Done."
echo -n "Restarting Oracle Listeners: "
su - oracle -c "lsnrctl stop" >> /var/log/oracle
su - oracle -c "lsnrctl start" >> /var/log/oracle
echo "Done."
echo "----------------------------------------------" >> /var/log/oracle
date +"! %T %a %D : Finished." >> /var/log/oracle
echo "----------------------------------------------" >> /var/log/oracle
touch /var/lock/subsys/oracle
;;
*)
echo "Usage: oracle {start|stop|restart}"
exit 1
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment