Rails deploy failing - [error]Health check on port 3000 has failed. Your app is not responding properly. Services exposed on ports [80, 443] will have intermittent failures until the health check passes.

Hi all,

I’m trying to deploy a Rails 7 app and I’m getting the following in the logs: [error]Health check on port 3000 has failed. Your app is not responding properly. Services exposed on ports [80, 443] will have intermittent failures until the health check passes.

Any idea how to fix that?

Thanks!

All that is saying is that your app failed to start. Common causes include not setting some sort of secret or environment variable that your app needs. But to find out we would need to see something like a stack traceback. Can you check your logs? See Existing Rails Apps · Fly Docs for information on how to do that.

Hi @rubys

Here are the logs:

2023-03-17T21:33:49Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/railties-7.0.1/lib/rails/application.rb:510:in `block in run_tasks_blocks'
2023-03-17T21:33:49Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `block in execute'
2023-03-17T21:33:49Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `each'
2023-03-17T21:33:49Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `execute'
2023-03-17T21:33:49Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:219:in `block in invoke_with_call_chain'
2023-03-17T21:33:49Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `synchronize'
2023-03-17T21:33:49Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `invoke_with_call_chain'
2023-03-17T21:33:49Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:243:in `block in invoke_prerequisites'
2023-03-17T21:33:49Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:241:in `each'
2023-03-17T21:33:49Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:241:in `invoke_prerequisites'
2023-03-17T21:33:49Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:218:in `block in invoke_with_call_chain'
2023-03-17T21:33:49Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `synchronize'
2023-03-17T21:33:49Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `invoke_with_call_chain'
2023-03-17T21:33:49Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:243:in `block in invoke_prerequisites'
2023-03-17T21:33:49Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:241:in `each'
2023-03-17T21:33:49Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:241:in `invoke_prerequisites'
2023-03-17T21:33:49Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:218:in `block in invoke_with_call_chain'
2023-03-17T21:33:49Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `synchronize'
2023-03-17T21:33:49Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `invoke_with_call_chain'
2023-03-17T21:33:49Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:188:in `invoke'
2023-03-17T21:33:49Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:160:in `invoke_task'
2023-03-17T21:33:49Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `block (2 levels) in top_level'
2023-03-17T21:33:49Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `each'
2023-03-17T21:33:49Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `block in top_level'
2023-03-17T21:33:49Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:125:in `run_with_threads'
2023-03-17T21:33:49Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:110:in `top_level'
2023-03-17T21:33:49Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/railties-7.0.1/lib/rails/commands/rake/rake_command.rb:24:in `block (2 levels) in perform'
2023-03-17T21:33:49Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:186:in `standard_exception_handling'
2023-03-17T21:33:49Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/railties-7.0.1/lib/rails/commands/rake/rake_command.rb:24:in `block in perform'
2023-03-17T21:33:49Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/rake_module.rb:59:in `with_application'
2023-03-17T21:33:49Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/railties-7.0.1/lib/rails/commands/rake/rake_command.rb:18:in `perform'
2023-03-17T21:33:49Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/railties-7.0.1/lib/rails/command.rb:51:in `invoke'
2023-03-17T21:33:49Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/railties-7.0.1/lib/rails/commands.rb:18:in `<main>'
2023-03-17T21:33:49Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
2023-03-17T21:33:49Z app[1b2fc1f5] ams [info]Tasks: TOP => db:prepare => db:load_config => environment
2023-03-17T21:33:49Z app[1b2fc1f5] ams [info](See full trace by running task with --trace)
2023-03-17T21:33:50Z app[1b2fc1f5] ams [info]Starting clean up.
2023-03-17T21:33:56Z runner[1b2fc1f5] ams [info]Starting instance
2023-03-17T21:33:56Z runner[1b2fc1f5] ams [info]Configuring virtual machine
2023-03-17T21:33:56Z runner[1b2fc1f5] ams [info]Pulling container image
2023-03-17T21:33:57Z runner[1b2fc1f5] ams [info]Unpacking image
2023-03-17T21:33:57Z runner[1b2fc1f5] ams [info]Preparing kernel init
2023-03-17T21:33:57Z runner[1b2fc1f5] ams [info]Configuring firecracker
2023-03-17T21:34:00Z runner[1b2fc1f5] ams [info]Starting virtual machine
2023-03-17T21:34:00Z app[1b2fc1f5] ams [info]Starting init (commit: 08b4c2b)...
2023-03-17T21:34:00Z app[1b2fc1f5] ams [info]Preparing to run: `/rails/bin/docker-entrypoint ./bin/rails server` as rails
2023-03-17T21:34:00Z app[1b2fc1f5] ams [info]2023/03/17 21:34:00 listening on [fdaa:1:abf7:a7b:c988:1b2f:c1f5:2]:22 (DNS: [fdaa::3]:53)
2023-03-17T21:34:02Z health[1b2fc1f5] ams [warn]Health check on port 3000 is in a 'warning' state. Your app may not be responding properly. Services exposed on ports [80, 443] may have intermittent failures until the health check passes.
2023-03-17T21:34:03Z app[1b2fc1f5] ams [info]rails aborted!
2023-03-17T21:34:03Z app[1b2fc1f5] ams [info]ArgumentError: Missing `secret_key_base` for 'production' environment, set this string with `bin/rails credentials:edit`
2023-03-17T21:34:03Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/railties-7.0.1/lib/rails/application.rb:580:in `validate_secret_key_base'
2023-03-17T21:34:03Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/railties-7.0.1/lib/rails/application.rb:418:in `secret_key_base'
2023-03-17T21:34:03Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/railties-7.0.1/lib/rails/application.rb:157:in `key_generator'
2023-03-17T21:34:03Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/turbo-rails-1.0.1/lib/turbo/engine.rb:65:in `block in <class:Engine>'
2023-03-17T21:34:03Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/railties-7.0.1/lib/rails/initializable.rb:32:in `instance_exec'
2023-03-17T21:34:03Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/railties-7.0.1/lib/rails/initializable.rb:32:in `run'
2023-03-17T21:34:03Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/railties-7.0.1/lib/rails/initializable.rb:61:in `block in run_initializers'
2023-03-17T21:34:03Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/railties-7.0.1/lib/rails/initializable.rb:60:in `run_initializers'
2023-03-17T21:34:03Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/railties-7.0.1/lib/rails/application.rb:372:in `initialize!'
2023-03-17T21:34:03Z app[1b2fc1f5] ams [info]/rails/config/environment.rb:5:in `<main>'
2023-03-17T21:34:03Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
2023-03-17T21:34:03Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/zeitwerk-2.5.4/lib/zeitwerk/kernel.rb:35:in `require'
2023-03-17T21:34:03Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/railties-7.0.1/lib/rails/application.rb:348:in `require_environment!'
2023-03-17T21:34:03Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/railties-7.0.1/lib/rails/application.rb:510:in `block in run_tasks_blocks'
2023-03-17T21:34:03Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `block in execute'
2023-03-17T21:34:03Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `each'
2023-03-17T21:34:03Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `execute'
2023-03-17T21:34:03Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:219:in `block in invoke_with_call_chain'
2023-03-17T21:34:03Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `synchronize'
2023-03-17T21:34:03Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `invoke_with_call_chain'
2023-03-17T21:34:03Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:243:in `block in invoke_prerequisites'
2023-03-17T21:34:03Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:241:in `each'
2023-03-17T21:34:03Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:241:in `invoke_prerequisites'
2023-03-17T21:34:03Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:218:in `block in invoke_with_call_chain'
2023-03-17T21:34:03Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `synchronize'
2023-03-17T21:34:03Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `invoke_with_call_chain'
2023-03-17T21:34:03Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:243:in `block in invoke_prerequisites'
2023-03-17T21:34:03Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:241:in `each'
2023-03-17T21:34:03Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:241:in `invoke_prerequisites'
2023-03-17T21:34:03Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:218:in `block in invoke_with_call_chain'
2023-03-17T21:34:03Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `synchronize'
2023-03-17T21:34:03Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `invoke_with_call_chain'
2023-03-17T21:34:03Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:188:in `invoke'
2023-03-17T21:34:03Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:160:in `invoke_task'
2023-03-17T21:34:03Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `block (2 levels) in top_level'
2023-03-17T21:34:03Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `each'
2023-03-17T21:34:03Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `block in top_level'
2023-03-17T21:34:03Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:125:in `run_with_threads'
2023-03-17T21:34:03Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:110:in `top_level'
2023-03-17T21:34:03Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/railties-7.0.1/lib/rails/commands/rake/rake_command.rb:24:in `block (2 levels) in perform'
2023-03-17T21:34:03Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:186:in `standard_exception_handling'
2023-03-17T21:34:03Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/railties-7.0.1/lib/rails/commands/rake/rake_command.rb:24:in `block in perform'
2023-03-17T21:34:03Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/rake_module.rb:59:in `with_application'
2023-03-17T21:34:03Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/railties-7.0.1/lib/rails/commands/rake/rake_command.rb:18:in `perform'
2023-03-17T21:34:03Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/railties-7.0.1/lib/rails/command.rb:51:in `invoke'
2023-03-17T21:34:03Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/railties-7.0.1/lib/rails/commands.rb:18:in `<main>'
2023-03-17T21:34:03Z app[1b2fc1f5] ams [info]/rails/vendor/bundle/ruby/3.1.0/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
2023-03-17T21:34:03Z app[1b2fc1f5] ams [info]Tasks: TOP => db:prepare => db:load_config => environment
2023-03-17T21:34:03Z app[1b2fc1f5] ams [info](See full trace by running task with --trace)
2023-03-17T21:34:04Z app[1b2fc1f5] ams [info]Starting clean up.

