https://www.cnblogs.com/airdot/p/9688530.html
http://www.r9it.com/20180613/ubuntu-18.04-auto-start.html
ubuntu-18.04 設置開機啟動腳本
參閱下列鏈接
ubuntu-18.04不能像ubuntu14一樣通過編輯rc.local來設置開機啟動腳本帝火,通過下列簡單設置后,可以使rc.local重新發(fā)揮作用推捐。
1默刚、建立rc-local.service文件
sudo?vi?/etc/systemd/system/rc-local.service
2响禽、將下列內(nèi)容復制進rc-local.service文件
[Unit]
Description=/etc/rc.local?Compatibility
ConditionPathExists=/etc/rc.local
[Service]
Type=forking
ExecStart=/etc/rc.local?start
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
SysVStartPriority=99
[Install]
WantedBy=multi-user.target
3彼哼、創(chuàng)建文件rc.local
sudo?vi?/etc/rc.local
4五鲫、將下列內(nèi)容復制進rc.local文件
#!/bin/sh -e
#
# 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?"看到這行字轿钠,說明添加自啟動腳本成功沟优。"?>?/usr/local/test.log
exit?0
5涕滋、給rc.local加上權限
sudo?chmod?+x?/etc/rc.local
6、啟用服務
sudo?systemctl?enable?rc-local
7挠阁、啟動服務并檢查狀態(tài)
sudo?systemctl start rc-local.service
sudo?systemctl status rc-local.service
8宾肺、重啟并檢查test.log文件
cat?/usr/local/test.log
如果能看到內(nèi)容,說明設置成功侵俗,你就可以通過編輯rc.local文件來設置啟動腳本了