ruby-on-rails - Ruby写文件遇到的一个问题

 晨心晨艺日记 发布于 2022-10-26 15:11

我使用resque运行一个worker, 这个worker使用Ruby的File类写文件,非常简单。

但是遇到一个奇怪问题,在ubuntu下写文件一直不成功,出现了Permission denied错误

resque进程如下

$  ps -ef | grep resque
grant   5868     1  0 15:02 ?        00:00:00 /bin/sh -l -c . 
/etc/environment && cd /home/grant/test/current; nohup bundle exec rake 
environment resque:work RAILS_ENV=production QUEUE=* VERBOSE=1 
PIDFILE=tmp/pids/resque-worker.pid

grant   5871  5868  0 15:02 ?        00:00:28 resque-1.24.1: Waiting for *

被写的文件权限

$ ls -l test.txt
-rw-rw-r-- 1 jack jack 21931 Jun 25 16:46 text.txt

grant用户权限,他已经属于jack用户组了

$ groups grant
grant : jack  grant

如果在用grant用户直接编辑这个test.txt是可以编辑的

我后来将文件权限改成666,就写成功了,后来装了个auditd来确认下到底是谁写的。

$ sudo ausearch -k test-file-changed | tail -1
type=SYSCALL msg=audit(1372321822.380:6): arch=40000003 syscall=5 
success=yes exit=15 a0=facbae40 a1=88241 a2=1b6 a3=0 items=3 ppid=20992 
pid=26087 auid=4294967295 uid=1008 gid=1009 euid=1008 suid=1008 fsuid=1008 
egid=1009 sgid=1009 fsgid=1009 ses=4294967295 tty=(none) comm="ruby" 
exe="/usr/local/bin/ruby" key="test-file-changed"

uid = 1008 是 grant gid = 1009 是 grant

我怀疑是不是因为这个gid是grant的原因导致的呢?

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有