Ruby File.read()在我的Capistrano任务中失败(文件*确实*存在)
我的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
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
你当时是如何在远程机器上读取文件的?你当时是如何在远程机器上读取文件的?