【Linux问题】解决rc.local文件不存在问题(Ubuntu 18.04)

        ubuntu16.04 版本后就不再使用 initd 管理系统,而改用 systemd。

解决方法:
第一步:编写 rc-local.service 文件。

        默认的 service文件都是存在与 /etc/systemd/system 目录下,有点像某种服务的配置文件。注意到 /lib/systemd/system 下也有个 rc-local.service,可以借用这个模板来进行修改,也可以从头开始编写。

sudo vim /etc/systemd/system/rc-local.service
[Unit]
 Description=/etc/rc.local Compatibility
 ConditionPathExists=/etc/rc.local
[Service]
 Type=forking
 ExecStart=/etc/rc.local start
 TimeoutSec=0
 StandardOutput=tty
 RemainAfterExit=yes
 SysVStartPriority=99
[Install]
 WantedBy=multi-user.target

        其中 Unit 字段主要描述服务的启动顺序以及依赖关系,Service 字段主要描述如何启动,Install 字段描述如何安装这个服务。

第二步:激活 rc-local.service。

sudo systemctl enable rc-local.service

第三步:手动创建 /etc/rc.local,并赋予执行权限。

        ubuntu 18.04 系统默认已经将 /etc/rc.local 文件移除了,因此,我们需要手动创建一个,并将需要开机执行的命令写入到文件中,  

sudo vim /etc/rc.local
#!/bin/bash
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

# 下面填入开机启动的命令
# ......

exit 0
sudo chmod +x /etc/rc.local

 第四步:启动这个服务并查看它的状态。

sudo systemctl start rc-local.service
sudo systemctl status rc-local.service

 

第五步:reboot 重启验证。

  • 2
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

谢老板不用蟹

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值