Centos启用rc-local服务
- 简介
- 问题分析
- 解决方法
- 启动并查看状态
简介
大多时候我们可以在/etc/rc.d/rc.local中写一些命令来实现随着服务器的启动(重启)运行自己的程序或服务,但是配置后无法启动,查看了下rc-local.service服务状态显示未启动。
[root@master ~]# systemctl status rc-local
● rc-local.service - /etc/rc.d/rc.local CompatibilityLoaded: loaded (/usr/lib/systemd/system/rc-local.service; static; vendor preset: disabled)Active: inactive (dead)
Condition: start condition failed at 五 2024-03-15 15:40:37 CST; 2s agoConditionFileIsExecutable=/etc/rc.d/rc.local was not met
问题分析
默认情况下,使用下面的命令无法启动rc-local.service服务,原因是需要两处文件都设置可执行权限,但是 /etc/rc.d/rc.local 默认没有可执行权限。
[root@master ~]# systemctl start rc-local.service
[root@master ~]# systemctl enable rc-local.service
[root@master ~]# cd /etc/rc.d/
[root@master rc.d]# ll
总用量 4
drwxr-xr-x. 2 root root 70 6月 11 2022 init.d
drwxr-xr-x. 2 root root 45 6月 11 2022 rc0.d
drwxr-xr-x. 2 root root 45 6月 11 2022 rc1.d
drwxr-xr-x. 2 root root 45 6月 11 2022 rc2.d
drwxr-xr-x. 2 root root 45 6月 11 2022 rc3.d
drwxr-xr-x. 2 root root 45 6月 11 2022 rc4.d
drwxr-xr-x. 2 root root 45 6月 11 2022 rc5.d
drwxr-xr-x. 2 root root 45 6月 11 2022 rc6.d
-rw-r--r-- 1 root root 504 3月 15 15:37 rc.local
解决方法
设置可执行权限
# 设置可执行权限
[root@master rc.d]# chmod +x /etc/rc.d/rc.local
启动并查看状态
[root@master etc]# systemctl start rc-local.service
[root@master etc]# systemctl status rc-local.service
● rc-local.service - /etc/rc.d/rc.local CompatibilityLoaded: loaded (/usr/lib/systemd/system/rc-local.service; static; vendor preset: disabled)Active: active (running) since 五 2024-03-15 15:46:15 CST; 8s agoProcess: 29650 ExecStart=/etc/rc.d/rc.local start (code=exited, status=0/SUCCESS)Main PID: 29653 (rsync.sh)Tasks: 3Memory: 596.0KCGroup: /system.slice/rc-local.service├─29653 /bin/bash /home/rsync/rsync.sh├─29654 /home/rsync/inotify/bin/inotifywait -mrq --timefmt %d/%m/%y %H:%M --format %T %w%f%e -e modify,...└─29655 /bin/bash /home/rsync/rsync.sh3月 15 15:46:15 master systemd[1]: Starting /etc/rc.d/rc.local Compatibility...
3月 15 15:46:15 master systemd[1]: Started /etc/rc.d/rc.local Compatibility.