2023年9月28日 星期四

Ubuntu 22.04用systemd開啟rc.local

Ubuntu 22.04 server預設沒有 /etc/rc.local。三步驟設定:

  1. 編輯 /etc/systemd/system/rc-local.service
  2. 建立 /etc/rc.local
  3. 設定開機啟動執行 /etc/rc.local

⇢步驟1: 編輯 /etc/systemd/system/rc-local.service

這個步驟首先需要用sudo -i將身份變成root後,然後產生檔案
sudo -i
cat > /etc/systemd/system/rc-local.service << _END_
[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
_END_


⇢步驟2:建立/etc/rc.local

printf '%s\n' '#!/bin/bash' 'exit 0' | sudo tee -a /etc/rc.local
sudo chmod +x /etc/rc.local


⇢步驟3:設定開機啟動執行/etc/rc.local

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: /usr/lib/systemd/system/rc-local.service.d
             └─debian.conf
     Active: active (exited) since Tue 2022-02-6 11:59:35 CST; 5s ago
    Process: 5056 ExecStart=/etc/rc.local start (code=exited, status=0/SUCCESS)

Feb 15 11:59:35 olallieberry systemd[1]: Starting /etc/rc.local Compatibility...
Feb 15 11:59:35 olallieberry systemd[1]: Started /etc/rc.local Compatibility.


參考資料

_EOF_

Dark sci-fi , a small radar on mountain ,sunset, concept art, high detail, warm lighting, volumetric godrays, vivid beautiful

Steps: 20, Sampler: DPM++ 2M Karras, CFG scale: 7, Seed: 231121, Size: 512x256, Model hash: 6ce0161689, Model: v1-5-pruned-emaonly, Version: v1.6.0-2-g4afaaf8a

Time taken: 5 min. 3.4 sec.
A: 3.35 GB, R: 3.42 GB, Sys: 2.0/2 GB (100.0%)

沒有留言:

張貼留言