0

我試着去部署與Capistrano的nginx的一個簡單的應用程序和麒麟Capistrano的權限被拒絕的錯誤:設置

  • /srv/paintings.git(發起並推動回購)

  • /SRV /繪畫(應安裝應用程序的地方)

我deploy.rb看起來像

# config/deploy.rb 
require "bundler/capistrano" 

set :scm,    :git 
set :repository,  "[email protected]:srv/paintings.git" 
set :branch,   "origin/master" 
set :migrate_target, :current 
set :ssh_options,  { :forward_agent => true } 
set :rails_env,  "production" 
set :deploy_to,  "/srv/paintings" 
set :normalize_asset_timestamps, false 

set :user,   "root" 
set :group,   "rvm" 
set :use_sudo,  true 

role :web, "109.0.0.0.05" 
role :app, "109.0.0.0.05" 
role :db,  "109.0.0.0.05", :primary => true 

set(:latest_release) { fetch(:current_path) } 
set(:release_path) { fetch(:current_path) } 
set(:current_release) { fetch(:current_path) } 

set(:current_revision) { capture("cd #{current_path}; git rev-parse --short HEAD").strip } 
set(:latest_revision) { capture("cd #{current_path}; git rev-parse --short HEAD").strip } 
set(:previous_revision) { capture("cd #{current_path}; git rev-parse --short [email protected]{1}").strip } 

default_environment["RAILS_ENV"] = 'production' 
default_run_options[:shell] = 'bash' 

namespace :deploy do 
    desc "Deploy your application" 
    task :default do 
    update 
    restart 
    end 

    desc "Setup your git-based deployment app" 
    task :setup, :except => { :no_release => true } do 
    dirs = [deploy_to, shared_path] 
    dirs += shared_children.map { |d| File.join(shared_path, d) } 
    run "#{try_sudo} mkdir -p #{dirs.join(' ')} && #{try_sudo} chmod g+w #{dirs.join(' ')}" 
    run "git clone #{repository} #{current_path}" 
    end 

    task :cold do 
    update 
    migrate 
    end 

    task :update do 
    transaction do 
     update_code 
    end 
    end 

    desc "Update the deployed code." 
    task :update_code, :except => { :no_release => true } do 
    run "cd #{current_path}; git fetch origin; git reset --hard #{branch}" 
    finalize_update 
    end 

    desc "Update the database (overwritten to avoid symlink)" 
    task :migrations do 
    transaction do 
     update_code 
    end 
    migrate 
    restart 
    end 

    task :finalize_update, :except => { :no_release => true } do 
    run "chmod -R g+w #{latest_release}" if fetch(:group_writable, true) 

    # mkdir -p is making sure that the directories are there for some SCM's that don't 
    # save empty folders 
    run <<-CMD 
     rm -rf #{latest_release}/log #{latest_release}/public/system #{latest_release}/tmp/pids && 
     mkdir -p #{latest_release}/public && 
     mkdir -p #{latest_release}/tmp && 
     ln -s #{shared_path}/log #{latest_release}/log && 
     ln -s #{shared_path}/system #{latest_release}/public/system && 
     ln -s #{shared_path}/pids #{latest_release}/tmp/pids && 
     ln -sf #{shared_path}/database.yml #{latest_release}/config/database.yml 
    CMD 

    if fetch(:normalize_asset_timestamps, true) 
     stamp = Time.now.utc.strftime("%Y%m%d%H%M.%S") 
     asset_paths = fetch(:public_children, %w(images stylesheets javascripts)).map { |p| "#{latest_release}/public/#{p}" }.join(" ") 
     run "find #{asset_paths} -exec touch -t #{stamp} {} ';'; true", :env => { "TZ" => "UTC" } 
    end 
    end 

    desc "Zero-downtime restart of Unicorn" 
    task :restart, :except => { :no_release => true } do 
    run "kill -s USR2 `cat /tmp/unicorn.my_site.pid`" 
    end 

    desc "Start unicorn" 
    task :start, :except => { :no_release => true } do 
    run "cd #{current_path} ; bundle exec unicorn_rails -c config/unicorn.rb -D" 
    end 

    desc "Stop unicorn" 
    task :stop, :except => { :no_release => true } do 
    run "kill -s QUIT `cat /tmp/unicorn.my_site.pid`" 
    end 

    namespace :rollback do 
    desc "Moves the repo back to the previous version of HEAD" 
    task :repo, :except => { :no_release => true } do 
     set :branch, "[email protected]{1}" 
     deploy.default 
    end 

    desc "Rewrite reflog so [email protected]{1} will continue to point to at the next previous release." 
    task :cleanup, :except => { :no_release => true } do 
     run "cd #{current_path}; git reflog delete --rewrite [email protected]{1}; git reflog delete --rewrite [email protected]{1}" 
    end 

    desc "Rolls back to the previously deployed version." 
    task :default do 
     rollback.repo 
     rollback.cleanup 
    end 
    end 
end 

def run_rake(cmd) 
    run "cd #{current_path}; #{rake} #{cmd}" 
end 

日誌輸出: *做帽時:設置 *

 [109.etc] env RAILS_ENV=production sh -c 'git clone [email protected]:srv/paintings.git /srv/paintings/current' 
** [out :: 109.etc] Initialized empty Git repository in /srv/paintings/current/.git/ 
** [out :: 109.etc] The authenticity of host '109.etc (109.etc)' can't be established. 
** [out :: 109.etc] RSA key fingerprint is e9:af etc. 
** [out :: 109.etc] Are you sure you want to continue connecting (yes/no)? 

Typing Yes keeps me waiting forever with no status updates 
+0

檢查生產機器中是否存在版本[/ srv/paintings/releases]文件夾。我認爲你必須在生產機器上手動創建這個文件夾。 – Arun 2012-03-12 09:50:50

+0

thx。它不存在,試圖手動添加它,但錯誤仍然存​​在 – Rubytastic 2012-03-12 10:13:57

+0

set:use_sudo as false並嘗試它。 – Arun 2012-03-14 11:09:37

回答

1

我當我告訴Capistrano連接到一個我以前從未連接過的ssh服務器時,有一次類似的錯誤。您是否嘗試過使用ssh [email protected]連接服務器(使用同一用戶,即root而不是git)?

它可能會再次問你是否要信任服務器。如果是這樣的話,我的猜測是卡皮斯特拉諾對你的'是'輸入沒有反應。

另外,您以root身份連接到您的服務器。這意味着你不需要將use_sudo設置爲true

+0

得到這個修正,thx無法更新帖子。似乎部署現在全部運行,但像獨角獸一樣有一些小問題,但猜測不適合這種獎勵。 – Rubytastic 2012-03-16 14:49:20

+0

我很高興你能工作。 – Pascal 2012-03-17 13:52:53

+0

還不完全,我很恐怖再次卡住另一部分,並想到發佈一個問題,但這將在另一個話題。謝謝 – Rubytastic 2012-03-17 13:53:37

1

不使用default_environment["PATH"] = "--"bash提供完整的路徑以某種方式(通常/bin/bash

+0

Thx指出這樣明顯的東西,我*完全*錯過,即使我已經看了好幾次,似乎不夠好。在發佈更新時更改了該部分。但問題確切的一致持續 – Rubytastic 2012-03-14 12:29:03