0

A cronjob generated on a Ubuntu 20 server by the whenever gem is failing, as the log registers:

PG::ConnectionBad: FATAL:  Peer authentication failed for user "*name_of_application*"

The database.yml file defines

default: &default
  adapter: postgresql
  encoding: unicode
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>

development:
  <<: *default

The application handles all migrations, records creations, updates, etc. as expected, so the connection with PG is proper. However, it seems the whenever gem wants to connect as user name_of_application

Following the documentation and inline help, I ran

bundle exec whenever --user *name_of_linux_user*

to no avail.

The schedule.rb is as follows:

env :PATH, ENV['PATH']
 
job_type :rbenv_rake, %Q{export PATH=/home/deploy/.rbenv/shims:/home/deploy/.rbenv/bin:/usr/bin:$PATH; eval "$(rbenv init -)"; \
                         cd :path && :environment_variable=:environment :bundle_command rake :task --silent :output }

job_type :rbenv_runner, %Q{export PATH=/home/deploy/.rbenv/shims:/home/deploy/.rbenv/bin:/usr/bin:$PATH; eval "$(rbenv init -)"; \
                         cd :path && :bundle_command :runner_command -e :environment ':task' :output }


  every 1.day, :at => '00:22 am' do
    rake "cleanup:promos", :output => "log/sweep_log.log"
  end

Why is wheneverdefaulting to the application's name and how should this be corrected?

Jerome
  • 5,583
  • 3
  • 33
  • 76
  • Does this answer your question? [Getting error: Peer authentication failed for user "postgres", when trying to get pgsql working with rails](https://stackoverflow.com/questions/18664074/getting-error-peer-authentication-failed-for-user-postgres-when-trying-to-ge) – Smek Oct 15 '21 at 07:54
  • I have attempted that; I restarted postgresql `sudo service postgreql restart` yet the log returns the same error. – Jerome Oct 15 '21 at 09:17

1 Answers1

0

whenever gem presumes the application is running in production mode, thus renders to crontab

cd /home/deploy/app_name/releases/20211025093952  && RAILS_ENV=production

That database had not been created, thus leading to the user connection error.

 && RAILS_ENV=development

solved this use case.

Jerome
  • 5,583
  • 3
  • 33
  • 76