大网数据广告活动
服务器运维问答

Create a directory under /var/run at boot

· 52CE 我爱测

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 owners…

问题原文

原帖链接 · 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.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-05-29)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0 / CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。