Automatic Shutdown and Startup of Oracle Database and Listener on Linux
We need to edit the /etc/oratab file and make sure that the databases are set to Y.
ora11g:/u01/app/oracle/product/11.2.0/dbhome_1:Y
ora12c:/u01/app/oracle/product/12.1.0/dbhome_1:Y
Next we will create a script to take advantage of the dbshut and dbstart commands when you are shutting down or rebooting the server.
vi /etc/init.d/dbora
#!/bin/sh
# chkconfig: 345 99 10
# description: Service to start and stop Oracle Database and Listener
#
# processname: oracle
# config: /etc/oratab
# pidfile: /var/run/oracle.pid
# Source function library.
. /etc/init.d/functions
RETVAL=0
ORA_OWNER="oracle"
ORA_HOME="/u01/app/oracle/product/11.2.0/dbhome_1"
# See how we were called.
prog="oracle"
start() {
echo -n $"Starting $prog: "
su - $ORA_OWNER -c "$ORA_HOME/bin/dbstart $ORA_HOME"
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/dbora
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
su - $ORA_OWNER -c "$ORA_HOME/bin/dbshut $ORA_HOME"
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -r /var/lock/subsys/dbora
return $RETVAL
}
restart() {
stop
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
*)
echo $"Usage: $0 {start|stop|restart}"
exit 1
esac
exit $?
Now change permissions and make the service active.
[root@oracle ~]# chgrp dba /etc/init.d/dbora
[root@oracle ~]# chmod 750 /etc/init.d/dbora
[root@oracle ~]# chkconfig --level 345 dbora on
We need to edit the /etc/oratab file and make sure that the databases are set to Y.
ora11g:/u01/app/oracle/product/11.2.0/dbhome_1:Y
ora12c:/u01/app/oracle/product/12.1.0/dbhome_1:Y
Next we will create a script to take advantage of the dbshut and dbstart commands when you are shutting down or rebooting the server.
vi /etc/init.d/dbora
#!/bin/sh
# chkconfig: 345 99 10
# description: Service to start and stop Oracle Database and Listener
#
# processname: oracle
# config: /etc/oratab
# pidfile: /var/run/oracle.pid
# Source function library.
. /etc/init.d/functions
RETVAL=0
ORA_OWNER="oracle"
ORA_HOME="/u01/app/oracle/product/11.2.0/dbhome_1"
# See how we were called.
prog="oracle"
start() {
echo -n $"Starting $prog: "
su - $ORA_OWNER -c "$ORA_HOME/bin/dbstart $ORA_HOME"
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/dbora
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
su - $ORA_OWNER -c "$ORA_HOME/bin/dbshut $ORA_HOME"
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -r /var/lock/subsys/dbora
return $RETVAL
}
restart() {
stop
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
*)
echo $"Usage: $0 {start|stop|restart}"
exit 1
esac
exit $?
Now change permissions and make the service active.
[root@oracle ~]# chgrp dba /etc/init.d/dbora
[root@oracle ~]# chmod 750 /etc/init.d/dbora
[root@oracle ~]# chkconfig --level 345 dbora on