1. 打开编辑rc-local.service:
sudo vim /lib/systemd/system/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] #此处Install为自己添加
WantedBy=multi-user.target
Alias=rc-local.service
2. 如果没有/etc/rc.local,创建/etc/rc.local文件
sudo touch /etc/rc.local
3. 编辑
sudo vim /etc/rc.local
4. 按i编辑
#!/bin/bash
#下面键入需要开机执行的命令
sleep2
cd /RobotQt/robot_exe/
source ./run.sh &
5. 按esc键入:wq保存
6. sudo chmod +x /etc/rc.local
7. 启用服务:
sudo systemctl enable rc-local
sudo systemctl start rc-local.service
sudo systemctl status rc-local.service
8. 重启:
reboot