[英]Normal user touching a file in /var/run failed
I have a program called HelloWorld belonging to user test我有一个名为HelloWorld的程序属于用户测试
HelloWorld will create a file HelloWorld.pid in /var/run to keep single instance. HelloWorld将在/var/run中创建一个文件HelloWorld.pid以保留单个实例。 I using following command to try to make test can access /var/run我使用以下命令尝试使测试可以访问/var/run
usermod -a -G root test
However, when I run it, falied但是,当我运行它时,失败了
could someone help me?有人可以帮助我吗?
What are the permissions on /var/run
? /var/run
的权限是什么? On my system, /var/run
is rwxr-xr-x
, which means only the user root
can write to it.在我的系统上, /var/run
是rwxr-xr-x
,这意味着只有用户root
可以写入它。 The permissions do not allow write access by members of the root
group.权限不允许root
组的成员进行写访问。
The normal way of handling this is by creating a subdirectory of /var/run
that is owned by the user under which you'll be running your service.处理这个问题的正常方法是创建一个/var/run
的子目录,该子目录归用户所有,您将在该目录下运行您的服务。 Eg,例如,
sudo mkdir /var/run/helloworld
sudo chown myusername /var/run/helloworld
Note that /var/run
is often an ephemeral filesystem that disappears when your system reboots.请注意, /var/run
通常是一个临时文件系统,在系统重新启动时会消失。 If you would like your target directory to be created automatically when the system boots you can do that using the systemd tmpfiles service.如果您希望在系统启动时自动创建目标目录,您可以使用 systemd tmpfiles服务来实现。
Some linux systems store per-user runtime files in /var/run/user/UID/
.一些 linux 系统将每个用户的运行时文件存储在/var/run/user/UID/
中。
In this case you can create your pid file in /var/run/user/$(id -u test)/HelloWorld.pid
.在这种情况下,您可以在/var/run/user/$(id -u test)/HelloWorld.pid
中创建您的 pid 文件。
Alternatively just use /tmp
.或者,只需使用/tmp
。
You may want to use the user's name as a prefix to the pid filename to avoid collision with other users, for instance /tmp/test-HelloWorld.pid
.您可能希望使用用户名作为 pid 文件名的前缀以避免与其他用户发生冲突,例如/tmp/test-HelloWorld.pid
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.