第一步:新建 /etc/init.d/oralce 文件(文件名就是服务名)。文件里的内容如下:
#!/bin/sh # Comments to support chkconfig on RedHat Linux # chkconfig: 2345 64 36 # description: oracle database engine. # Comments to support LSB init script conventions ### BEGIN INIT INFO # Provides: oracle # Required-Start: $local_fs $network $remote_fs # Should-Start: ypbind nscd ldap ntpd xntpd # Required-Stop: $local_fs $network $remote_fs # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: start and stop oracle # Description: oracle database engine. ### END INIT INFO # source function library. . /etc/rc.d/init.d/functions NAME=oracle DESC="$NAME daemon" if [ -z "$ORACLE_HOME" ]; then source /home/oracle/.bash_profile fi do_start() { if [ "$USER" = "oracle" ]; then dbstart $ORACLE_HOME || echo -n "$NAME already running" else su oracle -c "dbstart $ORACLE_HOME" || echo -n "$NAME already running" fi } do_stop() { if [ "$USER" = "oracle" ]; then dbshut $ORACLE_HOME || echo -n "$NAME not running" else su oracle -c "dbshut $ORACLE_HOME" || echo -n "$NAME not running" fi } case "$1" in start) echo -n "Starting $DESC: $NAME" do_start echo "." ;; stop) echo -n "Stopping $DESC: $NAME" do_stop echo "." ;; restart) echo -n "Restarting $DESC: $NAME" do_stop do_start echo "." ;; *) echo "Usage: $SCRIPTNAME {start|stop|restart}" >&2 exit 3 ;; esac exit 0
第二步:设置开机启动,在终端执行以下命令:
chkconfig --add oracle chkconfig oracle on
service oracle start
service oracle stop
如果要关闭开机启动,在终端执行以下命令:
chkconfig oracle off