【问题标题】:Deploying rails app to DigitalOcean using capistrano, nginx, puma使用 capistrano、nginx、puma 将 rails 应用程序部署到 DigitalOcean
【发布时间】: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


    【解决方案1】:

    在 /etc/environment.xml 中添加您的环境变量。添加到 .bashrc、.bashprofile、.profile 将它们添加为 shell 变量而不是环境,并且 capistrano 并没有真正创建新的 shell。

    还有一个 set :default_env, { 'var' => 'val' } 选项用于 capistrano。

    有关更多信息,请参阅此答案:Capistrano and environment variables

    【讨论】:

      猜你喜欢
      • 2017-08-23
      • 1970-01-01
      • 2018-01-30
      • 2020-04-22
      • 1970-01-01
      • 2013-09-29
      • 2016-07-22
      • 2019-04-27
      • 2016-08-25
      相关资源
      最近更新 更多