八.Ubutu18.04系統(tǒng)添加開(kāi)機(jī)自啟動(dòng)腳本

參考文章:https://www.cnblogs.com/airdot/p/9688530.html
RedHat系列以及Ubuntu14可以通過(guò)編輯rc.local來(lái)設(shè)置開(kāi)機(jī)啟動(dòng)腳本,Ubutu18.04就需要添加開(kāi)機(jī)自啟動(dòng)的服務(wù)來(lái)恢復(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.啟動(dòng)服務(wù)并添加開(kāi)機(jī)自啟動(dòng)以及查看服務(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)開(kāi)機(jī)是否加載啟動(dòng)腳本

cat /usr/local/test.log 
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀(guān)點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容