Thanks!

The error is in the logs:

ArgumentError: Missing secret_key_base for ‘production’ environment, set this string with bin/rails credentials:edit

Yup. And that is a variation of Existing Rails Apps · Fly Docs error, with similar solutions.

If you do not have a config/master.key file (often because you did a git clone of an existing project as secrets aren’t placed in git), then follow the instructions on that page for generating new credentials. If you do have a config/master.key, follow the instructions for setting that secret.

The things is I’m using a development and production keys and not a master key. Do I still need one? If not, my idea would be for fly.io to use the production key, but I don’t know how.

imagen

Correct!

would you know how to tell fly.io to use the existing production.key?

Mac/Linux/Windows Bash:

fly secrets set RAILS_MASTER_KEY=$(cat config/credentials/production.key)

Windows Powershell:

$Env:RAILS_MASTER_KEY = Get-Content 'config\credentials\production.key'

I tried that but I’m getting this: Error No change detected to secrets. Skipping release.

Now I’m starting to wonder if your production credentials are set up correctly. Try running:

rails credentials:edit --environment production

You should see a line starting with secret_key_base:

For comparison, try:

rails credentials:edit

And don’t post the results of what you see here or anywhere online as those secrets can be used to compromise your application.

Hi @rubys

You’re right, the production.key doesn’t contain secret_key_base

I ran rails credentials:edit and that one does have it. Should I copy the secret_key_base from the master.key to production.key? Or do I need a unique one for production.key?

Thanks

Your call. But personally I would generate a new one using:

rails secret

Thanks a lot @rubys that fixed the issue. I was able to deploy successfully now. Have a nice weekend!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.