首页 > Ruby写文件遇到的一个问题

Ruby写文件遇到的一个问题

我使用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的原因导致的呢?

【热门文章】
【热门文章】