开机自启动脚本配置
- 创建一个启动service脚本
sudo vim /usr/lib/systemd/system/rclocal.service
- 写入内容
1
2
3
4
5
6
7
8
9
10
11
12
13
14[Unit]
Description=/etc/rc.local Compatibility
[Service]
Type=forking
ExecStart=/etc/rc.local start
# ExecStart=/usr/bin/su -c '/etc/user.local start' 用户名
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
SysVStartPriority=99
[Install]
WantedBy=multi-user.target
- 写入内容
- 创建 /etc/rc.local 文件
sudo vim /etc/rc.local
- 写入内容
1
2
3
4
5
6
7
8#!/bin/sh
# /etc/rc.local
if test -d /etc/rc.local.d; then
for rcscript in /etc/rc.local.d/*.sh; do
test -r "${rcscript}" && sh ${rcscript}
done
unset rcscript
fi
- 写入内容
- 添加执行权限
sudo chmod a+x /etc/rc.local
- 添加/etc/rc.local.d文件夹
sudo mkdir /etc/rc.local.d
- 启动并设置开机自启动
sudo systemctl start rclocal
sudo systemctl enable rclocal