Systemd:必要なサービスの後にタイマーを実行する方法は?

Systemd:必要なサービスの後にタイマーを実行する方法は?

現在私はこれを持っています。システムタイマー( my.timer):

[Unit]
Description=My Timer

[Timer]
OnActiveSec=30 
Unit=my-subsequent.service

[Install]
WantedBy=multi-user.target

タイマーは、次の理由で起動時に有効になるように設定されていsystemctl enable my.timerますsystemctl start my.timer

有効にすると、タイマーはサービスを開始する前に30秒間待ちますmy-subsequent.service

しかし、起動時にタイマーを有効にするのではなく待機したいです。その他のサービスmy-preceding.service)は起動時に有効になります。

したがって、チェーンは次のようになります。始める> my-preceding.service> my.timer> my-subsequent.service

どうすればいいですか?


編集する:

私はタイマーでとAfter=利用可能かどうかを調べようとしましたが、Requires=何も見つかりませんでした。しかし、一見すると、これがうまくいくようです。これは許容可能なソリューションですか?

[Unit]
Description=My Timer
After=my-preceding.service
Requires=my-preceding.service

[Timer]
OnActiveSec=30 
Unit=my-subsequent.service

[Install]
WantedBy=multi-user.target

ベストアンサー1

はい、を使用するAfter=ことはRequires=サービスを注文する正しい方法です。また、指定されたサービスRequiresが失敗するとサービスも失敗することに注意することもできます。マンページから:

Often, it is a better choice to use Wants= instead of Requires= in order to 
achieve a system that is more robust when dealing with failing services.

おすすめ記事