Fedora 開機啟動執行腳本

📢 本文由 gemini-2.5-flash 翻譯

前言

千萬不要把無窮迴圈放進去啊!!!請使用 systemd 方式

建立腳本

請在此檔案中寫入您的腳本

1
vi /etc/rc.d/rc.local

賦予執行權限

1
chmod +x /etc/rc.d/rc.local

編輯啟動狀態

編輯檔案

1
vi /usr/lib/systemd/system/rc-local.service

請在最後一行加入 [Install]

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.

# This unit gets pulled automatically into multi-user.target by
# systemd-rc-local-generator if /etc/rc.d/rc.local is executable.
[Unit]
Description=/etc/rc.d/rc.local Compatibility
ConditionFileIsExecutable=/etc/rc.d/rc.local
After=network.target

[Service]
Type=forking
ExecStart=/etc/rc.d/rc.local start
TimeoutSec=0
RemainAfterExit=yes
SysVStartPriority=99

[Install]
WantedBy=multi-user.target

然後使用 systemd 開機自動啟動

1
systemctl enable rc-local.service 

檢視啟動狀態

請使用以下指令

1
systemctl status rc-local.service

參考文章

Fedora 22(15以上版本)開機自動啟動腳本 - 可酷可樂 - 博客園

This post is licensed under CC BY-NC-SA 4.0 by the author.