Skip to content

Instantly share code, notes, and snippets.

@oscarfonts
Created November 8, 2013 16:28
Show Gist options
  • Save oscarfonts/7373655 to your computer and use it in GitHub Desktop.
Save oscarfonts/7373655 to your computer and use it in GitHub Desktop.
Oracle 11g init script for Ubuntu 12.04 (/etc/init.d/oracle)
#!/bin/bash
#
# Run-level Startup script for the Oracle Instance and Listener
#
### BEGIN INIT INFO
# Provides: Oracle
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Startup/Shutdown Oracle listener and instance
### END INIT INFO
ORACLE_HOME="/opt/oracle/Oracle11gee/product/11.2.0/dbhome_1"
ORACLE_OWNR="oracle"
# if the executables do not exist -- display error
if [ ! -f $ORACLE_HOME/bin/dbstart -o ! -d $ORACLE_HOME ]
then
echo "Oracle startup: cannot start"
exit 1
fi
# depending on parameter -- startup, shutdown, restart
# of the instance and listener or usage display
case "$1" in
start)
# Oracle listener and instance startup
echo -n "Starting Oracle: "
su - $ORACLE_OWNR -c "$ORACLE_HOME/bin/dbstart $ORACLE_HOME"
su - $ORACLE_OWNR -c "$ORACLE_HOME/bin/lsnrctl start"
#Optional : for Enterprise Manager software only
#su - $ORACLE_OWNR -c "$ORACLE_HOME/bin/emctl start dbconsole"
touch /var/lock/oracle
su - $ORACLE_OWNR -c "echo $'startup\nexit' | $ORACLE_HOME/bin/sqlplus / as sysdba"
echo "OK"
;;
stop)
# Oracle listener and instance shutdown
echo -n "Shutdown Oracle: "
#Optional : for Enterprise Manager software only
#su - $ORACLE_OWNR -c "$ORACLE_HOME/bin/emctl stop dbconsole"
su - $ORACLE_OWNR -c "echo $'shutdown\nexit' | $ORACLE_HOME/bin/sqlplus / as sysdba"
su - $ORACLE_OWNR -c "$ORACLE_HOME/bin/lsnrctl stop"
su - $ORACLE_OWNR -c "$ORACLE_HOME/bin/dbshut $ORACLE_HOME"
rm -f /var/lock/oracle
echo "OK"
;;
reload|restart)
$0 stop
$0 start
;;
*)
echo "Usage: $0 start|stop|restart|reload"
exit 1
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment