简体   繁体   English

普通用户在 /var/run 中触摸文件失败

[英]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/runrwxr-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.

相关问题 NGINX: connect() to unix:/var/run/php7.0-fpm.sock failed (2: No such file or directory) - NGINX: connect() to unix:/var/run/php7.0-fpm.sock failed (2: No such file or directory) MongoDB,不是root用户的Ubuntu用户,并将PID文件存储在/ var / run / mongodb中 - MongoDB, an Ubuntu user other than root, and storing the PID file in /var/run/mongodb 无法以普通用户身份运行 docker - Can't run docker as a normal user 如何以普通用户身份运行Chrome浏览器? - How to run chromium browser as a normal user? 我收到一个错误,说套接字绑定失败:/var/run/renderd/renderd.sock 如果我是普通用户,其他一切正常吗? - I get an error saying socket bind failed for: /var/run/renderd/renderd.sock if i am a regular user else everything works fine? linux从以普通用户身份运行的c代码中以root身份运行命令 - linux running command as root from c code that run as normal user docker-engine运行级别:/ var / run / utmp:没有这样的文件或目录 - docker-engine runlevel:/var/run/utmp: No such file or directory Linux Bash脚本:从用户或文件输入声明变量名 - Linux Bash Scripting: Declare var name from user or file input Nginx Docker,Nginx 连接()到 Z4913A9178621EADCDF191DB17915FBsocket 失败。 - Nginx Docker, Nginx connect() to unix:/var/run/fcgiwrap.socket failed 我怎么能告诉Java代码运行脚本,因为它是从普通用户的命令行运行的? - How can i tell Java code run the script as it was running from command line as normal user?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM