进入/etc/systemd/system/目录,创建myscript.service,并赋予权限
sudo vim /etc/systemd/system/myscript.service
[Unit]
Description=My Script Service
After=network.target
[Service]
ExecStart=/home/start.sh
Restart=always
[Install]
WantedBy=multi-user.target
【其中User是开发板的用户名,为root,
否则查看运行状态显示 myscript.service: Failed to determine user credentials: No such process
ExecStart是执行脚本,使用绝对路径表示
start.sh是完成ntp服务操作,否则没法开启openvpn服务】
输入一下指令:
重新加载
sudo systemctl daemon-reload
使能
sudo systemctl enable myscript.service
手动开启
sudo systemctl start myscript.service
重启开发板后查看服务开启状态
sudo systemctl status myscript.service
关闭自启动服务
sudo systemctl stop myscript.service
sudo systemctl disable myscript.service