1. 程式人生 > 實用技巧 >ubuntu-18.04 設定開機啟動指令碼

ubuntu-18.04 設定開機啟動指令碼

ubuntu-18.04 設定開機啟動指令碼

原文地址:https://www.jianshu.com/p/79d24b4af4e5

在設定frp的時候,需要新增到開機自啟動專案中。不過ubuntu-18.04不能像ubuntu14一樣通過編輯rc.local來設定開機啟動指令碼,通過下列簡單設定後,可以使rc.local重新發揮作用。

1.建立rc-local.service檔案

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

2.將下列內容複製進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.建立檔案rc.local

sudo vi /etc/rc.local

將下列內容複製進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

4.給rc.local加上許可權,啟用服務

sudo chmod +x /etc/rc.local
sudo systemctl enable rc
-local

啟動服務並檢查狀態

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

5.重啟並檢查test.log檔案

cat /usr/local/test.log