我的pidfile是否必须位于/var/run中? [英] Must my pidfile be located in /var/run?

查看:125
本文介绍了我的pidfile是否必须位于/var/run中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要问的是两种情况:技术上和风格上.

I'm asking in both contexts: technically and stylistically.

我的应用程序/守护程序可以在/opt/my_app/run/中保留一个pidfile吗?

Can my application/daemon keep a pidfile in /opt/my_app/run/?

这样做很不好吗?

我的需要是:我的守护程序在特定用户下运行,实现者必须在/var/run中mkdir一个新目录,chown并对其进行chgrp才能使我的守护程序运行.似乎仅将pidfile保留在本地(对于守护程序)似乎更容易.

My need is this: my daemon runs under a specific user, and the implementor must mkdir a new directory in /var/run, chown, and chgrp it to make my daemon run. Seems easier to just keep the pidfile local (to the daemon).

推荐答案

我不会将pidfile放在应用程序安装目录(例如/opt/my_app/whatever)下.该目录可以是只读的,可以在计算机之间共享,可以由守护程序监视,该守护程序会将在那里的任何更改视为可能的闯入尝试……

I wouldn't put a pidfile under an application installation directory such as /opt/my_app/whatever. This directory could be mounted read-only, could be shared between machines, could be watched by a daemon that treats any change there as a possible break-in attempt…

pidfile的正常位置是/var/run.大多数unices会在启动时清理此目录;在Ubuntu下,这是通过/var/run内存文件系统(tmpfs)实现的.

The normal location for pidfiles is /var/run. Most unices will clean this directory on boot; under Ubuntu this is achieved by /var/run an in-memory filesystem (tmpfs).

如果从以root用户身份运行的脚本启动守护程序,请让它创建一个子目录/var/run/gmooredaemon并将其锁定给运行守护程序的用户,然后再将该用户su并启动该守护程序.

If you start your daemon from a script that's running as root, have it create a subdirectory /var/run/gmooredaemon and chown it to the daemon-running user before suing to the user and starting the daemon.

在许多现代Linux系统上,如果从不是以root用户身份运行的脚本或启动程序启动守护程序,则可以将pidfile放入/run/user/$UID中,这与传统的/var/run在每用户上等效.请注意,启动器的根部分或以root用户身份运行的启动脚本需要创建目录(对于人类用户,该目录是在用户登录时创建的).

On many modern Linux systems, if you start the daemon from a script or launcher that isn't running as root, you can put the pidfile in /run/user/$UID, which is a per-user equivalent of the traditional /var/run. Note that the root part of the launcher, or a boot script running as root, needs to create the directory (for a human user, the directory is created when the user logs in).

否则,在/tmp/var/tmp下选择一个位置,但这会增加额外的复杂性,因为pidfile的名称是否位于世界可写目录中,无法唯一确定.

Otherwise, pick a location under /tmp or /var/tmp, but this introduces additional complexity because the pidfile's name can't be uniquely determined if it's in a world-writable directory.

在任何情况下,分发者或管理员都可以轻松地(命令行选项,也许还有编译时选项)更改pidfile的位置.

In any case, make it easy (command-line option, plus perhaps a compile-time option) for the distributor or administrator to change the pidfile location.

这篇关于我的pidfile是否必须位于/var/run中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