Ruby on rails 通过sftp进行cap部署上载失败

Ruby on rails 通过sftp进行cap部署上载失败,ruby-on-rails,capistrano,web-deployment,Ruby On Rails,Capistrano,Web Deployment,你好!我会尽量说得非常具体。很抱歉,我在尝试部署应用程序时遇到了很多问题。我是rails的新手,所以我使用rails第四版进行了敏捷Web开发,我被capistrano的部署部分困住了。我在书中尝试了确切的代码,但没有成功,并且从这个论坛和其他论坛上听取了一些建议,这些建议被证明是有用的,但我仍然无法正确部署我的部署。rb是这样的: require 'bundler/capistrano' set :user, 'user_created_for_this_example' set :dom

你好!我会尽量说得非常具体。很抱歉,我在尝试部署应用程序时遇到了很多问题。我是rails的新手,所以我使用rails第四版进行了敏捷Web开发,我被capistrano的部署部分困住了。我在书中尝试了确切的代码,但没有成功,并且从这个论坛和其他论坛上听取了一些建议,这些建议被证明是有用的,但我仍然无法正确部署我的部署。rb是这样的:

require 'bundler/capistrano'

set :user, 'user_created_for_this_example'

set :domain,  'IPADDRESS'

set :application, 'depot'

# file paths

set :repository,  "#{user}@#{domain}:depot.git"

set :deploy_to, "/home/#{user}/#{domain}"

# set :scm, :git # You can set :scm explicitly or Capistrano will make an intelligent guess 
based on known version control directory names

# Or: `accurev`, `bzr`, `cvs`, `darcs`, `git`, `mercurial`, `perforce`, `subversion` or `none`

#roles server

role :web, domain

role :app, domain

role :db, domain, :primary => true

#deploy config

set :deploy_to, "/home/#{user}/#{domain}"

set :deploy_via, :copy

set :scm, 'git'

set :branch, 'master'

set :scm_verbose, true

set :use_sudo, false 


# if you want to clean up old releases on each deploy uncomment this:
# after "deploy:restart", "deploy:cleanup"

# if you're still using the script/reaper helper you will need
# these http://github.com/rails/irs_process_scripts

# If you are using Passenger mod_rails uncomment this:

namespace :deploy do

  task :start do ; end

  task :stop do ; end

  task :restart, :roles => :app, :except => { :no_release => true } do

    run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"

  end

end

after "deploy:update_code", :bundle_install

desc "install the necesary prerequisites"

task :bundle_install, :roles => :app do

  run "cd #{release_path} && bundle install"

end
set :copy_dir, "/tmp/sftp"
当我运行cap-deploy:setup和cap-deploy:check时,似乎一切正常:

~/rails_projects/depot$ cap deploy:setup

  * 2012-11-13 10:37:35 executing `deploy:setup'

  * executing "mkdir -p /home/git/xx.xx.xx.xx /home/git/xx.xx.xx.xx/releases /home/git
/xx.xx.xx.xx/shared /home/git/xx.xx.xx.xx/shared/system /home/git/xx.xx.xx.xx/shared/log 
/home/git/xx.xx.xx.xx/shared/pids"

    servers: ["xx.xx.xx.xx"]

    [xx.xx.xx.xx] executing command

    command finished in 158ms

  * executing "chmod g+w /home/git/xx.xx.xx.xx /home/git/xx.xx.xx.xx/releases /home/git/xx.xx.xx.xx/shared /home/git/xx.xx.xx.xx/shared/system /home/git/xx.xx.xx.xx/shared/log /home/git/xx.xx.xx.xx/shared/pids"

    servers: ["xx.xx.xx.xx"]

    [xx.xx.xx.xx] executing command

    command finished in 7ms

~/rails_projects/depot$ cap deploy:check

  * 2012-11-13 10:37:39 executing `deploy:check'

  * executing "test -d /home/git/xx.xx.xx.xx/releases"

    servers: ["xx.xx.xx.xx"]

    [xx.xx.xx.xx] executing command

    command finished in 152ms

  * executing "test -w /home/git/xx.xx.xx.xx"

    servers: ["xx.xx.xx.xx"]

    [xx.xx.xx.xx] executing command

    command finished in 5ms

  * executing "test -w /home/git/xx.xx.xx.xx/releases"

    servers: ["xx.xx.xx.xx"]

    [xx.xx.xx.xx] executing command

    command finished in 5ms

  * executing "which tar"

    servers: ["xx.xx.xx.xx"]

    [xx.xx.xx.xx] executing command

    command finished in 6ms

You appear to have all necessary dependencies installed
但是当cap-deploy:migrations、cap-deploy或cap-deploy:cold命令出现时,下一个弹出窗口是:

