【发布时间】:2017-03-16 07:54:59
【问题描述】:
我目前正在关注 DigitalOcean 页面上有关如何使用 capistrano 部署到生产环境的教程。我已经到了尝试运行迁移的步骤,但它却报错了:
SSHKit::Runner::ExecuteError: Exception while executing on host 104.236.51.1: rake exit status: 1
rake stdout: rake aborted!
Mysql2::Error: Access denied for user 'foo'@'localhost' (using password: NO)
查看日志,我可以看到它尝试执行的命令,如下所示:
/home/foo/apps/programming_class_judge/releases/20161102041809 && ( export RAILS_ENV="production" ; ~/.rvm/bin/rvm default do bundle exec rake db:migrate )
如果我 ssh 进入机器并运行这个命令,它就可以工作。我不明白为什么在使用 capistrano 部署时不使用密码。
以下是我的 db.yaml 文件的 prod 设置(JUDGE_PRODUCTION_DB_PASSWORD 环境变量在我的本地和远程计算机中):
default: &default
adapter: mysql2
encoding: utf8
pool: 5
username: root
password: <= ENV['JUDGE_DB_PASSWORD'] %>
socket: /tmp/mysql.sock
production:
<<: *default
database: judge_production
username: foo
password: <%= ENV['JUDGE_PRODUCTION_DB_PASSWORD'] %>
socket: /var/run/mysqld/mysqld.sock
我的 config/deploy.rb 脚本基本上是本教程中的内容的复制粘贴,将文本替换为红色:https://www.digitalocean.com/community/tutorials/deploying-a-rails-app-on-ubuntu-14-04-with-capistrano-nginx-and-puma
有人知道为什么当我执行cap production deploy:initial 时迁移可能会失败,但当我手动尝试时却没有?
感谢任何帮助。
【问题讨论】:
标签: ruby-on-rails nginx capistrano digital-ocean puma