ubuntu-18.04 設置開機啓動腳本

ubuntu-18.04 設置開機啓動腳本ubuntu

參閱下列連接bash

https://askubuntu.com/questions/886620/how-can-i-execute-command-on-startup-rc-local-alternative-on-ubuntu-16-10ui

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

一、創建rc-local.service文件spa

sudo vi /etc/systemd/system/rc-local.service

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

[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.local  ip

sudo vi /etc/rc.local

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

#!/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加上權限string

sudo chmod +x /etc/rc.local

六、啓用服務it

sudo systemctl enable rc-local

七、啓動服務並檢查狀態

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

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

cat /usr/local/test.log  

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

相關文章
相關標籤/搜索