~/rails_projects/depot$ cap deploy:migrations

  * 2012-11-13 10:37:42 executing `deploy:migrations'

  * 2012-11-13 10:37:42 executing `deploy:update_code'

    executing locally: "git ls-remote git@xx.xx.xx.xx:depot.git master"

    command finished in 241ms

  * getting (via checkout) revision c3f88ca97e5868dd476f20e9a044b7dad800274a to /tmp/20121113173743

    executing locally: git clone git@xx.xx.xx.xx:depot.git /tmp/20121113173743 && cd /tmp/20121113173743 && git checkout -b deploy c3f8
8ca97e5868dd476f20e9a044b7dad800274a

Cloning into '/tmp/20121113173743'...

remote: Counting objects: 392, done.

remote: Compressing objects: 100% (257/257), done.

remote: Total 392 (delta 111), reused 392 (delta 111)

Receiving objects: 100% (392/392), 8.59 MiB, done.

Resolving deltas: 100% (111/111), done.

Switched to a new branch 'deploy'

    command finished in 769ms

  * Compressing /tmp/20121113173743 to /tmp/20121113173743.tar.gz

    executing locally: tar czf 20121113173743.tar.gz 20121113173743

    command finished in 652ms

    servers: ["xx.xx.xx.xx"]

 ** sftp upload /tmp/20121113173743.tar.gz -> /tmp/20121113173743.tar.gz

    [xx.xx.xx.xx] /tmp/20121113173743.tar.gz

*** upload via sftp failed on xx.xx.xx.xx: Net::SFTP::StatusException 
(Net::SFTP::StatusException open /tmp/20121113173743.tar.gz (3, "permission denied"))

upload via sftp failed on xx.xx.xx.xx: Net::SFTP::StatusException (Net::SFTP::StatusException open /tmp/20121113173743.tar.gz (3, "permission denied"))

我很抱歉,如果这是一个虚拟的问题,一个简单的修复或已经发布了一个,但我不知道还有什么可以尝试,再次我只是从这个东西开始,我真的迷路了。我在同一台机器上运行,所有的xx.xx.xx.xx代表我的ip地址。任何建议都将不胜感激。我试着尽可能具体一些,但如果遗漏了什么,我会把它贴出来。提前感谢您的时间和帮助。

尝试将此行添加到deploy.rb配置文件中:

default_run_options[:pty] = true

这里的问题是,sftp的源位置和目标位置相同:

** sftp upload /tmp/20121113173743.tar.gz -> /tmp/20121113173743.tar.gz
为了解决此问题,您可以在config/deploy.rb文件中指定参数copy_dir,如下所示:

require 'bundler/capistrano'

set :user, 'user_created_for_this_example'

set :domain,  'IPADDRESS'

set :application, 'depot'

# file paths

set :repository,  "#{user}@#{domain}:depot.git"

set :deploy_to, "/home/#{user}/#{domain}"

# set :scm, :git # You can set :scm explicitly or Capistrano will make an intelligent guess 
based on known version control directory names

# Or: `accurev`, `bzr`, `cvs`, `darcs`, `git`, `mercurial`, `perforce`, `subversion` or `none`

#roles server

role :web, domain

role :app, domain

role :db, domain, :primary => true

#deploy config

set :deploy_to, "/home/#{user}/#{domain}"

set :deploy_via, :copy

set :scm, 'git'

set :branch, 'master'

set :scm_verbose, true

set :use_sudo, false 


# if you want to clean up old releases on each deploy uncomment this:
# after "deploy:restart", "deploy:cleanup"

# if you're still using the script/reaper helper you will need
# these http://github.com/rails/irs_process_scripts

# If you are using Passenger mod_rails uncomment this:

namespace :deploy do

  task :start do ; end

  task :stop do ; end

  task :restart, :roles => :app, :except => { :no_release => true } do

    run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"

  end

end

after "deploy:update_code", :bundle_install

desc "install the necesary prerequisites"

task :bundle_install, :roles => :app do

  run "cd #{release_path} && bundle install"

end
set :copy_dir, "/tmp/sftp"

无需手动创建该文件夹。

我们从

set :deploy_via, :copy

这对我们很有效。我们没有添加以下行

default_run_options[:pty] = true

权限被拒绝
:权限不足?你能手动访问你的FTP并在
/home/user/etc
中写东西吗?我确信问题出在你的FTP配置中。我有同样的问题并解决它。使用ls-al/可以看到哪个组是tmp文件夹的创建者。使用id、groups和usermod命令,您必须将自己添加到creator组中。这是一个老问题,但如果您仍然想知道:谢谢Dario!,但是结果还是一样的,我也读过关于添加ssh\u选项[:forward\u agent]=true的文章,没有不同的结果。我确实认为问题在于权限,但我不知道如何解决。再次感谢您的回答和时间,我们将采纳您的任何建议,并对由此带来的麻烦表示歉意。谢谢您对我的帮助。现在显示:sftp upload/tmp/sftp/20160202184928.tar.gz->/tmp/20160202184928.tar.gz没有更多错误