“Centos7自启动rc.local中的脚本不执行”的版本间的差异

来自linux中国网wiki
跳到导航 跳到搜索
(导入1个版本)
 
(未显示同一用户的1个中间版本)
第29行: 第29行:
  
 
最好将该脚本(程序)目录的所有权给该用户:
 
最好将该脚本(程序)目录的所有权给该用户:
 +
 +
 +
 +
 +
tail  boot.log
 +
[  OK  ] Started Network Time Service.
 +
[FAILED] Failed to start /etc/rc.d/rc.local Compatibility.
 +
See 'systemctl status rc-local.service' for details.
 +
 +
#启动rc-local 服务  on aliyun 不要不小心 不清空了  /etc/rc.d/rc.local
 +
systemctl enable  rc-local.service
 +
 +
 +
 +
 +
Failed to start /etc/rc.d/rc.local Compatibility
 +
 +
#原内容哦 有时改了就不行 要原文件
 +
cat /etc/rc.d/rc.local
 +
#!/bin/bash
 +
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
 +
#
 +
# It is highly advisable to create own systemd services or udev rules
 +
# to run scripts during boot instead of using this file.
 +
#
 +
# In contrast to previous versions due to parallel execution during boot
 +
# this script will NOT be run after all other services.
 +
#
 +
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
 +
# that this script will be executed during boot.
 +
 +
 +
 +
 +
  
  

2019年11月13日 (三) 06:08的最新版本

原因解析

在centos7,使用ls -l /etc/rc.loacl可以看到如下结果
lrwxrwxrwx. 1 root root 13 7月  31 22:02 /etc/rc.local -> rc.d/rc.local

可以看到上面的执行结果是显示有执行权限的,
但是当使用ls -l /etc/rc.d/rc.loacl的时候却可以看到如下结果
-rw-r--r--. 1 root root 730 Sep 27 05:38 /etc/rc.d/rc.local
/etc/rc.loacl所链接的文件是没有执行权限的,
所以在启动的时候rc.local中写的命令得不到执行,
因此需要手动添加执行权限给/etc/rc.d/rc.loacl


解决办法

Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.
打开 就有提示哦  请用心看 哈哈 

chmod +x /etc/rc.d/rc.local

关于在rc.local文件中指定用户执行脚本命令

使用su命令即可,命令格式:

su - username -c “your-cammand” ,如:

注意:指定用户执行的脚本(程序)目录,该用户必须有管理该脚本(程序)目录(文件)的权限。

最好将该脚本(程序)目录的所有权给该用户:




tail  boot.log
[  OK  ] Started Network Time Service.
[FAILED] Failed to start /etc/rc.d/rc.local Compatibility.
See 'systemctl status rc-local.service' for details.

#启动rc-local 服务  on aliyun 不要不小心 不清空了  /etc/rc.d/rc.local
 systemctl enable  rc-local.service




Failed to start /etc/rc.d/rc.local Compatibility

#原内容哦 有时改了就不行 要原文件 
cat /etc/rc.d/rc.local
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.







see also

Centos 7关于rc.local脚本命令开机不执行及指定用户启动的解决方法