I'm attempting to get a vagrant environment up to run a Rails application that connects to a remote Postgres database hosted on Heroku. Running the app from my host machine (Mac OS X) works just fine, but fails on a fresh Ubuntu installation in my vagrant box, even though they're pointed to the same source directory. Here's what I get when attempting to start the web server:
00:02:22 web.1 | Connecting to database specified by database.yml
00:02:22 web.1 | /opt/ruby/lib/ruby/gems/2.0.0/gems/activerecord-3.2.13/lib/active_record/connection_adapters/postgresql_adapter.rb:1216:in `initialize': FATAL: no pg_hba.conf entry for host "207.172.212.123", user "user", database "database", SSL off (PG::ConnectionBad)
00:02:22 web.1 | from /opt/ruby/lib/ruby/gems/2.0.0/gems/activerecord-3.2.13/lib/active_record/connection_adapters/postgresql_adapter.rb:1216:in `new'
00:02:22 web.1 | from /opt/ruby/lib/ruby/gems/2.0.0/gems/activerecord-3.2.13/lib/active_record/connection_adapters/postgresql_adapter.rb:1216:in `connect'
00:02:22 web.1 | from /opt/ruby/lib/ruby/gems/2.0.0/gems/activerecord-3.2.13/lib/active_record/connection_adapters/postgresql_adapter.rb:324:in `initialize'
00:02:22 web.1 | from /opt/ruby/lib/ruby/gems/2.0.0/gems/activerecord-3.2.13/lib/active_record/connection_adapters/postgresql_adapter.rb:28:in `new'
00:02:22 web.1 | from /opt/ruby/lib/ruby/gems/2.0.0/gems/activerecord-3.2.13/lib/active_record/connection_adapters/postgresql_adapter.rb:28:in `postgresql_connection'
00:02:22 web.1 | from /opt/ruby/lib/ruby/gems/2.0.0/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:315:in `new_connection'
00:02:22 web.1 | from /opt/ruby/lib/ruby/gems/2.0.0/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:325:in `checkout_new_connection'
00:02:22 web.1 | from /opt/ruby/lib/ruby/gems/2.0.0/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:247:in `block (2 levels) in checkout'
00:02:22 web.1 | from /opt/ruby/lib/ruby/gems/2.0.0/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:242:in `loop'
00:02:22 web.1 | from /opt/ruby/lib/ruby/gems/2.0.0/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:242:in `block in checkout'
00:02:22 web.1 | from /opt/ruby/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
00:02:22 web.1 | from /opt/ruby/lib/ruby/gems/2.0.0/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:239:in `checkout'
00:02:22 web.1 | from /opt/ruby/lib/ruby/gems/2.0.0/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:102:in `block in connection'
00:02:22 web.1 | from /opt/ruby/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
00:02:22 web.1 | from /opt/ruby/lib/ruby/gems/2.0.0/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:101:in `connection'
00:02:22 web.1 | from /opt/ruby/lib/ruby/gems/2.0.0/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:410:in `retrieve_connection'
00:02:22 web.1 | from /opt/ruby/lib/ruby/gems/2.0.0/gems/composite_primary_keys-5.0.13/lib/composite_primary_keys/connection_adapters/abstract/connection_specification_changes.rb:47:in `retrieve_connection'
00:02:22 web.1 | from /opt/ruby/lib/ruby/gems/2.0.0/gems/composite_primary_keys-5.0.13/lib/composite_primary_keys/connection_adapters/abstract/connection_specification_changes.rb:29:in `connection'
00:02:22 web.1 | from /opt/ruby/lib/ruby/gems/2.0.0/gems/activerecord-3.2.13/lib/active_record/railtie.rb:88:in `block in <class:Railtie>'
00:02:22 web.1 | from /opt/ruby/lib/ruby/gems/2.0.0/gems/railties-3.2.13/lib/rails/initializable.rb:30:in `instance_exec'
00:02:22 web.1 | from /opt/ruby/lib/ruby/gems/2.0.0/gems/railties-3.2.13/lib/rails/initializable.rb:30:in `run'
00:02:22 web.1 | from /opt/ruby/lib/ruby/gems/2.0.0/gems/railties-3.2.13/lib/rails/initializable.rb:55:in `block in run_initializers'
00:02:22 web.1 | from /opt/ruby/lib/ruby/gems/2.0.0/gems/railties-3.2.13/lib/rails/initializable.rb:54:in `each'
00:02:22 web.1 | from /opt/ruby/lib/ruby/gems/2.0.0/gems/railties-3.2.13/lib/rails/initializable.rb:54:in `run_initializers'
00:02:22 web.1 | from /opt/ruby/lib/ruby/gems/2.0.0/gems/railties-3.2.13/lib/rails/application.rb:136:in `initialize!'
00:02:22 web.1 | from /opt/ruby/lib/ruby/gems/2.0.0/gems/railties-3.2.13/lib/rails/railtie/configurable.rb:30:in `method_missing'
00:02:22 web.1 | from /vagrant/config/environment.rb:5:in `<top (required)>'
00:02:22 web.1 | from /opt/ruby/lib/ruby/gems/2.0.0/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `require'
00:02:22 web.1 | from /opt/ruby/lib/ruby/gems/2.0.0/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `block in require'
00:02:22 web.1 | from /opt/ruby/lib/ruby/gems/2.0.0/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:236:in `load_dependency'
00:02:22 web.1 | from /opt/ruby/lib/ruby/gems/2.0.0/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `require'
00:02:22 web.1 | from config.ru:4:in `block in <main>'
00:02:22 web.1 | from /opt/ruby/lib/ruby/gems/2.0.0/gems/rack-1.4.5/lib/rack/builder.rb:51:in `instance_eval'
00:02:22 web.1 | from /opt/ruby/lib/ruby/gems/2.0.0/gems/rack-1.4.5/lib/rack/builder.rb:51:in `initialize'
00:02:22 web.1 | from config.ru:1:in `new'
00:02:22 web.1 | from config.ru:1:in `<main>'
00:02:22 web.1 | from /opt/ruby/lib/ruby/gems/2.0.0/gems/unicorn-4.6.3/lib/unicorn.rb:48:in `eval'
00:02:22 web.1 | from /opt/ruby/lib/ruby/gems/2.0.0/gems/unicorn-4.6.3/lib/unicorn.rb:48:in `block in builder'
00:02:22 web.1 | from /opt/ruby/lib/ruby/gems/2.0.0/gems/unicorn-4.6.3/lib/unicorn/http_server.rb:722:in `call'
00:02:22 web.1 | from /opt/ruby/lib/ruby/gems/2.0.0/gems/unicorn-4.6.3/lib/unicorn/http_server.rb:722:in `build_app!'
00:02:22 web.1 | from /opt/ruby/lib/ruby/gems/2.0.0/gems/unicorn-4.6.3/lib/unicorn/http_server.rb:140:in `start'
00:02:22 web.1 | from /opt/ruby/lib/ruby/gems/2.0.0/gems/unicorn-4.6.3/bin/unicorn:126:in `<top (required)>'
00:02:22 web.1 | from /opt/ruby/bin/unicorn:23:in `load'
00:02:22 web.1 | from /opt/ruby/bin/unicorn:23:in `<main>'
00:02:22 web.1 | exited with code 1
I think the issue has to do with the pg gem not successfully establishing an SSL connection with Postgres. Is there something special that needs to be configured on the Ubuntu server to make the SSL connection happen?
Here is the database.yml:
adapter: postgresql
encoding: unicode
pool: 5
database: database
username: user
password: password
host: xxx-xxx-xxx-xxx.compute-1.amazonaws.com
port: 5432
This config works from my Mac, but not the Ubuntu VM. I've also tried adding sslmode: require, which also didn't help.
The key error portion is:
FATAL: no pg_hba.conf entry for host "207.172.212.123", user "user", database "database", SSL off
This tells you that you're not attempting to make an SSL connection. You'll want to explicitly tell libpq (which is what the Pg gem, and hence Rails, uses to connect to PostgreSQL) that you require an SSL connection, by finding a way to pass the sslmode parameter through to libpq with value require.
This question suggests that the Pg gem was modified to autonegotiate SSL. So at a guess, the version on your Mac is newer than the version on your Ubuntu box. For older versions it looks like there may not be a simple way to specify that SSL is required, but the JDBC URL format for the connection string with ssl=true may be used to work around the lack, per the first answer on that article, but that's a bit ugly.
Your comments suggest that your Pg gem doesn't understand sslmode as an option in database.yml, silently ignoring it.
In that case, I'd try using a connstring:
adapter: postgresql
database: "dbname=database host=207.172.212.123 user=user sslmode=require"
...
In general you can supply a connstring anywhere you can put a database name with libpq. You should leave out the user, host, etc keys in your database.yml if you do this. I haven't tested it with Rails, but this approach works with most things.
Or you could update your Pg gem to one that supports SSL properly. It looks like the current version should support sslmode as a connection option.
UPDATE:
It turns out that SSL was not supported by the libpq on the Ubuntu box.
Related
I updated my Ruby version to 3.1.3, but I was keep getting the following error and could not fix it, so I downgraded Ruby version back to 3.1.2.
However, I am keep getting the same error and I tried reinstalling all the gems and updating all the gems, but still getting the error. I would really appreciate if someone can help me out because I could not figure this out for very long time. I don't think I need to install JRuby separately or something because it used to work fine.
Thanks in advance!
20:23:24 web.1 | C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:17:in `require': cannot load such file -- jruby (LoadError)
20:23:24 web.1 | from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:17:in `require'
20:23:24 web.1 | from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/jruby-openssl-0.9.4/lib/jopenssl/load.rb:13:in `<main>'
20:23:24 web.1 | from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
20:23:24 web.1 | from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
20:23:24 web.1 | from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/jruby-openssl-0.9.4/lib/openssl.rb:1:in `<main>'
20:23:24 web.1 | from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
20:23:24 web.1 | from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
20:23:24 web.1 | from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/activesupport-7.0.4/lib/active_support/key_generator.rb:4:in `<main>'
20:23:24 web.1 | from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
20:23:24 web.1 | from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
20:23:24 web.1 | from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.4/lib/rails/application.rb:6:in `<main>'
20:23:24 web.1 | from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
20:23:24 web.1 | from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
20:23:24 web.1 | from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.4/lib/rails.rb:13:in `<main>'
20:23:24 web.1 | from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
20:23:24 web.1 | from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
20:23:25 web.1 | from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.4/lib/rails/commands/server/server_command.rb:5:in `<main>'
20:23:25 web.1 | from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
20:23:25 web.1 | from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
20:23:25 web.1 | from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.4/lib/rails/command/behavior.rb:44:in `block (2 levels) in lookup'
20:23:25 web.1 | from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.4/lib/rails/command/behavior.rb:40:in `each'
20:23:25 web.1 | from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.4/lib/rails/command/behavior.rb:40:in `block in lookup'
20:23:25 web.1 | from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.4/lib/rails/command/behavior.rb:39:in `each'
20:23:25 web.1 | from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.4/lib/rails/command/behavior.rb:39:in `lookup'
20:23:25 web.1 | from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.4/lib/rails/command.rb:73:in `find_by_namespace'
20:23:25 web.1 | from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.4/lib/rails/command.rb:46:in `invoke'
20:23:25 web.1 | from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.4/lib/rails/commands.rb:18:in `<main>'
20:23:25 web.1 | from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_requ from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/foreman-0.87.2/lib/foreman/vendor/thor/lib/thor/base.rb:444:in `start'
from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/foreman-0.87.2/bin/foreman:7:in `<top (required)>' from C:/Ruby31-x64/bin/foreman:32:in `load'
from C:/Ruby31-x64/bin/foreman:32:in `<main>'
It seems like one of the gems was causing the problem. I rolled back everything to before state and the server is working again.
The gem was gem 'google-auth'
I implemented action cable in our rails backend and angularjs frontend using angular-actioncable, it is all working as expected, client to server websocket connection is established and broadcasts and receives are working but when I start the app, it always throws a rack lint error and a 500 error on GET /cable,
09:33:10 web.1 | Rack::Lint::LintError: Status must be >=100 seen as integer
09:33:10 web.1 | /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rack-2.2.3/lib/rack/lint.rb:25:in `assert'
09:33:10 web.1 | /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rack-2.2.3/lib/rack/lint.rb:675:in `check_status'
09:33:10 web.1 | /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rack-2.2.3/lib/rack/lint.rb:70:in `_call'
09:33:10 web.1 | /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rack-2.2.3/lib/rack/lint.rb:42:in `call'
09:33:10 web.1 | /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rack-2.2.3/lib/rack/show_exceptions.rb:23:in `call'
09:33:10 web.1 | /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rack-2.2.3/lib/rack/common_logger.rb:38:in `call'
09:33:10 web.1 | /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/sinatra-2.1.0/lib/sinatra/base.rb:253:in `call'
09:33:10 web.1 | /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rack-2.2.3/lib/rack/chunked.rb:98:in `call'
09:33:10 web.1 | /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rack-2.2.3/lib/rack/content_length.rb:17:in `call'
09:33:10 web.1 | /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/unicorn-5.7.0/lib/unicorn/http_server.rb:632:in `process_client'
09:33:10 web.1 | /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/unicorn-5.7.0/lib/unicorn/http_server.rb:728:in `worker_loop'
09:33:10 web.1 | /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/unicorn-5.7.0/lib/unicorn/http_server.rb:548:in `spawn_missing_workers'
09:33:10 web.1 | /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/unicorn-5.7.0/lib/unicorn/http_server.rb:144:in `start'
09:33:10 web.1 | /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/unicorn-5.7.0/bin/unicorn:128:in `<top (required)>'
09:33:10 web.1 | /home/leonidas/.asdf/installs/ruby/2.7.3/bin/unicorn:23:in `load'
09:33:10 web.1 | /home/leonidas/.asdf/installs/ruby/2.7.3/bin/unicorn:23:in `<top (required)>'
09:33:10 web.1 | /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/2.7.0/bundler/cli/exec.rb:63:in `load'
09:33:10 web.1 | /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/2.7.0/bundler/cli/exec.rb:63:in `kernel_load'
09:33:10 web.1 | /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/2.7.0/bundler/cli/exec.rb:28:in `run'
09:33:10 web.1 | /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/2.7.0/bundler/cli.rb:476:in `exec'
09:33:10 web.1 | /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/2.7.0/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
09:33:10 web.1 | /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/2.7.0/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
09:33:10 web.1 | /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/2.7.0/bundler/vendor/thor/lib/thor.rb:399:in `dispatch'
09:33:10 web.1 | /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/2.7.0/bundler/cli.rb:30:in `dispatch'
09:33:10 web.1 | /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/2.7.0/bundler/vendor/thor/lib/thor/base.rb:476:in `start'
09:33:10 web.1 | /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/2.7.0/bundler/cli.rb:24:in `start'
09:33:10 web.1 | /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/libexec/bundle:46:in `block in <top (required)>'
09:33:10 web.1 | /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/2.7.0/bundler/friendly_errors.rb:123:in `with_friendly_errors'
09:33:10 web.1 | /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/libexec/bundle:34:in `<top (required)>'
09:33:10 web.1 | /home/leonidas/.asdf/installs/ruby/2.7.3/bin/bundle:23:in `load'
09:33:10 web.1 | /home/leonidas/.asdf/installs/ruby/2.7.3/bin/bundle:23:in `<main>'
09:33:10 web.1 | 127.0.0.1 - - [11/Feb/2022:09:33:10 +1100] "GET /cable/ HTTP/1.1" 500 3356 0.4378
I put prints in the rack gem and it returns a status of -1, can't find any docs on what -1 means.
Thanks
For anyone else having the same issue, the reason was Rack does socket highjacking while upgrading the http protocol to websockets and returns a -1 which the rack lint doesn't see as a valid http satus, in development you can set RACK_ENV=deployment RAILS_ENV=development to test and you can stub the headers/status check for action cable with a simple initializer, more details here, initializer from the link above,
class ::Rack::Lint
alias check_status_orig check_status
alias check_headers_orig check_headers
alias check_content_type_orig check_content_type
alias check_content_length_orig check_content_length
alias check_hijack_orig check_hijack
alias _call_orig _call
def _call(env)
#web_socket = env['REQUEST_PATH'] == '/cable'
_call_orig(env)
end
def check_status(status)
return if #web_socket
check_status_orig(status)
end
def check_headers(headers)
return if #web_socket
check_headers_orig(headers)
end
def check_content_type(status, headers)
return if #web_socket
check_content_type_orig(status, headers)
end
def check_content_length(status, headers)
return if #web_socket
check_content_type_orig(status, headers)
end
def check_hijack(env)
# Don't know why, but HijackWrapper break WebSocket!
return if #web_socket
check_hijack_orig(env)
end
end
I'm attempting to send exceptions to a slack channel. This was my set up:
Added the following to my Gemfile
gem 'exception_notification'
gem 'slack-notifier'
Created a new initializer config/initializers/errors.rb
# Works in development with or without this require
require 'exception_notification'
Rails.application.config.middleware.use(
ExceptionNotification::Rack,
:slack => {
:webhook_url => ENV["SLACK_ERROR_WEBHOOOK_URL"]
}
)
I have rebuilt my docker images and deleted the gem cache volumes.
This works properly in my development environment (errors get sent to slack), but isn't working on my production server. The only real difference that I can think of between the two is the RAILS_ENV value, at least configuration-wise. I'm fairly new to Rails however, as well as deploying to a production environment.
Immediately upon starting the app (docker-compose up) it exits with the following error:
/usr/local/bundle/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:34:in `require': cannot load such file -- exception_notification (LoadError)
app_1 | from /usr/local/bundle/gems/zeitwerk-2.3.0/lib/zeitwerk/kernel.rb:23:in `require'
app_1 | from /usr/local/bundle/gems/activesupport-6.0.2.1/lib/active_support/dependencies.rb:325:in `block in require'
app_1 | from /usr/local/bundle/gems/activesupport-6.0.2.1/lib/active_support/dependencies.rb:291:in `load_dependency'
app_1 | from /usr/local/bundle/gems/activesupport-6.0.2.1/lib/active_support/dependencies.rb:325:in `require'
app_1 | from /app/config/initializers/errors.rb:1:in `<main>'
app_1 | from /usr/local/bundle/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:55:in `load'
app_1 | from /usr/local/bundle/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:55:in `load'
app_1 | from /usr/local/bundle/gems/activesupport-6.0.2.1/lib/active_support/dependencies.rb:319:in `block in load'
app_1 | from /usr/local/bundle/gems/activesupport-6.0.2.1/lib/active_support/dependencies.rb:291:in `load_dependency'
app_1 | from /usr/local/bundle/gems/activesupport-6.0.2.1/lib/active_support/dependencies.rb:319:in `load'
app_1 | from /usr/local/bundle/gems/railties-6.0.2.1/lib/rails/engine.rb:667:in `block in load_config_initializer'
app_1 | from /usr/local/bundle/gems/activesupport-6.0.2.1/lib/active_support/notifications.rb:182:in `instrument'
app_1 | from /usr/local/bundle/gems/railties-6.0.2.1/lib/rails/engine.rb:666:in `load_config_initializer'
app_1 | from /usr/local/bundle/gems/railties-6.0.2.1/lib/rails/engine.rb:624:in `block (2 levels) in <class:Engine>'
app_1 | from /usr/local/bundle/gems/railties-6.0.2.1/lib/rails/engine.rb:623:in `each'
app_1 | from /usr/local/bundle/gems/railties-6.0.2.1/lib/rails/engine.rb:623:in `block in <class:Engine>'
app_1 | from /usr/local/bundle/gems/railties-6.0.2.1/lib/rails/initializable.rb:32:in `instance_exec'
app_1 | from /usr/local/bundle/gems/railties-6.0.2.1/lib/rails/initializable.rb:32:in `run'
app_1 | from /usr/local/bundle/gems/railties-6.0.2.1/lib/rails/initializable.rb:61:in `block in run_initializers'
app_1 | from /usr/local/lib/ruby/2.6.0/tsort.rb:228:in `block in tsort_each'
app_1 | from /usr/local/lib/ruby/2.6.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
app_1 | from /usr/local/lib/ruby/2.6.0/tsort.rb:422:in `block (2 levels) in each_strongly_connected_component_from'
app_1 | from /usr/local/lib/ruby/2.6.0/tsort.rb:431:in `each_strongly_connected_component_from'
app_1 | from /usr/local/lib/ruby/2.6.0/tsort.rb:421:in `block in each_strongly_connected_component_from'
app_1 | from /usr/local/bundle/gems/railties-6.0.2.1/lib/rails/initializable.rb:50:in `each'
app_1 | from /usr/local/bundle/gems/railties-6.0.2.1/lib/rails/initializable.rb:50:in `tsort_each_child'
app_1 | from /usr/local/lib/ruby/2.6.0/tsort.rb:415:in `call'
app_1 | from /usr/local/lib/ruby/2.6.0/tsort.rb:415:in `each_strongly_connected_component_from'
app_1 | from /usr/local/lib/ruby/2.6.0/tsort.rb:349:in `block in each_strongly_connected_component'
app_1 | from /usr/local/lib/ruby/2.6.0/tsort.rb:347:in `each'
app_1 | from /usr/local/lib/ruby/2.6.0/tsort.rb:347:in `call'
app_1 | from /usr/local/lib/ruby/2.6.0/tsort.rb:347:in `each_strongly_connected_component'
app_1 | from /usr/local/lib/ruby/2.6.0/tsort.rb:226:in `tsort_each'
app_1 | from /usr/local/lib/ruby/2.6.0/tsort.rb:205:in `tsort_each'
app_1 | from /usr/local/bundle/gems/railties-6.0.2.1/lib/rails/initializable.rb:60:in `run_initializers'
app_1 | from /usr/local/bundle/gems/railties-6.0.2.1/lib/rails/application.rb:363:in `initialize!'
app_1 | from /app/config/environment.rb:5:in `<main>'
app_1 | from /usr/local/bundle/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
app_1 | from /usr/local/bundle/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
app_1 | from /usr/local/bundle/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
app_1 | from /usr/local/bundle/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
app_1 | from /usr/local/bundle/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
app_1 | from /usr/local/bundle/gems/zeitwerk-2.3.0/lib/zeitwerk/kernel.rb:23:in `require'
app_1 | from /usr/local/bundle/gems/activesupport-6.0.2.1/lib/active_support/dependencies.rb:325:in `block in require'
app_1 | from /usr/local/bundle/gems/activesupport-6.0.2.1/lib/active_support/dependencies.rb:291:in `load_dependency'
app_1 | from /usr/local/bundle/gems/activesupport-6.0.2.1/lib/active_support/dependencies.rb:325:in `require'
app_1 | from /usr/local/bundle/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:49:in `require_relative'
app_1 | from config.ru:3:in `block in <main>'
app_1 | from /usr/local/bundle/gems/rack-2.2.2/lib/rack/builder.rb:116:in `eval'
app_1 | from /usr/local/bundle/gems/rack-2.2.2/lib/rack/builder.rb:116:in `new_from_string'
app_1 | from /usr/local/bundle/gems/rack-2.2.2/lib/rack/builder.rb:105:in `load_file'
app_1 | from /usr/local/bundle/gems/rack-2.2.2/lib/rack/builder.rb:66:in `parse_file'
app_1 | from /usr/local/bundle/gems/rack-2.2.2/lib/rack/server.rb:349:in `build_app_and_options_from_config'
app_1 | from /usr/local/bundle/gems/rack-2.2.2/lib/rack/server.rb:249:in `app'
app_1 | from /usr/local/bundle/gems/rack-2.2.2/lib/rack/server.rb:422:in `wrapped_app'
app_1 | from /usr/local/bundle/gems/rack-2.2.2/lib/rack/server.rb:312:in `block in start'
app_1 | from /usr/local/bundle/gems/rack-2.2.2/lib/rack/server.rb:379:in `handle_profiling'
app_1 | from /usr/local/bundle/gems/rack-2.2.2/lib/rack/server.rb:311:in `start'
app_1 | from /usr/local/bundle/gems/railties-6.0.2.1/lib/rails/commands/server/server_command.rb:39:in `start'
app_1 | from /usr/local/bundle/gems/railties-6.0.2.1/lib/rails/commands/server/server_command.rb:147:in `block in perform'
app_1 | from /usr/local/bundle/gems/railties-6.0.2.1/lib/rails/commands/server/server_command.rb:138:in `tap'
app_1 | from /usr/local/bundle/gems/railties-6.0.2.1/lib/rails/commands/server/server_command.rb:138:in `perform'
app_1 | from /usr/local/bundle/gems/thor-1.0.1/lib/thor/command.rb:27:in `run'
app_1 | from /usr/local/bundle/gems/thor-1.0.1/lib/thor/invocation.rb:127:in `invoke_command'
app_1 | from /usr/local/bundle/gems/thor-1.0.1/lib/thor.rb:392:in `dispatch'
app_1 | from /usr/local/bundle/gems/railties-6.0.2.1/lib/rails/command/base.rb:69:in `perform'
app_1 | from /usr/local/bundle/gems/railties-6.0.2.1/lib/rails/command.rb:46:in `invoke'
app_1 | from /usr/local/bundle/gems/railties-6.0.2.1/lib/rails/commands.rb:18:in `<main>'
app_1 | from /usr/local/bundle/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
app_1 | from /usr/local/bundle/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
app_1 | from /usr/local/bundle/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
app_1 | from /usr/local/bundle/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
app_1 | from /usr/local/bundle/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
app_1 | from /usr/local/bundle/gems/activesupport-6.0.2.1/lib/active_support/dependencies.rb:325:in `block in require'
app_1 | from /usr/local/bundle/gems/activesupport-6.0.2.1/lib/active_support/dependencies.rb:291:in `load_dependency'
app_1 | from /usr/local/bundle/gems/activesupport-6.0.2.1/lib/active_support/dependencies.rb:325:in `require'
app_1 | from bin/rails:4:in `<main>'
I've verified that the gem exception_notification is indeed installed by running docker exec -it <container-name> gem list, which includes exception_notification (4.4.3) in the output, and also running docker exec -it <container-name> gem which exception_notification which gives /usr/local/bundle/gems/exception_notification-4.4.3/lib/exception_notification.rb
Running Ruby on Rails v6.0.2 and Ruby v2.6.3
I had some similar problems when using Rails and Docker. Bootsnap cache may be stale.
Try removing the cache
rm tmp/cache/bootsnap-load-path-cache
You might also try restarting Spring
spring stop
It should restart automatically.
Try require 'exception_notification/rails'
I have a few jobs that query some external APIs. I have two types of jobs.
One job to gather a large amount of data.
And another to keep the data updated every fifteen minutes.
I would like the bulk job to fire one time on deployment to collect that bulk data, then lay dormant while the update job executes on set intervals to keep the data topped off.
How does one set a job to fire one time on deployment?
Edit:
This is what I've tried so far.
With a rake task
# application.rb
config.after_initialize do
Rails.application.load_tasks # Load our Event collection task.
Rake::Task['initialize_event_collection:build_eventbrite'].invoke
Rake::Task['initialize_event_collection:build_meetup'].invoke
end
namespace :initialize_event_collection do
desc "This task fetches Meetup and Eventbrite events in bulk on startup."
task :build_eventbrite do
FetchEventbriteJob.perform_later
end
task :build_meetup do
FetchMeetupJob.perform_later
end
end
It looks like it starts but then it doesn't really go anywhere:
Redis and Puma stuff above...
sidekiq_1 | 2017-03-21T02:20:36.829Z 1 TID-gq6vufr4k INFO: Booting Sidekiq 4.2.3 with redis options {:url=>"redis://redis:6379/"}
sidekiq_1 | 2017-03-21T02:20:37.449Z 1 TID-gq6vufr4k INFO: Running in ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]
sidekiq_1 | 2017-03-21T02:20:37.449Z 1 TID-gq6vufr4k INFO: See LICENSE and the LGPL-3.0 for licensing details.
sidekiq_1 | 2017-03-21T02:20:37.450Z 1 TID-gq6vufr4k INFO: Upgrade to Sidekiq Pro for more features and support: http://sidekiq.org
sidekiq_1 | 2017-03-21T02:20:37.456Z 1 TID-gq6vufr4k INFO: Loading Schedule
sidekiq_1 | 2017-03-21T02:20:37.456Z 1 TID-gq6vufr4k INFO: Schedule empty! Set Sidekiq.schedule
sidekiq_1 | 2017-03-21T02:20:37.457Z 1 TID-gq6vufr4k INFO: Schedules Loaded
sidekiq_1 | 2017-03-21T02:20:37.463Z 1 TID-gq6vufr4k INFO: Reloading Schedule
sidekiq_1 | 2017-03-21T02:20:37.464Z 1 TID-gq6vufr4k INFO: Loading Schedule
sidekiq_1 | 2017-03-21T02:20:37.464Z 1 TID-gq6vufr4k INFO: Scheduling UpdateEventbriteJob {"cron"=>"*/15 * * * *", "class"=>"UpdateEventbriteJob"}
sidekiq_1 | 2017-03-21T02:20:37.969Z 1 TID-gq6vufr4k INFO: Scheduling UpdateMeetupJob {"cron"=>"*/15 * * * *", "class"=>"UpdateMeetupJob"}
sidekiq_1 | 2017-03-21T02:20:38.353Z 1 TID-gq6vufr4k INFO: Scheduling UpdateStatusJob {"cron"=>"0 0 * * *", "class"=>"UpdateStatusJob"}
sidekiq_1 | 2017-03-21T02:20:38.383Z 1 TID-gq6vufr4k INFO: Schedules Loaded
sidekiq_1 | 2017-03-21T02:20:38.383Z 1 TID-gq6vufr4k INFO: Starting processing, hit Ctrl-C to stop
sidekiq_1 | 2017-03-21T02:20:38.610Z 1 TID-gq6wf5uic FetchEventbriteJob JID-6803f9b93ce89e02ccb73d1d INFO: start
sidekiq_1 | 2017-03-21T02:20:38.623Z 1 TID-gq6wf5vp4 FetchEventbriteJob JID-79b83c0d2be3c647d8c8b52e INFO: start
sidekiq_1 | 2017-03-21T02:20:38.652Z 1 TID-gq6wf5v68 FetchMeetupJob JID-5c65f2262582a1e278b9986d INFO: start
sidekiq_1 | 2017-03-21T02:20:38.752Z 1 TID-gq6wf5tx8 FetchMeetupJob JID-cedc08eb695de6c14e371259 INFO: start
sidekiq_1 | 2017-03-21T02:20:38.854Z 1 TID-gq6wf5uqo FetchEventbriteJob JID-227879792a37d35bb6815a5d INFO: start
web_1 | Puma starting in single mode...
web_1 | * Version 3.6.0 (ruby 2.3.1-p112), codename: Sleepy Sunday Serenity
web_1 | * Min threads: 5, max threads: 5
web_1 | * Environment: development
web_1 | * Listening on tcp://0.0.0.0:3000
web_1 | Use Ctrl-C to stop
I've tried to call a method that calls the same job:
# application.rb
config.after_initialize do
Event.build_eventbrite
Event.build_meetup
end
# event.rb
def build_eventbrite
FetchEventbriteJob.perform_later
end
def build_meetup
FetchMeetupJob.perform_later
end
It looks like Rails doesn't like this approach
sidekiq_1 | 2017-03-21T02:29:23.858Z 1 TID-gqzwqq0wc INFO: Booting Sidekiq 4.2.3 with redis options {:url=>"redis://redis:6379/"}
sidekiq_1 | undefined method `build_eventbrite' for Event (call 'Event.connection' to establish a connection):Class
sidekiq_1 | /usr/local/bundle/gems/activerecord-5.0.0.1/lib/active_record/dynamic_matchers.rb:21:in `method_missing'
sidekiq_1 | /work_project/config/application.rb:29:in `block in <class:Application>'
sidekiq_1 | /usr/local/bundle/gems/activesupport-5.0.0.1/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
sidekiq_1 | /usr/local/bundle/gems/activesupport-5.0.0.1/lib/active_support/lazy_load_hooks.rb:45:in `block in run_load_hooks'
sidekiq_1 | /usr/local/bundle/gems/activesupport-5.0.0.1/lib/active_support/lazy_load_hooks.rb:44:in `each'
sidekiq_1 | /usr/local/bundle/gems/activesupport-5.0.0.1/lib/active_support/lazy_load_hooks.rb:44:in `run_load_hooks'
sidekiq_1 | /usr/local/bundle/gems/railties-5.0.0.1/lib/rails/application/finisher.rb:65:in `block in <module:Finisher>'
sidekiq_1 | /usr/local/bundle/gems/railties-5.0.0.1/lib/rails/initializable.rb:30:in `instance_exec'
sidekiq_1 | /usr/local/bundle/gems/railties-5.0.0.1/lib/rails/initializable.rb:30:in `run'
sidekiq_1 | /usr/local/bundle/gems/railties-5.0.0.1/lib/rails/initializable.rb:55:in `block in run_initializers'
sidekiq_1 | /usr/local/lib/ruby/2.3.0/tsort.rb:228:in `block in tsort_each'
sidekiq_1 | /usr/local/lib/ruby/2.3.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
sidekiq_1 | /usr/local/lib/ruby/2.3.0/tsort.rb:431:in `each_strongly_connected_component_from'
sidekiq_1 | /usr/local/lib/ruby/2.3.0/tsort.rb:349:in `block in each_strongly_connected_component'
sidekiq_1 | /usr/local/lib/ruby/2.3.0/tsort.rb:347:in `each'
sidekiq_1 | /usr/local/lib/ruby/2.3.0/tsort.rb:347:in `call'
sidekiq_1 | /usr/local/lib/ruby/2.3.0/tsort.rb:347:in `each_strongly_connected_component'
sidekiq_1 | /usr/local/lib/ruby/2.3.0/tsort.rb:226:in `tsort_each'
sidekiq_1 | /usr/local/lib/ruby/2.3.0/tsort.rb:205:in `tsort_each'
sidekiq_1 | /usr/local/bundle/gems/railties-5.0.0.1/lib/rails/initializable.rb:54:in `run_initializers'
sidekiq_1 | /usr/local/bundle/gems/railties-5.0.0.1/lib/rails/application.rb:352:in `initialize!'
sidekiq_1 | /work_project/config/environment.rb:5:in `<top (required)>'
sidekiq_1 | /usr/local/bundle/gems/sidekiq-4.2.3/lib/sidekiq/cli.rb:242:in `require'
sidekiq_1 | /usr/local/bundle/gems/sidekiq-4.2.3/lib/sidekiq/cli.rb:242:in `boot_system'
sidekiq_1 | /usr/local/bundle/gems/sidekiq-4.2.3/lib/sidekiq/cli.rb:50:in `run'
sidekiq_1 | /usr/local/bundle/gems/sidekiq-4.2.3/bin/sidekiq:12:in `<top (required)>'
sidekiq_1 | /usr/local/bundle/bin/sidekiq:17:in `load'
sidekiq_1 | /usr/local/bundle/bin/sidekiq:17:in `<top (required)>'
sidekiq_1 | /usr/local/bundle/gems/bundler-1.14.6/lib/bundler/cli/exec.rb:74:in `load'
sidekiq_1 | /usr/local/bundle/gems/bundler-1.14.6/lib/bundler/cli/exec.rb:74:in `kernel_load'
sidekiq_1 | /usr/local/bundle/gems/bundler-1.14.6/lib/bundler/cli/exec.rb:27:in `run'
sidekiq_1 | /usr/local/bundle/gems/bundler-1.14.6/lib/bundler/cli.rb:335:in `exec'
sidekiq_1 | /usr/local/bundle/gems/bundler-1.14.6/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
sidekiq_1 | /usr/local/bundle/gems/bundler-1.14.6/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
sidekiq_1 | /usr/local/bundle/gems/bundler-1.14.6/lib/bundler/vendor/thor/lib/thor.rb:359:in `dispatch'
sidekiq_1 | /usr/local/bundle/gems/bundler-1.14.6/lib/bundler/cli.rb:20:in `dispatch'
sidekiq_1 | /usr/local/bundle/gems/bundler-1.14.6/lib/bundler/vendor/thor/lib/thor/base.rb:440:in `start'
sidekiq_1 | /usr/local/bundle/gems/bundler-1.14.6/lib/bundler/cli.rb:11:in `start'
sidekiq_1 | /usr/local/bundle/gems/bundler-1.14.6/exe/bundle:32:in `block in <top (required)>'
sidekiq_1 | /usr/local/bundle/gems/bundler-1.14.6/lib/bundler/friendly_errors.rb:121:in `with_friendly_errors'
sidekiq_1 | /usr/local/bundle/gems/bundler-1.14.6/exe/bundle:24:in `<top (required)>'
sidekiq_1 | /usr/local/bundle/bin/bundle:22:in `load'
sidekiq_1 | /usr/local/bundle/bin/bundle:22:in `<main>'
work_project_sidekiq_1 exited with code 1
web_1 | Exiting
web_1 | /usr/local/bundle/gems/activerecord-5.0.0.1/lib/active_record/dynamic_matchers.rb:21:in `method_missing': undefined method `build_eventbrite' for Event (call 'Event.connection' to establish a connection):Class (NoMethodError)
web_1 | from /work_project/config/application.rb:29:in `block in <class:Application>'
web_1 | from /usr/local/bundle/gems/activesupport-5.0.0.1/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
web_1 | from /usr/local/bundle/gems/activesupport-5.0.0.1/lib/active_support/lazy_load_hooks.rb:45:in `block in run_load_hooks'
web_1 | from /usr/local/bundle/gems/activesupport-5.0.0.1/lib/active_support/lazy_load_hooks.rb:44:in `each'
web_1 | from /usr/local/bundle/gems/activesupport-5.0.0.1/lib/active_support/lazy_load_hooks.rb:44:in `run_load_hooks'
web_1 | from /usr/local/bundle/gems/railties-5.0.0.1/lib/rails/application/finisher.rb:65:in `block in <module:Finisher>'
web_1 | from /usr/local/bundle/gems/railties-5.0.0.1/lib/rails/initializable.rb:30:in `instance_exec'
web_1 | from /usr/local/bundle/gems/railties-5.0.0.1/lib/rails/initializable.rb:30:in `run'
web_1 | from /usr/local/bundle/gems/railties-5.0.0.1/lib/rails/initializable.rb:55:in `block in run_initializers'
web_1 | from /usr/local/lib/ruby/2.3.0/tsort.rb:228:in `block in tsort_each'
web_1 | from /usr/local/lib/ruby/2.3.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
web_1 | from /usr/local/lib/ruby/2.3.0/tsort.rb:431:in `each_strongly_connected_component_from'
web_1 | from /usr/local/lib/ruby/2.3.0/tsort.rb:349:in `block in each_strongly_connected_component'
web_1 | from /usr/local/lib/ruby/2.3.0/tsort.rb:347:in `each'
web_1 | from /usr/local/lib/ruby/2.3.0/tsort.rb:347:in `call'
web_1 | from /usr/local/lib/ruby/2.3.0/tsort.rb:347:in `each_strongly_connected_component'
web_1 | from /usr/local/lib/ruby/2.3.0/tsort.rb:226:in `tsort_each'
web_1 | from /usr/local/lib/ruby/2.3.0/tsort.rb:205:in `tsort_each'
web_1 | from /usr/local/bundle/gems/railties-5.0.0.1/lib/rails/initializable.rb:54:in `run_initializers'
web_1 | from /usr/local/bundle/gems/railties-5.0.0.1/lib/rails/application.rb:352:in `initialize!'
web_1 | from /work_project/config/environment.rb:5:in `<top (required)>'
web_1 | from /work_project/config.ru:3:in `require_relative'
web_1 | from /work_project/config.ru:3:in `block in <main>'
web_1 | from /usr/local/bundle/gems/rack-2.0.1/lib/rack/builder.rb:55:in `instance_eval'
web_1 | from /usr/local/bundle/gems/rack-2.0.1/lib/rack/builder.rb:55:in `initialize'
web_1 | from /work_project/config.ru:in `new'
web_1 | from /work_project/config.ru:in `<main>'
web_1 | from /usr/local/bundle/gems/rack-2.0.1/lib/rack/builder.rb:49:in `eval'
web_1 | from /usr/local/bundle/gems/rack-2.0.1/lib/rack/builder.rb:49:in `new_from_string'
web_1 | from /usr/local/bundle/gems/rack-2.0.1/lib/rack/builder.rb:40:in `parse_file'
web_1 | from /usr/local/bundle/gems/rack-2.0.1/lib/rack/server.rb:318:in `build_app_and_options_from_config'
web_1 | from /usr/local/bundle/gems/rack-2.0.1/lib/rack/server.rb:218:in `app'
web_1 | from /usr/local/bundle/gems/railties-5.0.0.1/lib/rails/commands/server.rb:59:in `app'
web_1 | from /usr/local/bundle/gems/rack-2.0.1/lib/rack/server.rb:353:in `wrapped_app'
web_1 | from /usr/local/bundle/gems/railties-5.0.0.1/lib/rails/commands/server.rb:124:in `log_to_stdout'
web_1 | from /usr/local/bundle/gems/railties-5.0.0.1/lib/rails/commands/server.rb:77:in `start'
web_1 | from /usr/local/bundle/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:90:in `block in server'
web_1 | from /usr/local/bundle/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:85:in `tap'
web_1 | from /usr/local/bundle/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:85:in `server'
web_1 | from /usr/local/bundle/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:49:in `run_command!'
web_1 | from /usr/local/bundle/gems/railties-5.0.0.1/lib/rails/commands.rb:18:in `<top (required)>'
web_1 | from bin/rails:4:in `require'
web_1 | from bin/rails:4:in `<main>'
work_project_web_1 exited with code 1
My docker-compose file:
version: '2'
services:
db:
image: postgres:9.6.0
redis:
image: redis:3.2.4
command: redis-server
ports:
- '6379:6379'
volumes:
- '.:/var/lib/redis/data'
# To run jobs in development, uncomment out this block
sidekiq:
build: .
command: bundle exec sidekiq -C config/sidekiq.yml
env_file: .env
links:
- db
- redis
web:
build: .
command: bundle exec rails s -p 3000 -b '0.0.0.0'
env_file: .env
volumes:
- .:/work_project
ports:
- '3000:3000'
depends_on:
- db
- redis
Maybe a little overkill, but you could look at the Sidekiq Scheduler Gem. It offers a lot, like regular scheduling of jobs, but also includes an option to trigger on startup.
I have the problem that Foreman was running correctly until a few days ago. Yesterday I made a complete upgrade of the all system, so I don't know if this caused the problem.
Anyway I cannot trace the problem back.
To solve the problem I updated all my gems, uninstalled and re-installed the myslq2 gem, but nothing has changed.
I paste the Foreman output
luca#luca-X200MA:~/cmonrails/cmonrails$ foreman start
10:46:36 web.1 | started with pid 6863
10:46:36 memcached.1 | started with pid 6864
10:46:40 web.1 | warning: parser/current is loading parser/ruby21, which recognizes
10:46:40 web.1 | warning: 2.1.7-compliant syntax, but you are running 2.1.2.
10:46:40 web.1 | warning: please see https://github.com/whitequark/parser#compatibility-with-ruby-mri.
10:46:42 web.1 | => Booting WEBrick
10:46:42 web.1 | => Rails 4.2.3 application starting in development on http://0.0.0.0:3000
10:46:42 web.1 | => Run `rails server -h` for more startup options
10:46:42 web.1 | => Ctrl-C to shutdown server
10:46:42 web.1 | Exiting
10:46:42 web.1 | /var/lib/gems/2.1.0/gems/activerecord-4.2.3/lib/active_record/connection_adapters/connection_specification.rb:177:in `rescue in spec': Specified 'mysql2' for database adapter, but the gem is not loaded. Add `gem 'mysql2'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord). (Gem::LoadError)
10:46:42 web.1 | from /var/lib/gems/2.1.0/gems/activerecord-4.2.3/lib/active_record/connection_adapters/connection_specification.rb:174:in `spec'
10:46:42 web.1 | from /var/lib/gems/2.1.0/gems/activerecord-4.2.3/lib/active_record/connection_handling.rb:50:in `establish_connection'
10:46:42 web.1 | from /var/lib/gems/2.1.0/gems/activerecord-4.2.3/lib/active_record/railtie.rb:120:in `block (2 levels) in <class:Railtie>'
10:46:42 web.1 | from /var/lib/gems/2.1.0/gems/activesupport-4.2.3/lib/active_support/lazy_load_hooks.rb:38:in `instance_eval'
10:46:42 web.1 | from /var/lib/gems/2.1.0/gems/activesupport-4.2.3/lib/active_support/lazy_load_hooks.rb:38:in `execute_hook'
10:46:42 web.1 | from /var/lib/gems/2.1.0/gems/activesupport-4.2.3/lib/active_support/lazy_load_hooks.rb:45:in `block in run_load_hooks'
10:46:42 web.1 | from /var/lib/gems/2.1.0/gems/activesupport-4.2.3/lib/active_support/lazy_load_hooks.rb:44:in `each'
10:46:42 web.1 | from /var/lib/gems/2.1.0/gems/activesupport-4.2.3/lib/active_support/lazy_load_hooks.rb:44:in `run_load_hooks'
10:46:42 web.1 | from /var/lib/gems/2.1.0/gems/activerecord-4.2.3/lib/active_record/base.rb:315:in `<module:ActiveRecord>'
10:46:42 web.1 | from /var/lib/gems/2.1.0/gems/activerecord-4.2.3/lib/active_record/base.rb:26:in `<top (required)>'
10:46:42 web.1 | from /var/lib/gems/2.1.0/gems/newrelic_rpm-3.14.0.305/lib/new_relic/environment_report.rb:73:in `block in <class:EnvironmentReport>'
10:46:42 web.1 | from /var/lib/gems/2.1.0/gems/newrelic_rpm-3.14.0.305/lib/new_relic/environment_report.rb:99:in `call'
10:46:42 web.1 | from /var/lib/gems/2.1.0/gems/newrelic_rpm-3.14.0.305/lib/new_relic/environment_report.rb:99:in `block in initialize'
10:46:42 web.1 | from /var/lib/gems/2.1.0/gems/newrelic_rpm-3.14.0.305/lib/new_relic/environment_report.rb:97:in `each'
10:46:42 web.1 | from /var/lib/gems/2.1.0/gems/newrelic_rpm-3.14.0.305/lib/new_relic/environment_report.rb:97:in `inject'
10:46:42 web.1 | from /var/lib/gems/2.1.0/gems/newrelic_rpm-3.14.0.305/lib/new_relic/environment_report.rb:97:in `initialize'
10:46:42 web.1 | from /var/lib/gems/2.1.0/gems/newrelic_rpm-3.14.0.305/lib/new_relic/agent/agent.rb:799:in `new'
10:46:42 web.1 | from /var/lib/gems/2.1.0/gems/newrelic_rpm-3.14.0.305/lib/new_relic/agent/agent.rb:799:in `environment_for_connect'
10:46:42 web.1 | from /var/lib/gems/2.1.0/gems/newrelic_rpm-3.14.0.305/lib/new_relic/agent/agent.rb:790:in `generate_environment_report'
10:46:42 web.1 | from /var/lib/gems/2.1.0/gems/newrelic_rpm-3.14.0.305/lib/new_relic/agent/agent.rb:491:in `setup_and_start_agent'
10:46:42 web.1 | from /var/lib/gems/2.1.0/gems/newrelic_rpm-3.14.0.305/lib/new_relic/agent/agent.rb:479:in `check_config_and_start_agent'
10:46:42 web.1 | from /var/lib/gems/2.1.0/gems/newrelic_rpm-3.14.0.305/lib/new_relic/agent/agent.rb:547:in `start'
10:46:42 web.1 | from /var/lib/gems/2.1.0/gems/newrelic_rpm-3.14.0.305/lib/new_relic/control/instance_methods.rb:112:in `start_agent'
10:46:42 web.1 | from /var/lib/gems/2.1.0/gems/newrelic_rpm-3.14.0.305/lib/new_relic/control/instance_methods.rb:72:in `init_plugin'
10:46:42 web.1 | from /var/lib/gems/2.1.0/gems/newrelic_rpm-3.14.0.305/lib/newrelic_rpm.rb:41:in `block in <class:Railtie>'
10:46:42 web.1 | from /var/lib/gems/2.1.0/gems/railties-4.2.3/lib/rails/initializable.rb:30:in `instance_exec'
10:46:42 web.1 | from /var/lib/gems/2.1.0/gems/railties-4.2.3/lib/rails/initializable.rb:30:in `run'
10:46:42 web.1 | from /var/lib/gems/2.1.0/gems/railties-4.2.3/lib/rails/initializable.rb:55:in `block in run_initializers'
10:46:42 web.1 | from /usr/lib/ruby/2.1.0/tsort.rb:226:in `block in tsort_each'
10:46:42 web.1 | from /usr/lib/ruby/2.1.0/tsort.rb:348:in `block (2 levels) in each_strongly_connected_component'
10:46:42 web.1 | from /usr/lib/ruby/2.1.0/tsort.rb:427:in `each_strongly_connected_component_from'
10:46:42 web.1 | from /usr/lib/ruby/2.1.0/tsort.rb:347:in `block in each_strongly_connected_component'
10:46:42 web.1 | from /usr/lib/ruby/2.1.0/tsort.rb:345:in `each'
10:46:42 web.1 | from /usr/lib/ruby/2.1.0/tsort.rb:345:in `call'
10:46:42 web.1 | from /usr/lib/ruby/2.1.0/tsort.rb:345:in `each_strongly_connected_component'
10:46:42 web.1 | from /usr/lib/ruby/2.1.0/tsort.rb:224:in `tsort_each'
10:46:42 web.1 | from /usr/lib/ruby/2.1.0/tsort.rb:205:in `tsort_each'
10:46:42 web.1 | from /var/lib/gems/2.1.0/gems/railties-4.2.3/lib/rails/initializable.rb:54:in `run_initializers'
10:46:42 web.1 | from /var/lib/gems/2.1.0/gems/railties-4.2.3/lib/rails/application.rb:352:in `initialize!'
10:46:42 web.1 | from /home/luca/cmonrails/cmonrails/config/environment.rb:5:in `<top (required)>'
10:46:42 web.1 | from /home/luca/cmonrails/cmonrails/config.ru:3:in `require'
10:46:42 web.1 | from /home/luca/cmonrails/cmonrails/config.ru:3:in `block in <main>'
10:46:42 web.1 | from /var/lib/gems/2.1.0/gems/rack-1.6.4/lib/rack/builder.rb:55:in `instance_eval'
10:46:42 web.1 | from /var/lib/gems/2.1.0/gems/rack-1.6.4/lib/rack/builder.rb:55:in `initialize'
10:46:42 web.1 | from /home/luca/cmonrails/cmonrails/config.ru:in `new'
10:46:42 web.1 | from /home/luca/cmonrails/cmonrails/config.ru:in `<main>'
10:46:42 web.1 | from /var/lib/gems/2.1.0/gems/rack-1.6.4/lib/rack/builder.rb:49:in `eval'
10:46:42 web.1 | from /var/lib/gems/2.1.0/gems/rack-1.6.4/lib/rack/builder.rb:49:in `new_from_string'
10:46:42 web.1 | from /var/lib/gems/2.1.0/gems/rack-1.6.4/lib/rack/builder.rb:40:in `parse_file'
10:46:42 web.1 | from /var/lib/gems/2.1.0/gems/rack-1.6.4/lib/rack/server.rb:299:in `build_app_and_options_from_config'
10:46:42 web.1 | from /var/lib/gems/2.1.0/gems/rack-1.6.4/lib/rack/server.rb:208:in `app'
10:46:42 web.1 | from /var/lib/gems/2.1.0/gems/railties-4.2.3/lib/rails/commands/server.rb:61:in `app'
10:46:42 web.1 | from /var/lib/gems/2.1.0/gems/rack-1.6.4/lib/rack/server.rb:336:in `wrapped_app'
10:46:42 web.1 | from /var/lib/gems/2.1.0/gems/railties-4.2.3/lib/rails/commands/server.rb:139:in `log_to_stdout'
10:46:42 web.1 | from /var/lib/gems/2.1.0/gems/railties-4.2.3/lib/rails/commands/server.rb:78:in `start'
10:46:42 web.1 | from /var/lib/gems/2.1.0/gems/railties-4.2.3/lib/rails/commands/commands_tasks.rb:80:in `block in server'
10:46:42 web.1 | from /var/lib/gems/2.1.0/gems/railties-4.2.3/lib/rails/commands/commands_tasks.rb:75:in `tap'
10:46:42 web.1 | from /var/lib/gems/2.1.0/gems/railties-4.2.3/lib/rails/commands/commands_tasks.rb:75:in `server'
10:46:42 web.1 | from /var/lib/gems/2.1.0/gems/railties-4.2.3/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
10:46:42 web.1 | from /var/lib/gems/2.1.0/gems/railties-4.2.3/lib/rails/commands.rb:17:in `<top (required)>'
10:46:42 web.1 | from bin/rails:8:in `require'
10:46:42 web.1 | from bin/rails:8:in `<main>'
10:46:42 web.1 | exited with code 1
10:46:42 system | sending SIGTERM to all processes
10:46:42 memcached.1 | terminated by SIGTERM
I've seen this often - it seems there is an issues with the latest mysql2 gem. You should try specifying a version that previously worked. I've personally found 0.3.20 fixes the problem. So just update your Gemfile with:
gem 'mysql2', '0.3.20'
Hopefully that should fix it.
My only assumption is that there are some changes in the main mysql2 gem to support Rails 5?