systemd で Requires/Wants/BindsTo/PartOf を設定したサービスの開始や停止時の伝播のマトリクス

改めて man を読んでもよくわからなかったので表に整理したメモ。

ユニット A のファイルで Requires B のように指定したときの動作。

操作 Requires Wants BindsTo PartOf
start A start B start B start B -
stop A - - - -
restart A - - - -
exit A - - - -
failed A - - - -
start B - - - -
stop B stop A - stop A stop A
restart B restart A - restart A restart A
exit B - - stop A -
failed B - - stop A -

操作 の内容はそれぞれ次の通り。

  • start
    • systemctl start で開始
  • stop
    • systemctl stop で停止
  • restart
    • systemctl restart でリスタート
  • exit
    • サービスが正常開始後に終了コード 0 で停止
  • failed
    • サービスが正常開始後に終了コード 1 で停止

あと、ユニット A で After B を指定してて start A により開始した B が failed になったとき、Requires や BindsTo の場合は A の開始がブロックされる。これは Requires や Wants の違いとしてよく知られているものだけど↑の表にどう書くと良いか思いつかなかったので書いてません。