0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Linux基礎】SysVinitについて(個人メモ)

0
Posted at

はじめに

システムの起動

BIOS→ブートローダ→カーネル→init

のinitプロセスが実行されることで呼び出されるプロセスについて、
最近は systemd が主流ですが、LPICではSysVinitも頻出です。

SysVinitにおいて、/etc/init.d//etc/rcX.d/とコマンドが混同してイメージがわかなかったので、まとめます。

全体像

いかがSysvinitでサービス起動するときの順序です。
本記事では、④⑤を取り扱います。
image.png

④ランレベルごとの起動設定用フォルダ

どのサービスをどのランレベルで起動するかを管理します。

/etc/rc0.d/
/etc/rc1.d/
/etc/rc2.d/
/etc/rc3.d/
/etc/rc4.d/
/etc/rc5.d/
/etc/rc6.d/

例えば、ランレベル3用のディレクトリには以下のようなサービスを起動・停止するためのリンクが入っています。

/etc/rc3.d/

S01sysstat      # Start:sysstatサービスを起動(優先度01)
S10network      # Start:ネットワークを起動(優先度10)
S55sshd         # Start:SSHサーバを起動(優先度55)
S80httpd        # Start:Webサーバを起動(優先度80)

K20nfs          # Kill:ランレベル3に入る時、nfsを停止(優先度20)
K30postfix      # Kill:メールサービスを停止(優先度30)

#  S = Start(そのランレベルで起動)
#  K = Kill(そのランレベルに入るとき停止)

⑤サービス起動スクリプト本体

ここにはサービスの起動スクリプトの実体があります。

スクリプト例:

/etc/init.d/sshd
/etc/init.d/httpd
/etc/init.d/network

④でランレベルごとに起動するサービスデーモンが選択された後、シンボリックリンクでここにある実態のファイルを呼び出します。

呼び出しの例:

/etc/rc3.d/S55sshd #ランレベル3で実行されるsshdのシンボリックリンク(実行順序55)
   ↓
/etc/init.d/sshd  #sshdサービスの本体スクリプト

なぜシンボリックリンクで呼び出すのか
理由はシンプルで、ランレベルごとに起動設定だけ用意しておいた方が楽だからです。
本体スクリプトは /etc/init.d/Pに1つだけ置き、各ランレベルでは“そのサービスを使うかどうか”だけをリンクで決めます。

もし本体をランレベルごとにコピーするとかなり管理が大変です。

まとめ

【本体】
/etc/init.d/sshd

【ランレベル設定(リンク)】
/etc/rc3.d/S55sshd → /etc/init.d/sshd
/etc/rc5.d/S55sshd → /etc/init.d/sshd

「init.dが本体、rcX.dは起動順と有無を決める」と覚えておくと理解しやすいです。

参考:
https://www.infra-linux.com/menu-lpic3/sysvinit-startup/#google_vignette

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?