标签:ubuntu20.04 systemd service etc test 设置 rc 开机 local
修改 rc-local.service 文件的权限
sudo chmod 777 /lib/systemd/system/rc-local.service
修改 rc-local.service 文件
打开 rc-local.service,可以看到有以下内容:
# SPDX-License-Identifier: LGPL-2.1+ # # This file is part of systemd. # # systemd is free software; you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation; either version 2.1 of the License, or # (at your option) any later version. # This unit gets pulled automatically into multi-user.target by # systemd-rc-local-generator if /etc/rc.local is executable. [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
保存,退出。
修改 /etc/rc.local 文件
查看系统中有无 /etc/rc.local 这个文件,没有则自己创建一个。
写入以下内容(清空文件中原有所有内容):
#!/bin/sh echo "看到这行字,说明添加自启动脚本成功。" > /usr/local/test.log exit 0
赋予权限
sudo chmod +x /etc/rc.local
创建软链接
ln -s /lib/systemd/system/rc-local.service /etc/systemd/system/
重启Ubuntu后,去 /usr/local 下看看有没有生成test.log这个文件以及这个文件的内容。
cat /usr/local/test.log
其他说明
如果在 /etc/rc.local 中添加的是 ./test.sh 这种类型的,要在末尾加上&,不然重启ubuntu的时候会卡在启动界面进不去系统。
原文链接:https://blog.csdn.net/guilutian0541/article/details/124111560
标签:ubuntu20.04,systemd,service,etc,test,设置,rc,开机,local 来源: https://www.cnblogs.com/dwj192/p/16590318.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。