问题原文
原帖链接 · user24601 · CC BY-SA 3.0
I had a daemon that needed its own dir in /var/run for its PID file with write permission granted to the daemon's user.
I found I could create this dir with these commands:
# mkdir /var/run/mydaemon
Then I could change its ownership to the user/group under which I wished to run the process:
# chown myuser:myuser /var/run/mydaemon
But this dir would be GONE whenever I issue a reboot! How do I get this dir to create every time the machine boots?
已采纳解答
原帖链接 · HBruijn · CC BY-SA 4.0
There are two alternatives to have systemd create directories under /var/run / /run.
Typically the easiest is to declare a RuntimeDirectory in the unit file of your service. Example:
RuntimeDirectory=foo
This will create /var/run/foo for a system unit. (Note: DO NOT provide a full path, just the path under /var/run) For full docs please see the appropriate entry in systemd.exec docs.
For runtime directories that require more complex or different configuration or lifetime guarantees, use tmpfiles.d and
have your package drop a file /usr/lib/tmpfiles.d/mydaemon.conf :
#Type Path Mode UID GID Age Argument d /run/mydaemon 0755 myuser myuser - -
See the full tmpfiles.d docs here.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
