Debian default init: sysvinit -> systemd

: author

佐々木洋平\n((<"uwabami@gfd-dennou.org"|mailto:uwabami@gfd-dennou.org>))

: institution : content-source

EPNetFaN 2015 座学編

: date

2015-06-11

: allotted-time

45m

: theme

.

はじめに

はじめに/宣伝

そんなnこんなで

今日のお題

((systemd))

お品書き

お品書き

((init)) の役割

Linux の boot sequence

(1) 電源投入⇒BIOS or UEFI が起動 (2) BIOS or UEFI ⇒ bootloader を起動 (3) bootlader が kernel を起動 (4) kernel が ((init)) を起動

プロパティ

: background-image

images/linux-boot-sequence.png

: background-image-relative-height

80

: background-image-align

right

: background-image-relative-margin-right

5

: background-image-relative-margin-top

20

init とその役割

お品書き

SysV init

SysV init

:SysV init = SystemV 由来の init

* init が初回に行なうプロセスの総称
* ((:/sbin/init:)) バイナリそのもの(文脈に注意)

:SysV init 由来の概念

* ((*runlevel*)): 0(halt), 1(single user mode), 6(reboot), 等

Debian の sysvinit(1)

:sysvinit の設定ファイル群と初回起動時の挙動

* ((:/etc/inittab:)): runlevel ((*N*))one でシステムを初期化
* ((:/etc/rcS.d:)): ランレベル ((*S*))ingle でハードウェアを初期化
* ((:/etc/rc((*X*)).d:)): 2-5 のいずれかの runlevel でサービスを起動\n
  (通常は runlevel 2 で動作する)

Debian の sysvinit(2)

:Squeeze の sysvinit

* 単純な SysV init スタイル. sh script を((*逐次実行*))

:Wheezy の sysvinit

* LSB(Linux Standard Base) ヘッダーで定義された依存関係に従い, sh script を((*並列に実行*)) ⇒ 高速に起動
* 依存関係が間違っていると挙動不審

LSB ヘッダの例: dovecot

# emacs # -*- sh -*-
#! /bin/sh
### BEGIN INIT INFO
# Provides:          dovecot
# Required-Start:    $local_fs $remote_fs $network $syslog $time
# Required-Stop:     $local_fs $remote_fs $network $syslog
# Should-Start:      postgresql mysql slapd winbind nslcd
# Should-Stop:       postgresql mysql slapd winbind nslcd
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Dovecot init script
# Description:       Init script for dovecot services
### END INIT INFO

脱線: サービスの起動/停止

SysV init じゃ駄目なの?

(1) SysVinit によるサービス起動の複雑さn

- 環境の切り替え,他のサービスへの依存...etc.\n
⇒((*うまくやる*))のが難しい(できなくはないけれど)

(1) ファイルベースの PID 管理n

⇒((*SysV init は PID を管理していない*)). \n
- ファイルに吐いているだけ. \n
- PID の重複チェックは? 孫プロセスは?

(1) sh に起因するアレコレ: ((*遅い*))

お品書き

systemd

systemd とは?

:systemd: not system“D” or “S”ystemd

* (メイン)開発者: Lennart Poettering@Red Hat
* License: LGPL-2.1+

:特徴

* cgroups によるプロセス管理, 積極的な並列動作
* sh より簡便な設定, 詳細なドキュメント...etc.

cgroups とは?

systemd のプロセス管理

:全ての「サービス」は独自の cgroup に所属

* 「サービス」に関連する全てのプロセスを管理可能
  * (SysV init では PID ファイルでしか管理できなかった)
* 「サービス」の「リソース」「権限」も管理可能
  * (リソースの制限は ulimit 等で指定するしかなかった)

systemd-{cgls,cgtop}

:systemd-cgls

* cgroup の階層構造を表示

:systemd-cgtop

* cgroup のリソース消費を表示

systemd: サービス管理

systemd: runlevel

bootup(7)

 

boot の解析:nsystemd-analyze

システムの状態表示: systemctl

% systemctl list-units        <-- systemctl だけでも良い
% systemctl -t service        <-- サービスのみの表示
% systemctl --failed          <-- 起動に失敗したサービスの表示
% systemctl status            <-- 全体の状況を表示
% systemctl status SERVICE    <-- 特定のサービスの表示
# systemctl status SERVICE -l <-- 詳細表示

ユニットファイルの書き方

例: atd.service

[Unit]
Description=Deferred execution scheduler
Documentation=man:atd(8)

[Service]
ExecStart=/usr/sbin/atd -f
IgnoreSIGPIPE=false

[Install]
WantedBy=multi-user.target

Unit ファイルの置き場所

SysV init の sh は?

これからのinit: systemd

脱線: 他の OS は?

脱線: その2

お品書き

All your cgroups are belong to us

systemd components

# image
# src = images/systemd_components.png
# relative_height = 100
# caption = "http://ja.wikipedia.org/wiki/Systemd"

醜聞

- Fsck SystemD and its developers and its users:
  https://lists.debian.org/debian-ctte/2014/02/msg00376.html
- Linus 様が systemd にぶちきれる:
  http://cpplover.blogspot.jp/2014/04/linussystemd.html
- 「魚は頭から腐る」--systemdの開発者がトーバルズ氏を公然と批判:
  http://japan.zdnet.com/article/35054778/

個人的見解

まとめ

参考文献

- Debian リファレンス:
  https://www.debian.org/doc/manuals/debian-reference/index.ja.html
- Wikipedia: systemd
  http://ja.wikipedia.org/wiki/Systemd
- Fsck SystemD and its developers and its users:
  https://lists.debian.org/debian-ctte/2014/02/msg00376.html
- Linus 様が systemd にぶちきれる:
  http://cpplover.blogspot.jp/2014/04/linussystemd.html
- 「魚は頭から腐る」--systemdの開発者がトーバルズ氏を公然と批判:
  http://japan.zdnet.com/article/35054778/