本帖最后由 郑全 于 2022-6-2 11:35 编辑
解决linux下/etc/rc.local开机器不执行的原因。
今天一用户报数据库又连接不上了,一检查发现机器重启了,手工启动即可,但想到每次都这样,于是做了一个自动启动脚本 /home/oracle/scripts/startdb.sh 内容如下: lsnrctl start sqlplus / as sysdba <<eof startup; quit eof
加入 /etc/rc.local su - oracle -c "/home/oracle/scripts/startdb.sh" 但重启机器后,么有启动数据库 手工去执行这个脚本,以及手工去执行 /etc/rc.local都可以,但就是机器启动后,没有自动启动数据库 在排除了权限原因和脚本问题后,很郁闷,怎么放到开机启动项目中就无法执行了呢。 于是去查linux开机启动过程信息。发现了开机启动程序的级别为3. [root@dbserver ~]# cat /etc/inittab # inittab is only used by upstart for the default runlevel. # # ADDING OTHER CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM. # # System initialization is started by /etc/init/rcS.conf # # Individual runlevels are started by /etc/init/rc.conf # # Ctrl-Alt-Delete is handled by /etc/init/control-alt-delete.conf # # Terminal gettys are handled by /etc/init/tty.conf and /etc/init/serial.conf, # with configuration in /etc/sysconfig/init. # # For information on how to write upstart event handlers, or how # upstart works, see init(5), init(8), and initctl(8). # # Default runlevel. The runlevels used are: # 0 - halt (Do NOT set initdefault to this) # 1 - Single user mode # 2 - Multiuser, without NFS (The same as 3, if you do not have networking) # 3 - Full multiuser mode # 4 - unused # 5 - X11 # 6 - reboot (Do NOT set initdefault to this) # id:3:initdefault: [root@dbserver ~]#
果断顺藤莫瓜,找到了这个目录 /etc/rc.d/rc3.d,进去一看恍然大悟。
我的rc.local文件是在 /etc/rc.local中(网上都是说写在这里,我是按照网上来弄的),而我查看了系统指向rc.local文件的路径是 /etc/rc.d/rc.local [root@dbserver ~]# ls -ltr /etc/rc.d/rc3.d/S99* lrwxrwxrwx. 1 root root 11 Feb 1 2018 /etc/rc.d/rc3.d/S99local -> ../rc.local 后来把开机启动的脚本配置到/etc/rc.d/rc.local中(或者把S99local指向 /etc/rc.local也行),重启检查,成功!
范了经验主义哈 !!!!
我的机器版本为:rhel6.8
|