为以用户身份运行的守护程序存储pid文件 [英] Storing pid file for a daemon run as user
问题描述
是否存在首选位置来存储以用户身份运行的守护程序的pid文件? /var/run是标准位置,但这是用于用户守护程序的,因此它在那里没有写权限.大概我的守护进程将从.profile或.bashrc之类的文件启动.只是将其保存到/tmp是个坏主意吗?
Is there a preferred place to store a pid file for a daemon that's run as a user? /var/run is the standard place, but this is for a user daemon so it doesn't have write privileges there. Presumably my daemon will be started from .profile or .bashrc or something. Is just saving it to /tmp a bad idea?
推荐答案
如果正在为用户运行它,让我们看看存在哪种特定于用户的存储.
If it's being run for a user, let's see, what sort of storage exists that is user-specific.
嗯.
就是这样!主目录.我知道它最终会降临到我:-)
That's it! The home directory. I knew it would come to me eventually :-)
对不起,请稍等.认真地说,我只是将PID存储到$HOME/.daemon.pid
或~/.daemon.pid
中(当然,文件的命名方式取决于您).
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).
当然,这是假设您只为用户运行一个守护程序.如果不是这样,您将需要更棘手.
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.
这篇关于为以用户身份运行的守护程序存储pid文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!