Ubuntu16.04如果设置开机启动

  • 打开rc-local.service
cd /lib/systemd/system
sudo vim rc-local.service
  • 打开后看到如下内容
[Unit]  
Description=/etc/rc.local Compatibility  
ConditionFileIsExecutable=/etc/rc.local  
After=network.target

[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
RemainAfterExit=yes
GuessMainPID=no
  • 在文件末尾加上
[Install]
WantedBy=multi-user.agent
  • rc-local.service链接到/etc/systemd/system/目录
sudo ln -fs /lib/systemd/system/rc-local.service /etc/systemd/system/rc-local.service
  • /etc/目录创建rc.local
sudo touch /etc/rc.local
  • 编辑rc.local,将需要开机启动的脚本写入,注意文件首尾
#!/bin/bash

/usr/local/bin/test.sh
# ...

exit 0
  • rc.local赋予执行权限
sudo chmod +x /etc/rc.local
  • 重启,查看一下脚本是否重启成功吧

你可能感兴趣的:(Ubuntu16.04如果设置开机启动)