惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
Stack Overflow Blog
Stack Overflow Blog
Hugging Face - Blog
Hugging Face - Blog
博客园_首页
T
The Blog of Author Tim Ferriss
博客园 - 叶小钗
N
Netflix TechBlog - Medium
腾讯CDC
C
Check Point Blog
P
Proofpoint News Feed
Engineering at Meta
Engineering at Meta
GbyAI
GbyAI
S
SegmentFault 最新的问题
F
Fortinet All Blogs
美团技术团队
U
Unit 42
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园 - 司徒正美
F
Full Disclosure
Recorded Future
Recorded Future
D
DataBreaches.Net
博客园 - 【当耐特】
Martin Fowler
Martin Fowler
J
Java Code Geeks
I
InfoQ
Y
Y Combinator Blog
A
About on SuperTechFans
AI
AI
爱范儿
爱范儿
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Forbes - Security
Forbes - Security
W
WeLiveSecurity
M
MIT News - Artificial intelligence
雷峰网
雷峰网
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Simon Willison's Weblog
Simon Willison's Weblog
Schneier on Security
Schneier on Security
The GitHub Blog
The GitHub Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
aimingoo的专栏
aimingoo的专栏
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
G
GRAHAM CLULEY
Know Your Adversary
Know Your Adversary
Latest news
Latest news
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
D
Docker
Recent Commits to openclaw:main
Recent Commits to openclaw:main
量子位
V2EX - 技术
V2EX - 技术
Project Zero
Project Zero

Shell on 轻风云

宝塔linux版设置秒级监控
deepin下开机自启脚本
2021-12-15 · via Shell on 轻风云

利用 rc.local 文件实现脚本开机自启:

  1. 新建 /etc/rc.local 文件
  1. 粘贴以下模板
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
#!/bin/sh -e
#
# 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

在 exit 0 上方插入你需要自启的命令(一行一个)后保存文件

  1. 给脚本加上 755 权限
1
sudo chmod +755 /etc/rc.local
  1. 调试脚本(可选)
1
sudo /etc/rc.local # 使用 sudo 模拟 root 用户开机自启 /etc/rc.local 文件

ps:如果第 5 步模拟启动脚本没有报错,那我们就可以重启电脑看看是否可以成功实现脚本开机自启。
重启进入系统后我们可以通过 systemctl status rc-local.service 查看 rc-local 的 运行状态 ,如果结果显示的是 active (exited) 则说明你的脚本已经成功执行,反之如果结果显示 failed ,那么你需要检查一下脚本是否哪里有问题。

这里提供几个可能导致脚本无法正常启动的原因:

  1. 可能导致脚本无法执行的原因1. 执行脚本的用户不一致
  2. 由于 rc.local 开机自启的时候是以 root 用户执行的,这里很多人会忽略了一个问题,很多情况下你的命令是必须要普通用户执行的。
  3. 多余的 sudo,前面已经提到 rc.local 开机时是以 root 用户启动的,所以写在 rc.local 文件中命令不需要带有 sudo 前缀(实际上就算你带有了 sudo 前缀也不会产生错误)。

ps:个人建议每当往 rc.local 文件中添加了一个需要自启的命令时,可以先用 sudo /etc/rc.local 命令模拟一下看看是否能够执行成功(如果执行失败也能够直观地看到出错的原因),这样能够有效减少你重启电脑来调试的次数。