menu Chancel's blog
rss_feed
Chancel's blog
有善始者实繁,能克终者盖寡。

Ubuntu1804开机脚本

作者:Chancel Yang, 创建:2021-06-16, 字数:815, 已阅:40, 最后更新:2024-03-10

Ubuntu1804改用systemd来管理系统后,rc-local服务默认不再开启,记录一下如何开启这个服务

首先检查 /etc/systemd/system/rc-local.service文件是否存在,如果不存在,则创建这个文件

Bash
sudo ln -fs /lib/systemd/system/rc-local.service /etc/systemd/system/rc-local.service

然后编辑 sudo vim /etc/systemd/system/rc-local.service文件,添加Install节点

INI
[Unit]description=/etc/rc.local Compatibility
Documentation=man:systemd-rc-local-generator(8)
ConditionFileIsExecutable=/etc/rc.local
After=network.target

[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
RemainAfterExit=yes
GuessMainPID=no

[Install]
WantedBy=multi-user.target
Alias=rc-local.service

最后创建一下开机需要执行的 rc.local文件,sudo vim /etc/rc.local*,这里添加一个开机输出一个文件的测试

Bash
#!/bin/bash
echo 'hello world' > /tmp/hello.txt

最后使用systemd来启动开机执行

TEXT
sudo systemctl enable rc-local

[[replyMessage== null?"发表评论":"发表评论 @ " + replyMessage.m_author]]

account_circle
email
web_asset
textsms

评论列表([[messageResponse.total]])

还没有可以显示的留言...
[[messageItem.m_author]] [[messageItem.m_author]]
[[messageItem.create_time]]
[[getEnviron(messageItem.m_environ)]]
[[subMessage.m_author]] [[subMessage.m_author]] @ [[subMessage.parent_message.m_author]] [[subMessage.parent_message.m_author]]
[[subMessage.create_time]]
[[getEnviron(messageItem.m_environ)]]