Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/24.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 File.read()在我的Capistrano任务中失败(文件*确实*存在)_Ruby_Capistrano_Capistrano3 - Fatal编程技术网

Ruby File.read()在我的Capistrano任务中失败(文件*确实*存在)

Ruby File.read()在我的Capistrano任务中失败(文件*确实*存在),ruby,capistrano,capistrano3,Ruby,Capistrano,Capistrano3,我的Capistrano任务失败了 No such file or directory @ rb_sysopen - /home/blog/pids/grantb.blog.staging.pid` 以下是该文件确实存在的证据,来自我的命令提示符: [blog@grantb current]$ ls /home/blog/pids/grantb.blog.staging.pid /home/blog/pids/grantb.blog.staging.pid [blog@grantb curr

我的Capistrano任务失败了

No such file or directory @ rb_sysopen - /home/blog/pids/grantb.blog.staging.pid`
以下是该文件确实存在的证据,来自我的命令提示符:

[blog@grantb current]$ ls /home/blog/pids/grantb.blog.staging.pid
/home/blog/pids/grantb.blog.staging.pid

[blog@grantb current]$ irb
2.1.0 :001 > File.read("/home/blog/pids/grantb.blog.staging.pid").to_i
 => 936
以下是部分任务:

desc 'Restart application'
task :restart do
  on roles(:app), in: :sequence, wait: 5 do
    pid_file = fetch(:pid_file)

    puts "PID_FILE name: #{pid_file}"
      # outputs 'PID_FILE name: /home/blog/pids/grantb.blog.staging.pid'
    execute "/bin/ls #{pid_file}"  
      # outputs '/home/blog/pids/grantb.blog.staging.pid'
    execute "/bin/ls #{pid_file}"  
      # outputs '936'

    pid = File.read(pid_file).to_i
    # Exception while executing on host x.x.x.x: No such file or directory @ rb_sysopen - /home/blog/pids/grantb.blog.staging.pid
    # WHAT THE HELL!
有人能告诉我哪里出了问题吗?

找到了答案

正在本地计算机上执行File.read,而不是在远程计算机上执行。啊

我需要做的是这样的事情:

within release_path do
  execute "cat #{pid_file}"
end
我的实际任务是:

desc 'Restart application'
task :restart do
  on roles(:app), in: :sequence, wait: 5 do
    pid_file = fetch(:pid_file)

    within release_path do
      execute "((ls #{pid_file} && ps -p `cat #{pid_file}`) && kill -9 `cat #{pid_file}`) || true"
      execute "(ls #{pid_file} && /bin/rm #{pid_file}) || true"

      # RESTART COMMAND GOES HERE
    end
  end
end
我明白了

正在本地计算机上执行File.read,而不是在远程计算机上执行。啊

我需要做的是这样的事情:

within release_path do
  execute "cat #{pid_file}"
end
我的实际任务是:

desc 'Restart application'
task :restart do
  on roles(:app), in: :sequence, wait: 5 do
    pid_file = fetch(:pid_file)

    within release_path do
      execute "((ls #{pid_file} && ps -p `cat #{pid_file}`) && kill -9 `cat #{pid_file}`) || true"
      execute "(ls #{pid_file} && /bin/rm #{pid_file}) || true"

      # RESTART COMMAND GOES HERE
    end
  end
end

你当时是如何在远程机器上读取文件的?你当时是如何在远程机器上读取文件的?