1. 程式人生 > 其它 >Ubuntu 18.04 設定開機啟動

Ubuntu 18.04 設定開機啟動

1、建立rc-local.service檔案並編輯

sudovi/etc/systemd/system/rc-local.service
[Unit]
Description=/etc/rc.localCompatibility
ConditionPathExists=/etc/rc.local

[Service]
Type=forking
ExecStart=/etc/rc.localstart
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
SysVStartPriority=99

[Install]
WantedBy=multi-user.target

2、建立rc.local並編輯

sudovi/etc/rc.local
#!/bin/sh-e
#
#rc.local
#
#Thisscriptisexecutedattheendofeachmultiuserrunlevel.
#Makesurethatthescriptwill"exit0"onsuccessoranyother
#valueonerror.
#
#Inordertoenableordisablethisscriptjustchangetheexecution
#bits.
#
#Bydefaultthisscriptdoesnothing.
echo"看到這行字,說明新增自啟動指令碼成功。">/usr/local/test.log
exit0

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

sudochmod+x/etc/rc.local
sudosystemctlenablerc-local

4、啟動服務並檢查狀態

sudosystemctlstartrc-local.service
sudosystemctlstatusrc-local.service

5、檢查是否生效