Ubuntu20开机自启脚本
我测试了好几篇文章,终于有个成功了
local.service
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
rc.local
vim /etc/rc.local
#!/bin/sh -e
## rc.local
sh /root/startup.sh
exit 0
收尾
-
授权
chmod +x /etc/rc.local
-
自启动
systemctl enable rc-local
-
运行
systemctl start rc-local.service
-
查看状态
systemctl status rc-local.service
先别重启, ps -x
配合grep
搜索关键字看看进程启动没有
之后保存好文件重启进行测试 再次查看是否启动
举个例子:
startup.sh
#!/bin/bash -e
cd /root/News-D/
nohup python3 main.py &
cd /root/News-D/Finance/
nohup python3 -m http.server 20777 &
rm nohup.a.out
exit 0