简体   繁体   English

以用户身份存储守护程序的pid文件

[英]Storing pid file for a daemon run as user

Is there a preferred place to store a pid file for a daemon that's run as a user? 是否存在为以用户身份运行的守护程序存储pid文件的首选位置? /var/run is the standard place, but this is for a user daemon so it doesn't have write privileges there. / var / run是标准位置,但这适用于用户守护程序,因此它没有写入权限。 Presumably my daemon will be started from .profile or .bashrc or something. 据推测,我的守护进程将从.profile或.bashrc或其他东西开始。 Is just saving it to /tmp a bad idea? 只是把它保存到/ tmp一个坏主意?

If it's being run for a user, let's see, what sort of storage exists that is user-specific. 如果它是为用户运行的,那么让我们看看,存在哪种类型的用户特定存储。

Hmmm. 嗯。

That's it! 而已! The home directory. 主目录。 I knew it would come to me eventually :-) 我知道最终会来找我:-)


Sorry for the light jab. 抱歉光刺。 Seriously, I would just stash the PID into $HOME/.daemon.pid or ~/.daemon.pid (how you name the file is up to you of course). 说真的,我只是将PID存入$HOME/.daemon.pid~/.daemon.pid (当然,你如何命名文件取决于你)。

This is, of course, assuming you will only have one daemon running for a user. 当然,这是假设您只为用户运行一个守护程序。 If not, you'll need to be a bit trickier. 如果没有,你需要有点棘手。


And hopefully allaying your fears that a user will inadvertently delete unknown files in their home directory, that's why you make it "hidden" by starting it with a . 并希望减轻您对用户无意中删除其主目录中的未知文件的担忧,这就是为什么您通过启动它来使其“隐藏”的原因. character. 字符。

Most non-experienced users should never even see these and experienced users should know better than to muck about with them. 大多数没有经验的用户甚至不应该看到这些用户,而且有经验的用户应该知道这些用户应该知道更多。

The XDG Basedir specification defines where you should store these. XDG Basedir规范定义了您应该存储这些内容的位置。
The variable $XDG_RUNTIME_DIR defines it's location, although it has no default. 变量$XDG_RUNTIME_DIR定义了它的位置,尽管它没有默认值。
The most common fallback (if the variable is unset) is /tmp/service-$USER.id . 最常见的回退(如果未设置变量)是/tmp/service-$USER.id

This helps keep uncluttered homedirs, while keeping all runtime data in 这有助于保持整洁的homedirs,同时保留所有运行时数据

I suggest you go for a subdirectory within the user's home directory. 我建议你去用户主目录中的子目录。

~/.programname/.pid

If there is any other user configuration data, you can store that in here too, in order to avoid cluttering up the home directory. 如果有任何其他用户配置数据,您也可以将其存储在此处,以避免使主目录混乱。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM