尝试限制部署时出错:使用rails进行迁移

时间:2013-03-10 21:37:21

标签: ruby-on-rails capistrano

尝试将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

考虑到在部署过程中出现错误:迁移,可能是db错误?有什么不对?部署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中。

2 个答案:

答案 0 :(得分: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 deploy:setup

答案 1 :(得分:0)

问题原来是这样的:

服务器预装了Mysql 5.5 + Percona。我尝试使用它,但没有经验,我可能没有正确配置一切。我最终清理了服务器,在其上安装了空白的Ubuntu,然后安装了一个基本的PostgreSQL。现在一切都有效。感谢大家帮助我!