AWS OpsWorks - 无法使用AWS OpsWorks部署我的应用程序,尤其是无法成功迁移

时间:2015-07-26 08:57:16

标签: amazon-web-services aws-opsworks

遵循此文档(http://railsconf2015-aws.s3-website-us-east-1.amazonaws.com/),我正在尝试使用AWS OpsWorks部署我的rails应用程序。但是,我没有做到,特别是当我试图迁移它时。

这是错误日志。

Your bundle is complete!
Gems in the groups test and development were not installed.
It was installed into /home/deploy/.bundler/sample_app

[2015-07-26T08:21:32+00:00] INFO: No database adapter specified for sample_app, guessing
[2015-07-26T08:21:32+00:00] INFO: Looks like sample_app uses mysql2 in its Gemfile
[2015-07-26T08:21:32+00:00] INFO: Processing template[/srv/www/sample_app/shared/config/database.yml] action create (/var/lib/aws/opsworks/cache.stage2/cookbooks/deploy/definitions/opsworks_deploy.rb line 115)
[2015-07-26T08:21:32+00:00] INFO: deploy[/srv/www/sample_app] queueing checkdeploy hook /srv/www/sample_app/releases/20150726082129/deploy/before_migrate.rb
[2015-07-26T08:21:32+00:00] INFO: Processing template[/srv/www/sample_app/shared/config/database.yml] action create (/var/lib/aws/opsworks/cache.stage2/cookbooks/deploy/definitions/opsworks_deploy.rb line 115)
[2015-07-26T08:21:32+00:00] INFO: deploy[/srv/www/sample_app] made pre-migration symlinks
[2015-07-26T08:21:32+00:00] INFO: deploy[/srv/www/sample_app] set user to deploy
[2015-07-26T08:21:32+00:00] INFO: deploy[/srv/www/sample_app] set group to nginx
[2015-07-26T08:21:32+00:00] INFO: deploy[/srv/www/sample_app] migrating deploy

================================================================================
Error executing action `deploy` on resource 'deploy[/srv/www/sample_app]'
================================================================================


Chef::Exceptions::Exec
----------------------
if [ -f Gemfile ]; then echo 'OpsWorks: Gemfile found - running migration with bundle exec' && /usr/local/bin/bundle exec /usr/local/bin/rake db:migrate; else echo 'OpsWorks: no Gemfile - running plain migrations' && /usr/local/bin/rake db:migrate; fi returned 1, expected 0


Cookbook Trace:
---------------
/var/lib/aws/opsworks/cache.stage2/cookbooks/opsworks_commons/libraries/monkey_patch_deploy_provider.rb:45:in `block in migrate'
/var/lib/aws/opsworks/cache.stage2/cookbooks/opsworks_commons/libraries/monkey_patch_deploy_provider.rb:39:in `migrate'


Resource Declaration:
---------------------
# In /var/lib/aws/opsworks/cache.stage2/cookbooks/deploy/definitions/opsworks_deploy.rb

65:     deploy deploy[:deploy_to] do
66:       provider Chef::Provider::Deploy.const_get(deploy[:chef_provider])
67:       keep_releases deploy[:keep_releases]
68:       repository deploy[:scm][:repository]
69:       user deploy[:user]
70:       group deploy[:group]
71:       revision deploy[:scm][:revision]
72:       migrate deploy[:migrate]
73:       migration_command deploy[:migrate_command]
74:       environment deploy[:environment].to_hash
75:       purge_before_symlink(deploy[:purge_before_symlink]) unless deploy[:purge_before_symlink].nil?
76:       create_dirs_before_symlink(deploy[:create_dirs_before_symlink])
77:       symlink_before_migrate(deploy[:symlink_before_migrate])
78:       symlinks(deploy[:symlinks]) unless deploy[:symlinks].nil?
79:       action deploy[:action]
80: 
81:       if deploy[:application_type] == 'rails' && node[:opsworks][:instance][:layers].include?('rails-app')
82:         restart_command "sleep #{deploy[:sleep_before_restart]} && #{node[:opsworks][:rails_stack][:restart_command]}"
83:       end
84: 



Compiled Resource:
------------------
# Declared in /var/lib/aws/opsworks/cache.stage2/cookbooks/deploy/definitions/opsworks_deploy.rb:65:in `block in from_file'

deploy("/srv/www/sample_app") do
params {:deploy_data=>{"deploy_to"=>"/srv/www/sample_app", "chef_provider"=>"Timestamped", "keep_releases"=>5, "current_path"=>"/srv/www/sample_app/current", "document_root"=>"public", "ignore_bundler_groups"=>["test", "development"], "absolute_document_root"=>"/srv/www/sample_app/current/public/", "rake"=>"/usr/local/bin/rake", "migrate"=>true, "migrate_command"=>"if [ -f Gemfile ]; then echo 'OpsWorks: Gemfile found - running migration with bundle exec' && /usr/local/bin/bundle exec /usr/local/bin/rake db:migrate; else echo 'OpsWorks: no Gemfile - running plain migrations' && /usr/local/bin/rake db:migrate; fi", "rails_env"=>"production", "action"=>"deploy", "user"=>"deploy", "group"=>"nginx", "shell"=>"/bin/bash", "home"=>"/home/deploy", "sleep_before_restart"=>0, "stack"=>{"needs_reload"=>true}, "enable_submodules"=>true, "shallow_clone"=>false, "delete_cached_copy"=>true, "purge_before_symlink"=>["log", "tmp/pids", "public/system"], "create_dirs_before_symlink"=>["tmp", "public", "config"], "symlink_before_migrate"=>{"config/database.yml"=>"config/database.yml", "config/memcached.yml"=>"config/memcached.yml"}, "symlinks"=>{"system"=>"public/system", "pids"=>"tmp/pids", "log"=>"log"}, "environment"=>{"RAILS_ENV"=>"production", "RUBYOPT"=>"", "RACK_ENV"=>"production", "HOME"=>"/home/deploy", "SECRET_KEY_BASE"=>"42426faeafcbeafc1ac73a23d0844b7e3f4a27d8cc5a15b8c9ea9e092bab7f0d2f87c5102411aac919a3425bbe4560fb686e22525871236b9322c4b5573bf4da"}, "environment_variables"=>{"SECRET_KEY_BASE"=>"42426faeafcbeafc1ac73a23d0844b7e3f4a27d8cc5a15b8c9ea9e092bab7f0d2f87c5102411aac919a3425bbe4560fb686e22525871236b9322c4b5573bf4da"}, "ssl_support"=>false, "auto_npm_install_on_deploy"=>true, "nodejs"=>{"restart_command"=>"monit restart node_web_app_sample_app", "stop_command"=>"monit stop node_web_app_sample_app", "port"=>80}, "application"=>"sample_app", "application_type"=>"rails", "auto_bundle_on_deploy"=>true, "deploying_user"=>"arn:aws:iam::934616152548:root", "domains"=>["sample_app"], "mounted_at"=>nil, "restart_command"=>nil, "ssl_certificate"=>nil, "ssl_certificate_key"=>nil, "ssl_certificate_ca"=>nil, "scm"=>{"scm_type"=>"git", "repository"=>"https://github.com/takuwan0405/sample_app.git", "revision"=>nil, "ssh_key"=>nil, "user"=>nil, "password"=>nil}, "database"=>{"host"=>"172.31.10.7", "database"=>"sample_app", "port"=>3306, "username"=>"root", "password"=>"k7gs5opqfr", "reconnect"=>true, "data_source_provider"=>"stack", "type"=>"mysql"}, "memcached"=>{"host"=>nil, "port"=>11211}}, :app=>"sample_app", :name=>nil}
provider Chef::Provider::Deploy::Timestamped
action [:deploy]
updated true
updated_by_last_action true
retries 0
retry_delay 2
deploy_to "/srv/www/sample_app"
environment {"RAILS_ENV"=>"production", "RUBYOPT"=>"", "RACK_ENV"=>"production", "HOME"=>"/home/deploy", "SECRET_KEY_BASE"=>"42426faeafcbeafc1ac73a23d0844b7e3f4a27d8cc5a15b8c9ea9e092bab7f0d2f87c5102411aac919a3425bbe4560fb686e22525871236b9322c4b5573bf4da", "LC_ALL"=>"C"}
repository_cache "cached-copy"
purge_before_symlink ["log", "tmp/pids", "public/system"]
create_dirs_before_symlink ["tmp", "public", "config"]
symlink_before_migrate {"config/database.yml"=>"config/database.yml", "config/memcached.yml"=>"config/memcached.yml"}
symlinks {"system"=>"public/system", "pids"=>"tmp/pids", "log"=>"log"}
revision "HEAD"
migrate true
remote "origin"
enable_submodules true
scm_provider Chef::Provider::Git
keep_releases 5
enable_checkout true
checkout_branch "deploy"
cookbook_name "deploy"
recipe_name "rails"
repo "https://github.com/takuwan0405/sample_app.git"
user "deploy"
group "nginx"
migration_command "if [ -f Gemfile ]; then echo 'OpsWorks: Gemfile found - running migration with bundle exec' && /usr/local/bin/bundle exec /usr/local/bin/rake db:migrate; else echo 'OpsWorks: no Gemfile - running plain migrations' && /usr/local/bin/rake db:migrate; fi"
restart_command "sleep 0 && ../../shared/scripts/unicorn clean-restart"
before_migrate #<Proc:0x007f2d074dcbb0@/var/lib/aws/opsworks/cache.stage2/cookbooks/deploy/definitions/opsworks_deploy.rb:100>
shared_path "/srv/www/sample_app/shared"
destination "/srv/www/sample_app/shared/cached-copy"
current_path "/srv/www/sample_app/current"
end



[2015-07-26T08:21:33+00:00] INFO: Running queued delayed notifications before re-raising exception
[2015-07-26T08:21:33+00:00] ERROR: Running exception handlers
[2015-07-26T08:21:33+00:00] ERROR: Exception handlers complete
[2015-07-26T08:21:33+00:00] FATAL: Stacktrace dumped to /var/lib/aws/opsworks/cache.stage2/chef-stacktrace.out
[2015-07-26T08:21:33+00:00] ERROR: deploy[/srv/www/sample_app] (deploy::rails line 65) had an error: Chef::Exceptions::Exec: if [ -f Gemfile ]; then echo 'OpsWorks: Gemfile found - running migration with bundle exec' && /usr/local/bin/bundle exec /usr/local/bin/rake db:migrate; else echo 'OpsWorks: no Gemfile - running plain migrations' && /usr/local/bin/rake db:migrate; fi returned 1, expected 0
[2015-07-26T08:21:33+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)

它似乎成功进行了“捆绑安装”。

使用ssh,我去了/ srv / www / sample_app / releases / 20150726082129并输入了

rake db:migrate

然后出现错误句子。

Could not find i18n-0.7.0 in any of the sources
Run `bundle install` to install missing gems.

接下来,按照这个错误句子,我输入了

sudo bundle install

然后它说

Your bundle is complete!
Gems in the groups test and development were not installed.
It was installed into /home/deploy/.bundler/sample_app

然而,宝石似乎是空的。如果我输入

gem list

我找不到Gemfile中指定的gems

bigdecimal (1.2.6)
bundler (1.5.3)
io-console (0.4.3)
json (1.8.1)
kgio (2.9.3)
minitest (5.4.3)
power_assert (0.2.2)
psych (2.0.8)
rack (1.6.4)
raindrops (0.15.0)
rake (10.4.2)
rdoc (4.2.0)
test-unit (3.0.8)
unicorn (4.7.0)

我认为这些是解决我的问题的提示。

对不起,我不太擅长英语,所以如果你不明白我想要你帮忙的话,请告诉我一点未知的事。

3 个答案:

答案 0 :(得分:0)

Opworks is a pain to debug via their logs. here are some tips to debug.

You cannot do it in the normal ec2-user account you may be using to ssh. Do this command to be the deploy user ...

sudo su - deploy

which will then allow you to go to your app at the current location ...

cd /srv/www/sample_app/current

you will now also be able to see logs, run rake, and such. In particular, now you can run your failed command ...

if [ -f Gemfile ]; then echo 'OpsWorks: Gemfile found - running migration with bundle exec' && /usr/local/bin/bundle exec /usr/local/bin/rake db:migrate; else echo 'OpsWorks: no Gemfile - running plain migrations' && /usr/local/bin/rake db:migrate; fi

One place to look is in the shared area configuration, logs, i.e. ...

/srv/www/sample_app/shared/config/unicorn.conf 

答案 1 :(得分:0)

我已经使用OpsWorks来大量部署rails应用程序,这种部署错误很常见。

如果您在OpsWorks中部署Ruby on Rails应用程序时遇到迁移错误,只需 SSH 到服务器并转到最后部署文件夹(例如,对于您的情况) :/ srv / www / sample_app / releases / 20150726082129)。

