Ubuntu系统中rc.local是被谁调用的?
时间: 2024-04-04 08:34:30 浏览: 13
在Ubuntu系统中,rc.local是由系统服务管理程序systemd来调用的。systemd是Linux系统中常见的服务管理器,它会在系统启动时自动加载rc.local文件并执行其中的命令。不过需要注意的是,从Ubuntu 18.04版本开始,由于systemd对rc.local的支持不再默认开启,需要手动进行配置才能让rc.local生效。
相关问题
ubuntu rc.local启动失败
在 Ubuntu 中,rc.local 是一个用于在系统启动时执行自定义脚本的文件。但是,在最新的 Ubuntu 版本中,rc.local 默认是禁用的,并且不再被推荐使用。相反,Ubuntu 推荐使用 systemd 来管理系统服务和启动脚本。
如果你尝试使用 rc.local 启动脚本,并且遇到了问题,可能有以下几个原因:
1. 文件权限问题:确保 rc.local 文件具有可执行权限。你可以使用以下命令来设置权限:
```
sudo chmod +x /etc/rc.local
```
2. 文件路径问题:确保 rc.local 文件的路径正确。在最新的 Ubuntu 版本中,rc.local 文件的默认路径是 `/etc/rc.local`。
3. systemd 冲突:如果你同时使用了 systemd 和 rc.local,可能会导致冲突。在这种情况下,建议使用 systemd 来管理你的启动脚本。
如果你仍然遇到问题,我建议你提供更多的详细信息,例如错误消息或日志,以便我能够更好地帮助你解决问题。
Ubuntu下要怎么手动配置systemd对rc.local的支持呢?
在Ubuntu系统中,systemd默认是不支持rc.local的,但是我们可以手动配置systemd对rc.local的支持。具体步骤如下:
1. 创建rc-local.service文件
在Ubuntu 18.04及以上版本中,rc.local已经被弃用,我们需要手动创建rc-local.service文件。在终端输入以下命令:
```
sudo nano /etc/systemd/system/rc-local.service
```
然后将以下内容复制到文件中:
```
[Unit]
Description=/etc/rc.local Compatibility
[Service]
ExecStart=/etc/rc.local start
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=rc-local
User=root
Group=root
Type=forking
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
```
保存并退出。
2. 创建rc.local文件
在终端输入以下命令来创建rc.local文件:
```
sudo nano /etc/rc.local
```
然后将以下内容复制到文件中:
```
#!/bin/bash
# Your commands here
exit 0
```
在# Your commands here处添加你需要执行的命令。保存并退出。
3. 设置文件权限
在终端中输入以下命令来设置文件权限:
```
sudo chmod +x /etc/rc.local
sudo chmod +x /etc/systemd/system/rc-local.service
```
4. 重启systemd
在终端中输入以下命令来重启systemd:
```
sudo systemctl daemon-reload
sudo systemctl enable rc-local
sudo systemctl start rc-local.service
```
至此,你已经成功地手动配置了systemd对rc.local的支持。