sudo vi /etc/systemd/system/rc-local.service
写入以下内容:
[Unit]
Description=/etc/rc.local Compatibility
ConditionPathExists=/etc/rc.local #脚本文件位置
[Service]
Type=forking
ExecStart=/etc/rc.local start #配置的脚本文件rc.local为start
TimeoutSec=0
StandardOutput=tty #标准输出
RemainAfterExit=yes
SysVStartPriority=99 #优先级,当有多个开机启动文件时可以设置不同的值
[Install]
WantedBy=multi-user.target
sudo vi /etc/rc.local
示例写入开启frp:
#!/bin/bash
#
# 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.
echo "test....." > /var/test.log
#your shell
#excample:
/home/inspur/Documents/frp/frpc -c /home/inspur/Documents/frp/frpc.ini
#或
#打开新终端运行;分号隔开多条命令;exec bash防止终端一闪消失
gnome-terminal -- bash -c "cd /home/inspur/Documents/frp/;./frpc -c ./frpc.ini;exec bash"
exit 0
更改权限:
sudo chmod 775 /etc/rc.local
开启服务:
sudo systemctl enable rc-local
sudo systemctl start rc-local.service
链接:
sudo ln -fs /lib/systemd/system/rc-local.service /etc/systemd/system/rc-local.service
重启电脑查看:
sudo reboot
cat /var/test.log