无法从独角兽chgrp或chown文件

时间:2013-11-01 17:37:05

标签: ruby-on-rails ruby unicorn

我在尝试chownchgrp来自独角兽进程的文件时遇到了一个奇怪的问题。从rails c运行相同的代码,它会将组更改为正确的组,例如:

bash-$ whoami
zac

bash-$ groups
zachallett sysadmin

bash-$ ls -la
...
-rwxrw---- zac sysadmin 154 Nov 1 15:33 file.txt
...

rails controller action:

def controller
  file = "#{Rails.root}/file.txt"
  %x(chgrp zachallett #{file})
end

在独角兽日志中:

chgrp: changing group of `/var/www/app/current/file.txt': Operation not permitted

ps aux | grep unicorn的输出:

zac    6579  0.0  1.1 254640 45188 ?        Sl   17:13   0:01 unicorn_rails master -c config/unicorn.rb -E production -D                                               
zac    6582  0.0  1.0 254640 42704 ?        Sl   17:13   0:00 unicorn_rails worker[0] -c config/unicorn.rb -E production -D                                            
zac    6585  0.0  1.0 254640 42704 ?        Sl   17:13   0:00 unicorn_rails worker[1] -c config/unicorn.rb -E production -D                                            
zac    6588  0.0  1.0 254640 42704 ?        Sl   17:13   0:00 unicorn_rails worker[2] -c config/unicorn.rb -E production -D                                            
zac    6591  0.0  1.0 254640 42704 ?        Sl   17:13   0:00 unicorn_rails worker[3] -c config/unicorn.rb -E production -D                                            
zac    6594  0.0  1.1 254728 45004 ?        Sl   17:13   0:00 unicorn_rails worker[4] -c config/unicorn.rb -E production -D                                            
zac    6597  0.0  1.1 254728 45072 ?        Sl   17:13   0:00 unicorn_rails worker[5] -c config/unicorn.rb -E production -D                                            
zac    7274  0.0  0.0 103232   848 pts/0    S+   17:32   0:00 grep unicorn

rails c运行相同的chgrp,它可以很好地更改组。因此,用户zac拥有该文件,并且是sysadmin组的一部分,但是我无法从独角兽进程中对该文件运行chgrp

编辑:添加unicorn.rb配置文件

env = ENV["RAILS_ENV"] || "development"

working_directory "/var/www/<APP>/current"
pid               "/var/www/<APP>/shared/pids/unicorn.pid"
stderr_path       "/var/www/<APP>/shared/log/unicorn/stderr.log"
stdout_path       "/var/www/<APP>/shared/log/unicorn/stdout.log"

listen            "/var/www/<APP>/shared/sockets/unicorn.socket"
worker_processes  env == "production" ? 6 : 2
timeout           120
preload_app       true
user              "zac", "sysadmin"

before_fork do |server, worker|
  old_pid = "/var/www/<APP>/shared/pids/unicorn.pid.oldbin"

  if File.exists?(old_pid) && server.pid != old_pid
    begin
      Process.kill("QUIT", File.read(old_pid).to_i)
    rescue Errno::ENOENT, Errno::ESRCH
      # already killed
    end
  end
end

0 个答案:

没有答案