2

私は現在、Capistranoを使用して最初のRailsデプロイメントを試みているところですが、克服できなかった障害に遭遇しました。cap deployエラー「mkdir: cannot create directory/public'`」が発生します。

関連する詳細:

  • Railsバージョン:3.2.6
  • キャピストラーノバージョン:2.13.5
  • Dreamhostで実行
  • アセットをプリコンパイルしているので(これは問題の一部だと思います)、load 'deploy/assets'Capfileを使用しています。

私はここの指示に従いました:http ://wiki.dreamhost.com/Capistranoの大部分、およびCapistranoに関する他の多くの記事をWebで精査しました。

deploy.rb

require "bundler/capistrano"

ssh_options[:forward_agent] = true
ssh_options[File.join(ENV["HOME"], ".ssh", "id_rsa-dreamhost")]

set :application, "<app>"
set :repository,  "git@bitbucket.org:<gituser>/#{application}.git"
set :server_name, "<host>"
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`
set :checkout, "export"
set :deploy_via, :remote_cache
set :branch, "master"

set :base_path, "/home/<user>/<domain>"
set :deploy_to, "#{base_path}/#{application}"
set :keep_releases, 3

set :user, '<user>'
set :runner, '<user>'

set :use_sudo, false

default_run_options[:pty] = true

set :shared_path, "/home/<user>/<shared_folder>"
set :release_path, "#{base_path}/#{application}"

role :web, "<host>"                          # Your HTTP server, Apache/etc
role :app, "<host>"                          # This may be the same as your `Web` server
role :db,  "<host>", :primary => true # This is where Rails migrations will run

# 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

  desc "Restart the app by touching the restart.txt file."
  task :restart, :roles => :app, :except => { :no_release => true } do
    run "touch #{File.join(current_path,'tmp','restart.txt')}"
  end

  desc "Update the environment-specific files from the shared folder."
  task :symlink_shared, :roles => [:app] do
    run "ln -s #{shared_path}/app_config.yml #{release_path}/config/"

    run "rm #{release_path}/config/database.yml"
    run "ln -s #{shared_path}/database.yml #{release_path}/config/"

    run "rm #{release_path}/public/.htaccess"
    run "ln -s #{shared_path}/.htaccess #{release_path}/public/"
  end
end

before "deploy:restart", "deploy:symlink_shared"
after "deploy:update_code", "deploy:migrate"

cap deploy:setupの出力

* 2012-12-23 16:49:27 executing `deploy:setup'
  * executing "mkdir -p /home/<user>/<domain>/<app> /home/<user>/<domain>/<app>/releases   /home/<user>/<shared_folder> /home/<user>/<shared_folder>/system  /home/<user>/<shared_folder>/log /home/<user>/<shared_folder>/pids"
    servers: ["<host>"]
    [<host>] executing command
    command finished in 263ms
  * executing "chmod g+w /home/<user>/<domain>/<app>  /home/<user>/<domain>/<app>/releases /home/<user>/<shared_folder>  /home/<user>/<shared_folder>/system /home/<user>/<shared_folder>/log  /home/<user>/<shared_folder>/pids"
    servers: ["<host>"]
    [<host>] executing command
    command finished in 261ms

キャップデプロイの出力:チェック

