1

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

bash-$ whoami
zac

bash-$ groups
zachallett sysadmin

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

导轨控制器动作:

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

从 运行相同的 chgrp rails c,它改变组就好了。所以用户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
4

0 回答 0