linux oracle 服务自动启动、关闭
首先以root权限登录
1、创建服务脚本执行输出日志目录
mkdir -p /logs/oracle
chmod -R 777 /logs
2、进行服务脚本存入目录
cd /etc/rc.d/init.d
3、编写执行脚本oracle vi oracle
#!/bin/sh
# chkconfig:2345 99 10
# description: Oracle auto start-stop script.
#
# Set ORA_HOME to be equivalent to the $ORACLE_HOME
# from which you 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/10.2.0/db_1
ORA_OWNER=oracle
if [ ! -f $ORA_HOME/bin/dbstart ]
then
echo "Oracle startup: cannot start"
exit
fi
case "$1" in
'start')
# Start the Oracle databases:
echo "Starting Oracle Databases ... "
echo "-------------------------------------------------" >> /logs/oracle/log
date +" %T %a %D : Starting Oracle Databases as part of system up." >> /logs/oracle/log
echo "-------------------------------------------------" >> /var/log/oracle
su - $ORA_OWNER -c "$ORA_HOME/bin/dbstart" >>/logs/oracle/log
echo "Done"
# Start the Listener:
echo "Starting Oracle Listeners ... "
echo "-------------------------------------------------" >> /logs/oracle/log
date +" %T %a %D : Starting Oracle Listeners as part of system up." >> /logs/oracle/log
echo "-------------------------------------------------" >> /logs/oracle/log
su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl start" >>/logs/oracle/log
echo "Done."
echo "-------------------------------------------------" >> /logs/oracle/log
date +" %T %a %D : Finished." >> /var/log/oracle
echo "-------------------------------------------------" >> /logs/oracle/log
touch /var/lock/subsys/oracle
;;
'stop')
# Stop the Oracle Listener:
echo "Stoping Oracle Listeners ... "
echo "-------------------------------------------------" >> /logs/oracle/log
date +" %T %a %D : Stoping Oracle Listener as part of system down." >> /logs/oracle/log
echo "-------------------------------------------------" >> /logs/oracle/log
su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl stop" >>/logs/oracle/log
echo "Done."
rm -f /var/lock/subsys/oracle
# Stop the Oracle Database:
echo "Stoping Oracle Databases ... "
echo "-------------------------------------------------" >> /logs/oracle/log
date +" %T %a %D : Stoping Oracle Databases as part of system down." >> /logs/oracle/log
echo "-------------------------------------------------" >> /logs/oracle/log
su - $ORA_OWNER -c "$ORA_HOME/bin/dbshut" >>/var/log/oracle
echo "Done."
echo ""
echo "-------------------------------------------------" >> /logs/oracle/log
date +" %T %a %D : Finished." >> /var/log/oracle
echo "-------------------------------------------------" >> /logs/oracle/log
;;
'restart')
$0 stop
$0 start
;;
esac
4、赋予执行权限
chmod +x oracle
5、查看系统运行级别
sudo runlevel
--N 5
6、进行运行级别服务执行目录并创建链接
cd /etc/rc.d/r5.d
ln -s ../init.d/oracle K10oracle
ln -s ../init.d/oracle S99oracle
7、重启测试即可
首先以root权限登录
1、创建服务脚本执行输出日志目录
mkdir -p /logs/oracle
chmod -R 777 /logs
2、进行服务脚本存入目录
cd /etc/rc.d/init.d
3、编写执行脚本oracle vi oracle
#!/bin/sh
# chkconfig:2345 99 10
# description: Oracle auto start-stop script.
#
# Set ORA_HOME to be equivalent to the $ORACLE_HOME
# from which you 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/10.2.0/db_1
ORA_OWNER=oracle
if [ ! -f $ORA_HOME/bin/dbstart ]
then
echo "Oracle startup: cannot start"
exit
fi
case "$1" in
'start')
# Start the Oracle databases:
echo "Starting Oracle Databases ... "
echo "-------------------------------------------------" >> /logs/oracle/log
date +" %T %a %D : Starting Oracle Databases as part of system up." >> /logs/oracle/log
echo "-------------------------------------------------" >> /var/log/oracle
su - $ORA_OWNER -c "$ORA_HOME/bin/dbstart" >>/logs/oracle/log
echo "Done"
# Start the Listener:
echo "Starting Oracle Listeners ... "
echo "-------------------------------------------------" >> /logs/oracle/log
date +" %T %a %D : Starting Oracle Listeners as part of system up." >> /logs/oracle/log
echo "-------------------------------------------------" >> /logs/oracle/log
su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl start" >>/logs/oracle/log
echo "Done."
echo "-------------------------------------------------" >> /logs/oracle/log
date +" %T %a %D : Finished." >> /var/log/oracle
echo "-------------------------------------------------" >> /logs/oracle/log
touch /var/lock/subsys/oracle
;;
'stop')
# Stop the Oracle Listener:
echo "Stoping Oracle Listeners ... "
echo "-------------------------------------------------" >> /logs/oracle/log
date +" %T %a %D : Stoping Oracle Listener as part of system down." >> /logs/oracle/log
echo "-------------------------------------------------" >> /logs/oracle/log
su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl stop" >>/logs/oracle/log
echo "Done."
rm -f /var/lock/subsys/oracle
# Stop the Oracle Database:
echo "Stoping Oracle Databases ... "
echo "-------------------------------------------------" >> /logs/oracle/log
date +" %T %a %D : Stoping Oracle Databases as part of system down." >> /logs/oracle/log
echo "-------------------------------------------------" >> /logs/oracle/log
su - $ORA_OWNER -c "$ORA_HOME/bin/dbshut" >>/var/log/oracle
echo "Done."
echo ""
echo "-------------------------------------------------" >> /logs/oracle/log
date +" %T %a %D : Finished." >> /var/log/oracle
echo "-------------------------------------------------" >> /logs/oracle/log
;;
'restart')
$0 stop
$0 start
;;
esac
4、赋予执行权限
chmod +x oracle
5、查看系统运行级别
sudo runlevel
--N 5
6、进行运行级别服务执行目录并创建链接
cd /etc/rc.d/r5.d
ln -s ../init.d/oracle K10oracle
ln -s ../init.d/oracle S99oracle
7、重启测试即可