* 2012-12-23 16:49:45 executing `deploy:check'
  * executing "test -d /home/<user>/<domain>/<app>/releases"
    servers: ["<host>"]
    [<host>] executing command
    command finished in 265ms
  * executing "test -w /home/<user>/<domain>/<app>"
    servers: ["<host>"]
    [<host>] executing command
    command finished in 256ms
  * executing "test -w /home/<user>/<domain>/<app>/releases"
    servers: ["<host>"]
    [<host>] executing command
    command finished in 256ms
  * executing "which git"
    servers: ["<host>"]
    [<host>] executing command
    command finished in 259ms
  * executing "test -w /home/<user>/<shared_folder>"
    servers: ["<host>"]
    [<host>] executing command
    command finished in 263ms
You appear to have all necessary dependencies installed

cap:deployの出力

* 2012-12-23 16:51:41 executing `deploy'
  * 2012-12-23 16:51:41 executing `deploy:update'
 ** transaction: start
  * 2012-12-23 16:51:41 executing `deploy:update_code'
    updating the cached checkout on all servers
    executing locally: "git ls-remote git@bitbucket.org:<gituser>/<app>.git master"
    command finished in 1102ms
  * executing "if [ -d /home/<user>/<shared_folder>/cached-copy ]; then cd /home/<user>/<shared_folder>/cached-copy && git fetch -q origin && git fetch --tags -q origin && git reset -q --hard 42dfb6a3f529e2293192f5e22c3214b7da55c9b4 && git clean -q -d -x -f; else git clone -q git@bitbucket.org:<gituser>/<app>.git /home/<user>/<shared_folder>/cached-copy && cd /home/<user>/<shared_folder>/cached-copy && git checkout -q -b deploy 42dfb6a3f529e2293192f5e22c3214b7da55c9b4; fi"
    servers: ["<host>"]
    [<host>] executing command
    command finished in 3233ms
    copying the cached version to /home/<user>/<domain>/<app>
  * executing "cp -RPp /home/<user>/<shared_folder>/cached-copy /home/<user>/<domain>/<app> && (echo 42dfb6a3f529e2293192f5e22c3214b7da55c9b4 > /home/<user>/<domain>/<app>/REVISION)"
    servers: ["<host>"]
    [<host>] executing command
    command finished in 338ms
  * 2012-12-23 16:51:47 executing `deploy:finalize_update'
    triggering before callbacks for `deploy:finalize_update'
  * 2012-12-23 16:51:47 executing `deploy:assets:symlink'
  * executing "ls -x /home/<user>/<domain>/<app>/releases"
    servers: ["<host>"]
    [<host>] executing command
    command finished in 252ms
  * executing "rm -rf /public/assets &&\\\n        mkdir -p /public &&\\\n        mkdir -p /home/<user>/<shared_folder>/assets &&\\\n        ln -s /home/<user>/<shared_folder>/assets /public/assets"
    servers: ["<host>"]
    [<host>] executing command
 ** [out :: <host>] mkdir: cannot create directory `/public'
 ** [out :: <host>] : Permission denied
    command finished in 268ms
*** [deploy:update_code] rolling back
  * executing "rm -rf /home/<user>/<domain>/<app>; true"
    servers: ["<host>"]
    [<host>] executing command
    command finished in 265ms
failed: "sh -c 'rm -rf /public/assets &&\\\n        mkdir -p /public &&\\\n        mkdir -p /home/<user>/<shared_folder>/assets &&\\\n        ln -s /home/<user>/<shared_folder>/assets /public/assets'" on <host>

出力の下部にあるPermissiondeniedエラーと、最後に失敗したシェルコマンドを確認できます。ルート上のパブリックフォルダーのように見えるものを参照するのではなく、Webフォルダー内の相対パスを期待するため、なぜそれがで何かを行おうとしているのか理解できません。mkdirコマンドの前に追加する必要のある変数参照がどこかにないように感じますが、私が読んだドキュメントのいずれもこれを示していません。/publicpublic

私が得ることができるどんな助けにも感謝します、そして前もって感謝します。

4

1 に答える 1

1

release_path自分で設定しないshared_pathでください。Capistranoにそれを自動的に理解させてください。

deploy_toただし、正しく設定する必要があります。

set :deploy_to, "/home/<user>/<domain>/<application>"

変数にも注意してください。Capistranoのset構文は、変数が置換に使用できることを意味するものではありません。"#{base_path}/"がゼロであるために問題が発生し、に評価され"/"ます。

Capistranoの構成wikiで詳細を確認してください。

于 2012-12-24T01:25:43.980 に答える