开发者

capistrano put() and upload() both failing

With capistrano, I am deploying a Rails application from Mac OS X 10.5 to CentOS 5.2

Note that deploy.rb and the server environment have not changed in over a year.

There is a task within our deploy.rb file called upload:

put(File.read( file ),"#{shared_path}/#{filename}", :via => :scp)

This fails each and every time with the following exception:

No such file or directory - /srv/ourapp/releases/20100104194410/config/database.yml

My local copy of 开发者_C百科config/database.yml is failing to upload properly. I've verified it's not our internet connection, as this happens on three different connections and two different systems.

I've also tried to swap out put() for upload() but get the same result; also, dropping :via => :scp, and/or trying to force :sftp instead similarly fails.

Relevant info:

$ cap -V Capistrano v2.5.10

$ ruby -v ruby 1.8.7 (2008-08-11 patchlevel 72) [i686-darwin9.6.0]


If I understand your question correctly, it sounds like Capistrano is successfully uploading the files, but Rails is failing to start because it can't find the deploy.yml file. This might be happening during the Capistrano deploy as part of the deploy:restart task, making it look like a Capistrano error.

Based on the information you've given Capistrano is uploading the file to /svr/ourapp/shared/ and Rails is almost definitely looking for it in /svr/ourapp/releases/20100104194410/config/.

If that's the case, what you'll need to do is create a task which symlinks the shared database file to the expected location then add a hook so that task will be run after finalize_update. For instance:

task :symlink_database do
  run "ln -s #{shared_path}/database.yml #{latest_release}/config/database.yml"
end

after 'deploy:finalize_update', :symlink_database


namespace :deploy do
  task :upload_settings, :roles => :app do
    run "mkdir -p #{shared_path}/config/"
    top.upload "config/database.yml", "#{shared_path}/config/database.yml", :via => :scp
  end

  task :symlink_yml, :roles => :app do
    run "ln -sf #{shared_path}/config/database.yml #{release_path}/config/database.yml"
  end
end

after 'deploy:setup', 'deploy:upload_settings'
after 'deploy:update_code', 'deploy:symlink_yml'


This is purely from a server-side view, but have you checked to make sure that the user you're using to upload has proper permissions for the directory?

Doing a recursive change for the user (or group) depending on your server environment should fix this.

chown -R user_name_here /srv/ourapp/releases/
chgrp -R group_name_here /srv/ourapp/releases/

You might also want to clean up any code repositories e.g. git gc or svn cleanup. As well as updating any symbolic links.


The "No such file or directory" error occurs when you are trying to copy a file to a destination path that does not exist. As far as I know, the put and upload methods of Capistrano merely attempt to transfer the file, but do not make the required path. Is it possible that the config/ directory, or even the shared_path itself, has not been created when you are trying to upload this file?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