Ubuntu16.04如果设置开机启动

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/enoch612/article/details/82079231
  1. 打开rc-local.service
cd /lib/systemd/system
sudo vim rc-local.service
  1. 打开后看到如下内容
[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
  1. rc-local.service链接到/etc/systemd/system/目录
sudo ln -fs /lib/systemd/system/rc-local.service /etc/systemd/system/rc-local.service
  1. /etc/目录创建rc.local
sudo touch /etc/rc.local
  1. 编辑rc.local,将需要开机启动的脚本写入,注意文件首尾
#!/bin/bash

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

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

猜你喜欢

转载自blog.csdn.net/enoch612/article/details/82079231