前回は、systemd の service unit の先頭文字が s 〜 z までで、systemd-* を除く 20 units について、機能を調べてみた。
今回は、残りの systemd-* の 44 units について調べてみた。
$ systemctl list-unit-files *.service | grep ^systemd systemd-ask-password-console.service static systemd-ask-password-wall.service static systemd-backlight@.service static systemd-binfmt.service static systemd-exit.service static systemd-fsck-root.service static systemd-fsck@.service static systemd-fsckd.service static systemd-halt.service static systemd-hibernate-resume@.service static systemd-hibernate.service static systemd-hostnamed.service static systemd-hwdb-update.service static systemd-hybrid-sleep.service static systemd-initctl.service static systemd-journal-flush.service static systemd-journald.service static systemd-kexec.service static systemd-localed.service static systemd-logind.service static systemd-machine-id-commit.service static systemd-modules-load.service static systemd-networkd-wait-online.service disabled systemd-networkd.service enabled systemd-poweroff.service static systemd-quotacheck.service static systemd-random-seed.service static systemd-reboot.service static systemd-remount-fs.service static systemd-resolved.service disabled systemd-rfkill.service static systemd-suspend.service static systemd-sysctl.service static systemd-timedated.service static systemd-timesyncd.service enabled systemd-tmpfiles-clean.service static systemd-tmpfiles-setup-dev.service static systemd-tmpfiles-setup.service static systemd-udev-settle.service static systemd-udev-trigger.service static systemd-udevd.service static systemd-update-utmp-runlevel.service static systemd-update-utmp.service static systemd-user-sessions.service static
enabled が2つ、disabled が2つ、残り40は static。
enabled:
- systemd-networkd.service
- systemd-timesyncd.service
disabled:
- systemd-networkd-wait-online.service
- systemd-resolved.service
まずは、enabeld と disabled の4つについて調べてみる。
systemd-networkd
network を設定する service である。debian だと /etc/network/interfaces で通常は設定するが、起動時に時間を要していた事から systemd-networkd で設定するように変更した。
hiro20180901.hatenablog.com
仮想マシンの ubuntu 18.04 だと NetworkManager.service が入っていて、こちらから network の設定を行っている。なので、networking.service の元となる ifupdown package は入っておらず、NetworkManager と systemd-networkd.service、systemd-networkd.socket が連携している模様。こちらの方が systemd を使いこなしているように見える。systemd 環境での network 設定 (hostname、resolv 含む) は別途調べてみたいと考えている。
systemd-timesyncd
systemd-timesyncd command による時刻合わせを行う service。sysinit.target を WantedBy しているので dependency で起動されている。既に他の ntp daemon が起動している場合には無効にする設定が systemd-timesyncd.service.d/ 以下に存在し、昔の ntpd 等の代替となっている。これが systemd package から入っているので、他の ntp service を入れる必要はない。
systemd-networkd-wait-online、systemd-resolved
この2つは debian 9.6 では disabled も、ubuntu 18.04 だと enabled になっている。これも後でまとめて調べてみる。
systemd-ask-password-console、systemd-ask-password-wall
同名の path unit も存在している。man systemd-ask-password-console.service より:
systemd-ask-password-console.service is a system service that queries the user for system passwords (such as hard disk encryption keys and SSL certificate passphrases) on the console. It is intended to be used during boot to ensure proper handling of passwords necessary for boot.
hard disk 暗号化や SSL の passphrases を console で入力する為の unit の模様。実際に Exec されているのは /bin/systemd-tty-ask-password-agent。
terut.hatenablog.com
こちらによると vpn 接続の際の passphrases を command line で入力する際に使えるとの事。別 terminal から --query option で入力する。
systemd-backlight@
monitor の backlight の強さを記憶しておく unit。load 時に systemd-backlight command で load して、stop 時に save する。今の PC では使用していない。multi monitor 向けに template unit になっているのだと思う。
wiki.archlinux.jp
ArchWiki に記載されている。udev でも出来るが systemd-backlight でも出来る模様。
systemd-binfmt
hiro20180901.hatenablog.com
hiro20180901.hatenablog.com
こちらで紹介した binfmt_support.service は binfmt_support package に入っている unit だが、systemd 標準の同じ機能の物が systemd-binfmt になる。sysinit.target の wants directory に symbolic link が存在しているが、binfmt_support.service が有効になっているので、systemd-binfmt.service は static になっている。binfmt_misc をどちらで使用するかを決めて、それに合わせて使うようにするべきだろうが、とりあえず後回しにする。ArchLinux とか Linux From Scratch とかで最初から systemd を入れて設定すれば理解が深まるのだろうが...
systemd-exit
emergency.service と同様の system unit。systemd-exit.service と exit.target が対になっている。systemctl --force exit が実行される。
systemd-fsck-root、systemd-fsck@、systemd-fsckd
filesystem の fsck (filesystem check) 関係の unit。initramfs も絡んでいるようなので、後で initramfs も分解して中身を調べて置きたい。その際にもう少し調べてみる。
systemd-halt
systemd-exit と同様の system unit。systemd-halt.service と halt.service (/dev/null)、halt.target がセットになっている。systemctl --force halt が実行される。
systemd-hibernate-resume@、systemd-hibernate、systemd-hybrid-sleep、systemd-suspend
hibernate、sleep、suspend に関する unit。主に Note PC で使用するだろうが、電源周りの制御に関する unit だろう。これも system unit なので、後で調べる。
systemd-hostnamed
hiro20180901.hatenablog.com
こちらの hostname.service で調べていた。systemd の network 設定として、まとめて調べてみる。
systemd-hwdb-update
udev package から入っている unit。Hardware Database を更新する為の unit らしいが、udev と一緒に調べる。
systemd-initctl
systemd-initctl.service は systemd-initctl.socket から有効にされている。/dev/initctl と互換性のある名前付き pipe を作成し、systemd-initctl command が initctl の機能を提供している。man systemd-initctl では SysVinit system 向けと書いてあったが、じゃあ /dev/initctl ってなんだろうと思ってググっても良い情報が見つからない。なんとなく、SysVinit ではなく Upstart 向けの様に見えるが...今更 Upstart を調べる気持ちは無いのでここまで。止めたらどうなるかは後で調べてみよう。
ja.wikipedia.org
systemd-journal-flush
systemd-journald
gihyo.jp
systemd-journald は log を記録する為の unit である。service unit 以外にも socket unit も存在している。
$ find /lib/systemd/system | sort | grep journal /lib/systemd/system/sockets.target.wants/systemd-journald-audit.socket /lib/systemd/system/sockets.target.wants/systemd-journald-dev-log.socket /lib/systemd/system/sockets.target.wants/systemd-journald.socket /lib/systemd/system/sysinit.target.wants/systemd-journal-flush.service /lib/systemd/system/sysinit.target.wants/systemd-journald.service /lib/systemd/system/systemd-journal-flush.service /lib/systemd/system/systemd-journald-audit.socket /lib/systemd/system/systemd-journald-dev-log.socket /lib/systemd/system/systemd-journald.service /lib/systemd/system/systemd-journald.socket
service unit が2つ、socket unit が3つあり、全て sockets.target と sysinit.target の wants となっている。systemctl list-unit-files では5つ全てが static となっていて、起動直後には systemctl list-units でも表示されないが、一度 journalctl を実行すると running 状態に変わる。
/var/log 以下には以前の様に各種 log が残っているが、systemd 環境では journalctl を使って log を見るのが標準らしい。これに慣れるしか無いだろう。
systemd-kexec
kernel を softboot する機能 (kexec) を使用する為の system unit。halt 等と同様に後で調べてみる。
systemd-localed
www.atmarkit.co.jp
locale、及び console と X11 の keymap を変更する為の unit。localectl command で設定できる。dbus の service に symbolic link されているので、実際にはそちらで起動している模様。
$ localectl status System Locale: LANG=ja_JP.UTF-8 VC Keymap: n/a X11 Layout: us X11 Model: pc105 $ localectl list-locales C.UTF-8 en_US.utf8 ja_JP.utf8
keyboard は英語配列が便利で以前から使用している。Linux の使い始めに日本語キーボード設定が面倒だった事から英語配列に移り、HHK-Lite2 を使って10年以上経過しただろうか。多少反応が悪い key はあるが、問題なく使用できている。会社の日本語配列とは、何故かあまり混乱せずに切り替えられている。次に購入する keyboard も英語配列を選択したい。
日本語表示 = 日本語配列にしてしまうのはやめてほしい所。
systemd-logind
login を管理する為の unit。multi-user.target の wants に入っていて、依存性で起動している。dbus や polkit も関係している模様。後で調べる。
systemd-machine-id-commit
tooljp.com
OS install 時に決められる固有の machine-id が無い場合に設定する unit。機器構成や network を変更しても変わらない ID だが、何に使用しているのかは分からない。dbus か ?
systemd-modules-load
起動初期に kernel module を読み込む為の unit。sysinit.target の wants で依存性で oneshot で起動している。
systemd-networkd-wait-online
network 設定終了を待つ為の unit。
systemd-networkd の後、systemd-network-online.target の前に実行される...はずなのだが、実 PC の debian では static で起動していない。仮想マシンの Ubuntu では有効になっている。設定が違うのかな? systemd の network 設定を調べる際に、一緒に調べてみる。
systemd-poweroff
shutdown して電源を落とす為の system unit。後で調べる。
systemd-quotacheck
disk quota が有効かどうか確認する unit。
systemd-random-seed
random seed を load、save する為の unit。sysinit.target の wants の依存性で起動している。
wiki.archlinux.jp
乱数は高いセキュリティーを保つ為に必要な暗号に必須の機能。
systemd-reboot
再起動する為の system unit。後で調べる。
systemd-remount-fs
起動初期に /etc/fstab を元に filesystem を remount する為の unit。
systemd-resolved
network の名前解決用の unit。systemd の network 設定と一緒に調べてみるが、man page を見ると様々な機能がある模様。実 PC では使われていないので、別の software で /etc/resolv.conf が作成されている。
systemd-rfkill
wiki.archlinux.jp
Wifi を software 的に on/off する為の unit。rfkill command で Note PC 等の Hardware Switch と Software Switch の両方を表示・設定する。
systemd-sysctl
起動初期に kernel parameter を変更する為の unit。こちらは initramfs を分解した時に調べてみる。
systemd-timedated
system time と timezone を変更する為の unit。timedatectl で情報の取得と設定が出来る。
systemd-tmpfiles-clean
timer unit と一緒に動作する service unit。一時ファイルの整理用。
systemd-tmpfiles-setup-dev
/dev の static device node を作ると man page に書かれている。 sysinit.target の wants で依存性で起動している。initramfs の中だろうか。後で調べる。
systemd-tmpfiles-setup
一時ファイルとディレクトリを作る為の unit。おそらく他の *tmpfiles* service と連携して動作していると思う。
systemd-udev-settle
systemd-udev-trigger
systemd-udevd
udev 関連の unit。udev と一緒に調べる。やっぱり udev と systemd の連携は深いので、udev を理解しないと systemd の動作は理解しにくい。
systemd-update-utmp-runlevel
systemd-update-utmp
utmp と wtmp に SysVinit 形式の runlevel の変更を記録する為の unit。
systemd-user-sessions
systemd の user-session を起動する unit。multi-user.target の wants で依存性で起動している。systemd には system session と user session の2つが存在していて、systemd-cgls で cgroup をみると、user.slice と system.slice の2つに分かれている。
結果
- ざっくりとだが、systemd の service unit を調べてみた。
- 先頭に systemd が付く unit は、そのまま systemd-* command と一対一で対応している事が多い。
- systemd-* command は、これまで個々に開発されてきた system tool を systemd に合うように作り直した感じがある。
- この辺りは、initramfs を調べてみるとはっきりすると思う。