【问题标题】:Rails Whenever gem cron fe_sendauth: no password suppliedRails 每当 gem cron fe_sendauth:没有提供密码
【发布时间】:2016-01-16 01:26:21
【问题描述】:

我正在运行一个 Rails 服务器,它定期运行 rake task,无论何时使用 gem 和 cron。

我可以使用这些成功运行rake task。在我的远程服务器上,我以 root 身份运行它。第二次尝试也有效。

     RAILS_ENV=production rake fetch_myitems
     // attempt 1
     //attempt 2
     /bin/bash -l -c 'cd /home/rails/AniKawaii && RAILS_ENV=production bundle exec rake fetch_animegifs --silent >> log/whenever.log 2>&1'

调试后,这就是我最终发现的错误来源。我知道这与 database.yml 有关。但是我可以成功部署到我的实时生产服务器并且调用RAILS_ENV=production rake fetch_myitems 不会触发此错误,所以我不知道该怎么做。

PG::ConnectionBad: fe_sendauth: no password supplied

crontab -l

0,5,10,15,20,25,30,35,40,45,50,55 * * * * /bin/bash -l -c 'cd /home/rails/AniKawaii && RAILS_ENV=production bundle exec rake fetch_animegifs --silent >> log/whenever.log 2>&1'

【问题讨论】:

    标签: ruby-on-rails ruby cron whenever


    【解决方案1】:

    由于某种原因,/etc/default/unicorn file 中的 APP_DATABASE_PASSWORD 没有得到更新,即使我重新加载 nginx 和 unicorn。

    我的解决方法是手动覆盖 database.yml 中的密码。

    【讨论】:

      【解决方案2】:

      我的猜测是您的 database.yml 文件看起来像:

      production:
        adapter: postgresql
        encoding: unicode
        database: test-postgres_production
        pool: 5
        username: rails
        password: <%= ENV['PGPASS'] %>
      

      表示密码是从环境变量中获取的。您的 cronjob 应该类似于:

      0,5,10,15,20,25,30,35,40,45,50,55 * * * * /bin/bash -l -c 'cd /home/rails/AniKawaii && RAILS_ENV=production PGPASS=your_database_password_here bundle exec rake fetch_animegifs --silent >> log/whenever.log 2>&1'
      

      希望对你有所帮助。

      【讨论】:

      • 即使这样可行,在 cron 中通过 pass 是否安全?
      • cron 仍然比将它放在存储库中更安全
      猜你喜欢
      • 2019-04-25
      • 1970-01-01
      • 2016-10-15
      • 1970-01-01
      • 1970-01-01
      • 2014-05-07
      • 2013-08-02
      • 2016-05-19
      • 1970-01-01
      相关资源
      最近更新 更多