Skip to content

Instantly share code, notes, and snippets.

@ar90n
Last active January 21, 2024 02:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ar90n/eeede6500c9f9119cc63e03645c234aa to your computer and use it in GitHub Desktop.
Save ar90n/eeede6500c9f9119cc63e03645c234aa to your computer and use it in GitHub Desktop.
systemd-concept-and-functions-book-memo

自作Serviceを作成するときに指定すると便利なWants

WantedBy=multi-user.targetを指定するのが一般的。ネットワークが使えるようになったら起動するようにしたい場合は、WantedBy=network-online.targetを指定すると良い。

activeとなるタイミングはtypeによって異なる

たとえばtypeがsimpleの場合は、forkが実行された時点でactiveとなる。 Afterなどで他のサービスと依存関係を持たせる場合、activeになるタイミングに注意する必要がある。 とくに、typeをsimpleとしている場合は、forkが実行された時点でactiveとなるので、Afterとしても実際のプログラムが起動する順番は保証されない。 typeがsimpleなService同士での依存関係を持たせる場合は、ExecStartPostでサービスのプログラムの完了を確認する。

cronの代わりにsystemd-timerを使う

cronよりも直感的に設定できる。また、cronと違って、systemd-timerはsystemdのServiceとして管理されるので、systemdのログに出力される。

systemd-mountコマンドが便利

fstabに書かずにsystemdのServiceとしてマウントすることができる。systemdのログに出力されるので、fstabに書いた場合よりもログが見やすい。 automaountもsystemd-mountコマンドで設定できる。udevのルールとして書くこともできる。 あと、systemd-mount --listが便利

ueventの確認

udevadm monitor -pでueventを確認できる。

systemd-coredumpによるcoredumpnの管理

systemd-coredumpを使うとcoredumpをsystemdのサービスで管理できる。 ローテーションなどの設定やjournalctlからの参照ができるようになる。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment