Oracle 入门之service脚本管理启动,关闭,重启

2014-11-24 17:54:00 · 作者: · 浏览: 0

[root@jsb-ylw-5024 ~]# cat /etc/init.d/oracle
#!/bin/sh
#chkconfig: 35 85 15
#description:oracle
#function: start .. stop and restart the oracle instance on 11g R2 64bit
#author:lw.yang
#version: V.1.0


ORACLE_PID=`ps -ef |grep ora |grep -E 'smon|pmon|ckpt' |wc -l`
export ORACLE_BASE=/u01
export ORACLE_HOME=/u01/oracle
export ORACLE_SID=yang
export PATH=$ORACLE_HOME:/bin:$PATH


# Source function library.
. /etc/rc.d/init.d/functions


start() {
su - oracle<emctl start dbconsole
lsnrctl start
sqlplus /nolog<conn /as sysdba
startup
exit
EOD
exit
EOF
}


stop() {
su - oracle<emctl stop dbconsole
lsnrctl stop
sqlplus /nolog<conn /as sysdba
shutdown immediate
exit
EOD
exit
EOF
}


case "$1" in
start)
start
touch /var/lock/subsys/oracle
;;


stop)
stop
;;


status)
if [ "$ORACLE_PID" = "3" ];then
echo "Oracle instance is running..."
else echo "Oracle instance is not running..."
fi
;;


restart)
stop
start
;;



*)
echo $"Usage: $0 {start|stop|restart|status}"
exit 1


esac



[root@jsb-ylw-5024 ~]# chmod +x /etc/init.d/oracle
[root@jsb-ylw-5024 ~]# chkconfig --add oracle
[root@jsb-ylw-5024 ~]# service oracle status
Oracle instance is not running...