More Related Content
Similar to Hello, systemd (9)
More from Emma Haruka Iwao (20)
Hello, systemd
- 3. Hello, systemd!
• Systemd がやってきた
• RHEL 7, CentOS 7, Fedora に採用
• DebianとUbuntuも将来は採用
– たぶんGentoo以外みんなsystemd
• SysV Initとupstart、今までありがとう
- 4. Systemdとは
• PID 1 を置き換える新しいデーモン
• すべてのプロセスの親
– Systemd自体はカーネルにより直接起動される
• 今までより担当範囲が広くなった
• 後方互換性はほとんど無い
- 6. 何がうれしいの?
• init はサービスと点で接していた
– 起動とシグナル送信だけに責任を持つ
• systemd はサービスの一生を監視
– 起動前から終了後まですべてに責任を持つ
– cgroup によるリソースの分離
• 「unit」単位でシステムを抽象化
• シェルスクリプトからの解放
• 高速化、柔軟性、etc
- 8. SIGKILLしたらどうなるか
# systemctl status httpd
httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled)
Active: active (running) since Thu 2014-07-24 03:57:50 JST; 1min 21s ago
Main PID: 1311 (httpd)
Status: "Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec"
CGroup: /system.slice/httpd.service
├─1311 /usr/sbin/httpd -DFOREGROUND
├─1451 /usr/sbin/httpd -DFOREGROUND
├─1452 /usr/sbin/httpd -DFOREGROUND
├─1453 /usr/sbin/httpd -DFOREGROUND
├─1455 /usr/sbin/httpd -DFOREGROUND
└─1457 /usr/sbin/httpd -DFOREGROUND
Jul 24 03:57:50 centos7.local httpd[1311]: AH00558: httpd: Could not reliably
determine the server's fully qualified ...essage
Jul 24 03:57:50 centos7.local systemd[1]: Started The Apache HTTP Server.
- 9. # kill -9 1311
# systemctl status httpd
httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled)
Active: deactivating (stop-sigterm) (Result: signal) since Thu 2014-07-24
04:00:40 JST; 3s ago
Process: 2554 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited,
status=0/SUCCESS)
Process: 1311 ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND (code=killed,
signal=KILL)
Main PID: 1311 (code=killed, signal=KILL)
Status: "Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec"
CGroup: /system.slice/httpd.service
├─1451 /usr/sbin/httpd -DFOREGROUND
├─1452 /usr/sbin/httpd -DFOREGROUND
├─1453 /usr/sbin/httpd -DFOREGROUND
├─1455 /usr/sbin/httpd -DFOREGROUND
└─1457 /usr/sbin/httpd -DFOREGROUND
Jul 24 03:57:50 centos7.local httpd[1311]: AH00558: httpd: Could not reliably
determine the server's fully qualified ...essage
Jul 24 03:57:50 centos7.local systemd[1]: Started The Apache HTTP Server.
Jul 24 04:00:40 centos7.local systemd[1]: httpd.service: main process exited,
code=killed, status=9/KILL
- 11. cgroup によるリソースの分離
• リソース制限といえば ulimit
– プロセス単位なのでforkすると別になる
• cgroup で「サービス単位」の制限が可能
– すべてsystemd経由で指定できる
– わかりやすい、漏れが無い
– ulimit どこに書くのが正解か議論に終止符
- 12. unit 概念の追加
• あらゆるタスクを「unit」とした
• unit には service, target, device などがある
• runlevel も「multi-user.target」とunit化
• それぞれに依存関係を記述
– race conditionによる事故が無い
– システムの起動が高速化
- 16. おまけ: 単発コマンドを実行
• リソース制限したり、ログを残したり、状態を
監視しつつ簡単に実行できるよ
# systemd-run echo abc
Running as unit run-2942.service.
# systemctl status run-2942
run-2942.service
Loaded: not-found (Reason: No such file or directory)
Active: inactive (dead)
Jul 24 04:50:36 centos7.local systemd[1]: Starting /bin/echo abc...
Jul 24 04:50:36 centos7.local systemd[1]: Started /bin/echo abc.
Jul 24 04:50:36 centos7.local echo[2943]: abc