systemdのレシピ:ファイルフラグを使用してサービスを強制的に再起動する

チャレンジ:

解決策:
restart-myservice.service
[Unit] Description=Restart my cool service [Service] Type=oneshot ExecStartPre=/bin/rm -f /path/to/restart.flag ExecStart=/bin/systemctl restart myservice.service 


restart-myservice.path
 [Unit] Description=Path marker to restart my cool service [Path] PathExists=/path/to/restart.flag Unit=restart-myservice.service 


systemctl start restart-myservice.pathと言い、管理対象サービスのWantsパラメーターにsystemctl start restart-myservice.pathを書くことを忘れないでください。

制限事項:
パスユニットは、notifyシステムコールを通じて機能し、フラグがシンボリックリンクのあるパス上にある場合、シンボリックリンクが再配置されたとき(フラグのないディレクトリ上にあり、フラグ付きになった)、ほとんどの場合、起動しません。チェックしませんでした。

追加資料:
man systemd.path
man systemd.unit

Source: https://habr.com/ru/post/J273351/


All Articles