简介
大多时候我们可以在/etc/rc.local中写一些命令来启动自己的程序或服务,但是配置后无法启动,查看了下是rc-local.service未启动
[root@master ~]# systemctl enable rc-local.service
[root@master ~]# systemctl start rc-local.service
[root@master ~]# 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 Tue 2019-05-21 20:22:46 CST; 1s ago
ConditionFileIsExecutable=/etc/rc.d/rc.local was not met
默认情况下,使用上面的命令无法启动rc-local.service服务,原因是需要两处文件都设置可执行权限,但是 /etc/rc.d/rc.local 默认没有可执行权限
解决方法
## 设置可执行权限
[root@master ~]# chmod +x /etc/rc.d/rc.local
[root@master ~]# chmod +x /etc/rc.local
启动并查看状态
[root@master ~]# systemctl start rc-local.service
[root@master ~]# 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 Tue 2019-05-21 20:23:54 CST; 1s ago
Process: 5141 ExecStart=/etc/rc.d/rc.local start (code=exited, status=0/SUCCESS)
May 21 20:23:54 master systemd[1]: Starting /etc/rc.d/rc.local Compatibility...
May 21 20:23:54 master systemd[1]: Started /etc/rc.d/rc.local Compatibility.
引用
https://www.cipheronic.com/rc-local-service-enabling-on-centos7/