Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 无法从unicorn获取chgrp或chown文件_Ruby On Rails_Ruby_Unicorn - Fatal编程技术网

Ruby on rails 无法从unicorn获取chgrp或chown文件

Ruby on rails 无法从unicorn获取chgrp或chown文件,ruby-on-rails,ruby,unicorn,Ruby On Rails,Ruby,Unicorn,我在尝试chown或chgrp从unicorn进程获取文件时遇到了一个奇怪的问题。从rails c运行相同的代码,它会将组更改为正确的组,例如: bash-$ whoami zac bash-$ groups zachallett sysadmin bash-$ ls -la ... -rwxrw---- zac sysadmin 154 Nov 1 15:33 file.txt ... rails控制器操作: def controller file = "#{Rails.root}/

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

bash-$ whoami
zac

bash-$ groups
zachallett sysadmin

bash-$ ls -la
...
-rwxrw---- zac sysadmin 154 Nov 1 15:33 file.txt
...
rails控制器操作:

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
组的一部分,但是我无法从unicorn进程对该文件运行
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
env=env[“RAILS_env”]| |“development”
工作目录“/var/www//current”
pid“/var/www//shared/pids/unicorn.pid”
stderr_path“/var/www//shared/log/unicorn/stderr.log”
标准路径“/var/www//shared/log/unicorn/stdout.log”
侦听“/var/www//shared/sockets/unicorn.socket”
工人_过程环境==“生产”?6 : 2
超时120
预加载应用程序true
用户“zac”、“sysadmin”
在服务器、工人之前|
old_pid=“/var/www//shared/pids/unicorn.pid.oldbin”
如果文件.exists?(旧的_pid)和&server.pid!=老皮德
开始
Process.kill(“退出”,File.read(旧的\u pid.to\u i)
营救错误号::enoint,错误号::ESRCH
#已经杀了
终止
终止
终止

这可能是因为您正在进行更改的文件/应用程序没有
su
权限..请尝试
chmod-R 777您的应用程序
,然后再试一次…我认为这将有助于提高效率,您是否也可以发布您的unicorn配置?更新原始帖子以获得我的unicorn.rb文件。现在的一个快速修复方法是使unicorn主进程以root用户身份运行,而子进程以user
zac