0

Rails アプリをリモート サーバーにデプロイしようとしています。

このエラーが何度も発生し、問題の解決方法がわかりません。

コンソールログは次のとおりです。

D:\>cap deploy:migrations
  * ←[32m2013-03-11 01:15:33 executing `deploy:migrations'←[0m
  * ←[32m2013-03-11 01:15:33 executing `deploy:update_code'←[0m
    updating the cached checkout on all servers
    ←[33mexecuting locally: "git ls-remote root@NNN.NNN.131.4:myAppName.git mast
er"←[0m
root@NNN.NNN.131.4's password:
    ←[2;37mcommand finished in 11708ms←[0m
  * ←[33mexecuting "if [ -d /home/root/myAppName/shared/cached-copy ]; then cd /
home/root/myAppName/shared/cached-copy && git fetch  origin && git fetch --tags
 origin && git reset  --hard eba696f2195d19adba5fc7730828a69e7bfc3e9d && git cle
an  -d -x -f; else git clone root@NNN.NNN.131.4:myAppName.git /home/root/2antica
fe/shared/cached-copy && cd /home/root/myAppName/shared/cached-copy && git check
out -b deploy eba696f2195d19adba5fc7730828a69e7bfc3e9d; fi"←[0m
    servers: ["NNN.NNN.131.4"]
Password:
    [NNN.NNN.131.4] executing command
 ** [NNN.NNN.131.4 :: out] Cloning into '/home/root/myAppName/shared/cached-copy
'...
 ** [NNN.NNN.131.4 :: err] Host key verification failed.
 ** [NNN.NNN.131.4 :: err] fatal: The remote end hung up unexpectedly
    ←[2;37mcommand finished in 1171ms←[0m
failed: "sh -c 'if [ -d /home/root/myAppName/shared/cached-copy ]; then cd /home
/root/myAppName/shared/cached-copy && git fetch  origin && git fetch --tags  ori
gin && git reset  --hard eba696f2195d19adba5fc7730828a69e7bfc3e9d && git clean
-d -x -f; else git clone root@NNN.NNN.131.4:myAppName.git /home/root/myAppName/s
hared/cached-copy && cd /home/root/myAppName/shared/cached-copy && git checkout
-b deploy eba696f2195d19adba5fc7730828a69e7bfc3e9d; fi'" on NNN.NNN.131.4

ここに私の deploy.rb があります:

require 'bundler/capistrano'
set :user, 'root'
set :domain, 'NNN.NNN.131.4'
set :application, 'myAppName'

set :repository,  "#{user}@#{domain}:#{application}.git"
set :deploy_to, "/home/#{user}/myAppName"

role :app, domain
role :web, domain
role :db, domain, :primary => true

set :deploy_via, :remote_cache
set :scm, 'git'
set :branch, 'master'
set :scm_verbose, true
set :use_sudo, false
set :rails_env, :production

namespace :deploy do
  desc "cause Passenger to initiate a restart"
  task :restart do
    run "touch #{current_path}/tmp/restart.txt"
  end
  desc "reload the database with seed data"
  task :seed do
    run "cd #{current_path}; rake db:seed RAILS_ENV=#{rails_env}"
  end
end

cap deploy:migrations 中にエラーが発生したことを考えると、おそらく db エラーですか? 何が間違っている可能性がありますか?展開データベースは mysql 5.5 であり、database.yml に適切に記載されています。

編集 1: リポジトリをサーバーに手動で複製しました。スペースを節約するために出力を除外しました。

編集2:

これを deploy.rb に追加します。

default_run_options[:pty] = true

少し役に立ちました。コマンドは引き続き失敗しますが、はるかに長いログが残ります。

D:\>cap deploy:migrations
  * ←[32m2013-03-11 02:24:54 executing `deploy:migrations'←[0m
  * ←[32m2013-03-11 02:24:54 executing `deploy:update_code'←[0m
    updating the cached checkout on all servers
    ←[33mexecuting locally: "git ls-remote root@NNN.NNN.131.4:myAppName.git mast
er"←[0m
root@NNN.NNN.131.4's password:
    ←[2;37mcommand finished in 12717ms←[0m
  * ←[33mexecuting "if [ -d /home/root/myAppName/shared/cached-copy ]; then cd /
home/root/myAppName/shared/cached-copy && git fetch  origin && git fetch --tags
 origin && git reset  --hard 8b6824f3750031076be93783d7d9f66f53b0b429 && git cle
an  -d -x -f; else git clone root@NNN.NNN.131.4:myAppName.git /home/root/2antica
fe/shared/cached-copy && cd /home/root/myAppName/shared/cached-copy && git check
out -b deploy 8b6824f3750031076be93783d7d9f66f53b0b429; fi"←[0m
    servers: ["NNN.NNN.131.4"]
Password:
    [NNN.NNN.131.4] executing command
 ** [NNN.NNN.131.4 :: out] root@NNN.NNN.131.4's password:
Password:
 ** [NNN.NNN.131.4 :: out]
 ** [NNN.NNN.131.4 :: out] root@NNN.NNN.131.4's password:
Password:
 ** [NNN.NNN.131.4 :: out]
 ** [NNN.NNN.131.4 :: out] HEAD is now at 8b6824f capping capistrano
    ←[2;37mcommand finished in 23741ms←[0m
    copying the cached version to /home/root/myAppName/releases/20130310222546
  * ←[33mexecuting "cp -RPp /home/root/myAppName/shared/cached-copy /home/root/2
anticafe/releases/20130310222546 && (echo 8b6824f3750031076be93783d7d9f66f53b0b4
29 > /home/root/myAppName/releases/20130310222546/REVISION)"←[0m
    servers: ["NNN.NNN.131.4"]
    [NNN.NNN.131.4] executing command
    ←[2;37mcommand finished in 772ms←[0m
  * ←[32m2013-03-11 02:25:47 executing `deploy:finalize_update'←[0m
  * ←[33mexecuting "chmod -R -- g+w /home/root/myAppName/releases/20130310222546
 && rm -rf -- /home/root/myAppName/releases/20130310222546/public/system && mkdi
r -p -- /home/root/myAppName/releases/20130310222546/public/ && ln -s -- /home/r
oot/myAppName/shared/system /home/root/myAppName/releases/20130310222546/public/
system && rm -rf -- /home/root/myAppName/releases/20130310222546/log && ln -s --
 /home/root/myAppName/shared/log /home/root/myAppName/releases/20130310222546/lo
g && rm -rf -- /home/root/myAppName/releases/20130310222546/tmp/pids && mkdir -p
 -- /home/root/myAppName/releases/20130310222546/tmp/ && ln -s -- /home/root/2an
ticafe/shared/pids /home/root/myAppName/releases/20130310222546/tmp/pids"←[0m
    servers: ["NNN.NNN.131.4"]
    [NNN.NNN.131.4] executing command
    ←[2;37mcommand finished in 791ms←[0m
  * ←[33mexecuting "find /home/root/myAppName/releases/20130310222546/public/ima
ges /home/root/myAppName/releases/20130310222546/public/stylesheets /home/root/2
anticafe/releases/20130310222546/public/javascripts -exec touch -t 201303102225.
48 -- {} ';'; true"←[0m
    servers: ["NNN.NNN.131.4"]
    [NNN.NNN.131.4] executing command
 ** [out :: NNN.NNN.131.4] find: `/home/root/myAppName/releases/20130310222546/p
ublic/images'
 ** [out :: NNN.NNN.131.4] : No such file or directory
 ** [out :: NNN.NNN.131.4] find: `/home/root/myAppName/releases/20130310222546/p
ublic/stylesheets'
 ** [out :: NNN.NNN.131.4] : No such file or directory
 ** [out :: NNN.NNN.131.4] find:
 ** [out :: NNN.NNN.131.4] `/home/root/myAppName/releases/20130310222546/public/
javascripts'
 ** [out :: NNN.NNN.131.4] : No such file or directory
    ←[2;37mcommand finished in 756ms←[0m
    triggering after callbacks for `deploy:finalize_update'
  * ←[32m2013-03-11 02:25:49 executing `bundle:install'←[0m
  * ←[33mexecuting "ls -x /home/root/myAppName/releases"←[0m
    servers: ["NNN.NNN.131.4"]
    [NNN.NNN.131.4] executing command
    ←[2;37mcommand finished in 721ms←[0m
  * ←[33mexecuting "cd /home/root/myAppName/releases/20130310222546 && bundle in
stall --gemfile /home/root/myAppName/releases/20130310222546/Gemfile --path /hom
e/root/myAppName/shared/bundle --deployment --quiet --without development test"←
[0m
    servers: ["NNN.NNN.131.4"]
    [NNN.NNN.131.4] executing command
 ** [out :: NNN.NNN.131.4] Cannot write a changed lockfile while frozen.
    ←[2;37mcommand finished in 10392ms←[0m
  * ←[32m2013-03-11 02:26:00 executing `deploy:migrate'←[0m
  * ←[33mexecuting "cd /home/root/myAppName/releases/20130310222546 && bundle ex
ec rake RAILS_ENV=production  db:migrate"←[0m
    servers: ["NNN.NNN.131.4"]
    [NNN.NNN.131.4] executing command
 ** [out :: NNN.NNN.131.4] rake aborted!
 ** [out :: NNN.NNN.131.4] Please install the mysql2 adapter: `gem install activ
erecord-mysql2-adapter` (mysql2 is not part of the bundle. Add it to Gemfile.)
 ** [out :: NNN.NNN.131.4] /var/lib/gems/1.9.1/gems/bundler-1.3.0/lib/bundler/ru
bygems_integration.rb:205:in `block in replace_gem'
 ** [out :: NNN.NNN.131.4] /home/root/myAppName/shared/bundle/ruby/1.9.1/gems/ac
tiverecord-3.2.1/lib/active_record/connection_adapters/mysql2_adapter.rb:3:in `<
top (required)>'
 ** [out :: NNN.NNN.131.4] /home/root/myAppName/shared/bundle/ruby/1.9.1/gems/ac
tivesupport-3.2.1/lib/active_support/dependencies.rb:251:in `require'
 ** [out :: NNN.NNN.131.4] /home/root/myAppName/shared/bundle/ruby/1.9.1/gems/ac
tivesupport-3.2.1/lib/active_support/dependencies.rb:251:in `block in require'
 ** [out :: NNN.NNN.131.4] /home/root/myAppName/shared/bundle/ruby/1.9.1/gems/ac
tivesupport-3.2.1/lib/active_support/dependencies.rb:236:in `load_dependency'
 ** [out :: NNN.NNN.131.4] /home/root/myAppName/shared/bundle/ruby/1.9.1/gems/ac
tivesupport-3.2.1/lib/active_support/dependencies.rb:251:in `require'
 ** [out :: NNN.NNN.131.4]
 ** [out :: NNN.NNN.131.4] /home/root/myAppName/shared/bundle/ruby/1.9.1/gems/ac
tiverecord-3.2.1/lib/active_record/connection_adapters/abstract/connection_speci
fication.rb:48:in `resolve_hash_connection'
 ** [out :: NNN.NNN.131.4] /home/root/myAppName/shared/bundle/ruby/1.9.1/gems/ac
tiverecord-3.2.1/lib/active_record/connection_adapters/abstract/connection_speci
fication.rb:39:in `resolve_string_connection'
 ** [out :: NNN.NNN.131.4] /home/root/myAppName/shared/bundle/ruby/1.9.1/gems/ac
tiverecord-3.2.1/lib/active_record/connection_adapters/abstract/connection_speci
fication.rb:23:in `spec'
 ** [out :: NNN.NNN.131.4] /home/root/myAppName/shared/bundle/ruby/1.9.1/gems/ac
tiverecord-3.2.1/lib/active_record/connection_adapters/abstract/connection_speci
fication.rb:127:in `establish_connection'
 ** [out :: NNN.NNN.131.4] /home/root/myAppName/shared/bundle/ruby/1.9.1/gems/ac
tiverecord-3.2.1/lib/active_record/railtie.rb:76:in `block (2 levels) in <class:
Railtie>'
 ** [out :: NNN.NNN.131.4]
 ** [out :: NNN.NNN.131.4] /home/root/myAppName/shared/bundle/ruby/1.9.1/gems/ac
tivesupport-3.2.1/lib/active_support/lazy_load_hooks.rb:36:in `instance_eval'
 ** [out :: NNN.NNN.131.4] /home/root/myAppName/shared/bundle/ruby/1.9.1/gems/ac
tivesupport-3.2.1/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
 ** [out :: NNN.NNN.131.4] /home/root/myAppName/shared/bundle/ruby/1.9.1/gems/ac
tivesupport-3.2.1/lib/active_support/lazy_load_hooks.rb:26:in `on_load'
 ** [out :: NNN.NNN.131.4] /home/root/myAppName/shared/bundle/ruby/1.9.1/gems/ac
tiverecord-3.2.1/lib/active_record/railtie.rb:74:in `block in <class:Railtie>'
 ** [out :: NNN.NNN.131.4] /home/root/myAppName/shared/bundle/ruby/1.9.1/gems/ra
ilties-3.2.1/lib/rails/initializable.rb:30:in `instance_exec'
 ** [out :: NNN.NNN.131.4] /home/root/myAppName/shared/bundle/ruby/1.9.1/gems/ra
ilties-3.2.1/lib/rails/initializable.rb:30:in `run'
 ** [out :: NNN.NNN.131.4] /home/root/myAppName/shared/bundle/ruby/1.9.1/gems/ra
ilties-3.2.1/lib/rails/initializable.rb:55:in `block in run_initializers'
 ** [out :: NNN.NNN.131.4] /home/root/myAppName/shared/bundle/ruby/1.9.1/gems/ra
ilties-3.2.1/lib/rails/initializable.rb:54:in `each'
 ** [out :: NNN.NNN.131.4] /home/root/myAppName/shared/bundle/ruby/1.9.1/gems/ra
ilties-3.2.1/lib/rails/initializable.rb:54:in `run_initializers'
 ** [out :: NNN.NNN.131.4] /home/root/myAppName/shared/bundle/ruby/1.9.1/gems/ra
ilties-3.2.1/lib/rails/application.rb:136:in `initialize!'
 ** [out :: NNN.NNN.131.4] /home/root/myAppName/shared/bundle/ruby/1.9.1/gems/ra
ilties-3.2.1/lib/rails/railtie/configurable.rb:30:in `method_missing'
 ** [out :: NNN.NNN.131.4]
 ** [out :: NNN.NNN.131.4] /home/root/myAppName/releases/20130310222546/config/e
nvironment.rb:5:in `<top (required)>'
 ** [out :: NNN.NNN.131.4] /home/root/myAppName/shared/bundle/ruby/1.9.1/gems/ac
tivesupport-3.2.1/lib/active_support/dependencies.rb:251:in `require'
 ** [out :: NNN.NNN.131.4] /home/root/myAppName/shared/bundle/ruby/1.9.1/gems/ac
tivesupport-3.2.1/lib/active_support/dependencies.rb:251:in `block in require'
 ** [out :: NNN.NNN.131.4] /home/root/myAppName/shared/bundle/ruby/1.9.1/gems/ac
tivesupport-3.2.1/lib/active_support/dependencies.rb:236:in `load_dependency'
 ** [out :: NNN.NNN.131.4] /home/root/myAppName/shared/bundle/ruby/1.9.1/gems/ac
tivesupport-3.2.1/lib/active_support/dependencies.rb:251:in `require'
 ** [out :: NNN.NNN.131.4] /home/root/myAppName/shared/bundle/ruby/1.9.1/gems/ra
ilties-3.2.1/lib/rails/application.rb:103:in `require_environment!'
 ** [out :: NNN.NNN.131.4] /home/root/myAppName/shared/bundle/ruby/1.9.1/gems/ra
ilties-3.2.1/lib/rails/application.rb:292:in `block (2 levels) in initialize_tas
ks'
 ** [out :: NNN.NNN.131.4]
 ** [out :: NNN.NNN.131.4] Tasks: TOP => db:migrate => environment
 ** [out :: NNN.NNN.131.4] (See full trace by running task with --trace)
    ←[2;37mcommand finished in 6856ms←[0m
failed: "sh -c 'cd /home/root/myAppName/releases/20130310222546 && bundle exec r
ake RAILS_ENV=production  db:migrate'" on NNN.NNN.131.4

capistrano、mysql2、activerecord-mysql2-adapter はすべて gemfile にあります。

4

2 に答える 2

0

deploy.rbに以下を含めて、SSHキー転送を有効にします

ssh_options[:forward_agent] = true
default_run_options[:pty] = true

ただし、これを機能させるには、現在行っているようにパスワードではなく、SSHキーを使用してデプロイターゲットに接続する必要があります。秘密SSHキーの場所をdeploy.rbに入れます。例えば。

ssh_options[:keys] = %w(~/.keys/my-secret.pem)

また、他のcapタスクを実行する前に、cap deploy:setupを少なくとも1回実行する必要があります。アプリケーションディレクトリが存在しないことを示すログのエラーは、おそらく次のコマンドを実行する必要があることを意味します。

cap deploy:setup
于 2013-03-11T05:06:49.280 に答える
0

問題は次のようになりました。

サーバーには、Mysql 5.5 + Percona がプリインストールされていました。私はそれを使用しようとしましたが、経験がほとんどないため、すべてが正しく構成されていない可能性があります。サーバーをクリアし、空のUbuntuをインストールしてから、基本的なPostgreSQLをインストールしました。すべてが機能するようになりました。助けてくれてありがとう!

于 2013-03-29T05:44:53.590 に答える