以前一直在/etc/rc.local里写了脚本,一旦重启都会起效果,这次居然不灵了,真的奇了怪了。
查了下,
systemctl status rc-local.service
● rc-local.service - /etc/rc.d/rc.local Compatibility
Loaded: loaded (/usr/lib/systemd/system/rc-local.service; static; vendor preset: disabled)
Active: inactive (dead)
inactive 怪不得,先注册为开机启动 systemctl enable rc-local.service,然后再启动服务
启用服务并设置开机自启 sudo systemctl enable rc-local.service
立即启动服务(测试当前会话)sudo systemctl start rc-local.service
又查了下状态:
systemctl status rc-local.service
● rc-local.service - /etc/rc.d/rc.local Compatibility
Loaded: loaded (/usr/lib/systemd/system/rc-local.service; static; vendor preset: disabled)
Active: inactive (dead)
Condition: start condition failed at Mon 2025-07-07 17:57:32 CST; 10s ago
ConditionFileIsExecutable=/etc/rc.d/rc.local was not met
- 直接原因:Systemd 要求目标文件必须具有可执行权限(x),但当前文件权限不满足条件。
- 深层影响:服务启动被强制阻断,导致脚本完全无法执行。
添加可执行权限
sudo chmod +x /etc/rc.d/rc.local # 赋予执行权限 ls -l /etc/rc.d/rc.local # 验证权限变为 -rwxr-xr-x
然后再次启动服务:
systemctl start rc-local.service
Job for rc-local.service failed because the control process exited with error code. See "systemctl status rc-local.service" and "journalctl -xe" for details.
systemctl status rc-local.service
● rc-local.service - /etc/rc.d/rc.local Compatibility
Loaded: loaded (/usr/lib/systemd/system/rc-local.service; static; vendor preset: disabled)
Active: failed (Result: exit-code) since Mon 2025-07-07 17:59:55 CST; 7min ago
Process: 10888 ExecStart=/etc/rc.d/rc.local start (code=exited, status=1/FAILURE)
Jul 07 17:59:55 local-dev-cnc-server-main systemd[1]: Starting /etc/rc.d/rc.local Compatibility...
Jul 07 17:59:55 local-dev-cnc-server-main systemd[1]: rc-local.service: control process exited, code=exited status=1
Jul 07 17:59:55 local-dev-cnc-server-main systemd[1]: Failed to start /etc/rc.d/rc.local Compatibility.
Jul 07 17:59:55 local-dev-cnc-server-main systemd[1]: Unit rc-local.service entered failed state.
Jul 07 17:59:55 local-dev-cnc-server-main systemd[1]: rc-local.service failed.
还是失败,不知原因。看样子是进程已经存在了,不能反复启动。
换个指令,
systemctl restart rc-local.service
[root@local-dev-cnc-server-main ~]# systemctl status rc-local.service
● rc-local.service - /etc/rc.d/rc.local Compatibility
Loaded: loaded (/usr/lib/systemd/system/rc-local.service; static; vendor preset: disabled)
Active: active (exited) since Mon 2025-07-07 18:07:51 CST; 8s ago
Process: 11458 ExecStart=/etc/rc.d/rc.local start (code=exited, status=0/SUCCESS)
Jul 07 18:07:51 local-dev-cnc-server-main systemd[1]: Starting /etc/rc.d/rc.local Compatibility...
Jul 07 18:07:51 local-dev-cnc-server-main systemd[1]: Started /etc/rc.d/rc.local Compatibility.
好了,解决!