请注意“/ srv / www / {your app name} / current”只会指向您上次从OpsWorks成功部署,如果部署失败,最好直接访问“/ srv”下的最新部署文件夹/ www / {your app name} / releases / {deployment time}“

而不是

rake db:migrate

您应该运行

sudo bundle exec rake db:migrate

然后,您将看到更有意义的迁移错误,然后您应该知道该怎么做。

答案 2 :(得分:0)

我发现了问题,至少它对我有用。

迁移失败的原因可能有很多原因,OpsWorks日志无法帮助我们。 正如你们许多人建议的那样,要确切了解发生了什么,我们必须通过SSH登录我们的某个实例并尝试运行导致失败的命令。

通过ssh登录然后: su - deploy $ cd /srv/www/mynextapp/releases/20150401052640 $ /usr/local/bin/bundle exec /usr/local/bin/rake db:migrate

现在这个命令应该失败,告诉我们原因。

@ n1t1nv3rma收到此错误:

ExecJS::RuntimeUnavailable: Could not find a JavaScript runtime

他修好了in this way.

对我来说错误是: /usr/lib/postgresql/9.5/bin/pg_dump: invalid option -- 'i' Try "pg_dump --help" for more information. rake aborted! Error dumping database

我修复了它只是更新到Rails 4.2.6 (之前是4.2.3 - 有一个删除-i选项的提交)。

点击此处了解更多详情:https://github.com/aws/opsworks-cookbooks/issues/258

希望它有所帮助。