ubuntu-18.04 設置開機啓動腳本-親測有效

ubuntu-18.04不能像ubuntu14同樣經過編輯rc.local來設置開機啓動腳本,經過下列簡單設置後,能夠使rc.local從新發揮做用。html

二、將下列內容複製進rc-local.service文件ubuntu

[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

三、建立文件rc.localbash

sudo vi /etc/rc.localthis

四、將下列內容複製進rc.local文件spa

#!/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

五、給rc.local加上權限code

sudo chmod +x /etc/rc.local

六、啓用服務 htm

sudo systemctl enable rc-local

七、啓動服務並檢查狀態blog

sudo systemctl start rc-local.service
sudo systemctl status rc-local.service

八、重啓並檢查test.log文件ip

cat /usr/local/test.log  文檔

若是能看到內容,說明設置成功,你就能夠經過編輯rc.local文件來設置啓動腳本了

參考文檔: https://www.cnblogs.com/airdot/p/9688530.html

相關文章
相關標籤/搜索