Fedora 起動時にスクリプトを自動実行する方法

📢 この記事は gemini-3-flash-preview によって翻訳されました

はじめに

無限ループは絶対に中に入れないでね!!!今回は 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.

Visits Since 2025-02-28

Hugo で構築されています。 | テーマ StackJimmy によって設計されています。