參考文章:https://www.cnblogs.com/airdot/p/9688530.html
RedHat系列以及Ubuntu14可以通過編輯rc.local來設(shè)置開機(jī)啟動腳本析显,Ubutu18.04就需要添加開機(jī)自啟動的服務(wù)來恢復(fù)rc.local的功能签赃。
1谷异、建立rc-local.service文件,添加如下內(nèi)容:
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
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
SysVStartPriority=99
[Install]
WantedBy=multi-user.target
############################################################
2.創(chuàng)建rc.local文件并添加如下內(nèi)容:
sudo vi /etc/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 "111111111111" > /usr/local/test.log
exit 0
############################################################
3.給rc.local加上執(zhí)行權(quán)限
sudo chmod +x /etc/rc.local
4.啟動服務(wù)并添加開機(jī)自啟動以及查看服務(wù)狀態(tài)
sudo systemctl enable rc-local
sudo systemctl start rc-local.service
sudo systemctl status rc-local.service
############################################################
● rc-local.service - /etc/rc.local Compatibility
Loaded: loaded (/etc/systemd/system/rc-local.service; enabled; vendor preset: enabled)
Drop-In: /lib/systemd/system/rc-local.service.d
└─debian.conf
Active: active (exited) since Sat 2019-06-22 18:13:55 CST; 11s ago
Process: 2907 ExecStart=/etc/rc.local start (code=exited, status=0/SUCCESS)
6月 22 18:13:55 turingvideo-virtual-machine systemd[1]: Starting /etc/rc.local Compatibility...
6月 22 18:13:55 turingvideo-virtual-machine systemd[1]: Started /etc/rc.local Compatibility.
############################################################
5.重啟系統(tǒng)后檢查test.log文件確認(rèn)開機(jī)是否加載啟動腳本
cat /usr/local/test.log