Migrating rails app from heroku. Looks like server gets killed shortly after starting

So I was able to get the gem dependencies resolved, database set up, and fly deploy to work.
It took awhile to figure out how to run the rails server on port 3000 because whatever changes I made to fly.toml to change the internal port, they did not reflect when the server started. It still started on 8080. I ended up changing the server start command in fly.rake

sh 'bin/rails server -p 3000'

So now it is running off of 3000

When I run fly logs I see this:

2023-01-06T01:46:20Z runner[c78dfb7a] sjc [info]Starting instance
2023-01-06T01:46:20Z runner[c78dfb7a] sjc [info]Configuring virtual machine
2023-01-06T01:46:20Z runner[c78dfb7a] sjc [info]Pulling container image
2023-01-06T01:46:23Z runner[c78dfb7a] sjc [info]Unpacking image
2023-01-06T01:46:24Z runner[c78dfb7a] sjc [info]Preparing kernel init
2023-01-06T01:46:25Z runner[c78dfb7a] sjc [info]Configuring firecracker
2023-01-06T01:46:25Z runner[c78dfb7a] sjc [info]Starting virtual machine
2023-01-06T01:46:25Z app[c78dfb7a] sjc [info]Starting init (commit: f447594)…
2023-01-06T01:46:25Z app[c78dfb7a] sjc [info]Preparing to run: /bin/bash -o pipefail -c ${SERVER_COMMAND} as root
2023-01-06T01:46:25Z app[c78dfb7a] sjc [info]2023/01/06 01:46:25 listening on [fdaa:1:1b0f:a7b:b385:c78d:fb7a:2]:22 (DNS: [fdaa::3]:53)
2023-01-06T01:46:27Z app[c78dfb7a] sjc [info]fallocate -l 512M /swapfile
2023-01-06T01:46:27Z app[c78dfb7a] sjc [info]chmod 0600 /swapfile
2023-01-06T01:46:27Z app[c78dfb7a] sjc [info]mkswap /swapfile
2023-01-06T01:46:27Z app[c78dfb7a] sjc [info]Setting up swapspace version 1, size = 512 MiB (536866816 bytes)
2023-01-06T01:46:27Z app[c78dfb7a] sjc [info]no label, UUID=b2df5500-b1ab-41e3-9aff-3b852a2108f8
2023-01-06T01:46:27Z app[c78dfb7a] sjc [info]echo 10 > /proc/sys/vm/swappiness
2023-01-06T01:46:27Z app[c78dfb7a] sjc [info]swapon /swapfile
2023-01-06T01:46:27Z app[c78dfb7a] sjc [info]bin/rails server -p 3000
2023-01-06T01:46:28Z app[c78dfb7a] sjc [info]=> Booting WEBrick
2023-01-06T01:46:28Z app[c78dfb7a] sjc [info]=> Rails 6.0.0 application starting in production http://0.0.0.0:3000
2023-01-06T01:46:28Z app[c78dfb7a] sjc [info]=> Run rails server --help for more startup options
2023-01-06T01:46:29Z app[c78dfb7a] sjc [info]/app/vendor/bundle/ruby/2.7.0/gems/json-1.8.6/lib/json/common.rb:155: warning: Using the last argument as keyword parameters is deprecated
2023-01-06T01:46:29Z app[c78dfb7a] sjc [info][2023-01-06 01:46:29] INFO WEBrick 1.6.0
2023-01-06T01:46:29Z app[c78dfb7a] sjc [info][2023-01-06 01:46:29] INFO ruby 2.7.2 (2020-10-01) [x86_64-linux]
2023-01-06T01:46:29Z app[c78dfb7a] sjc [info][2023-01-06 01:46:29] INFO WEBrick::HTTPServer#start: pid=531 port=3000
2023-01-06T01:46:50Z runner[02929206] sjc [info]Shutting down virtual machine
2023-01-06T01:46:51Z app[02929206] sjc [info]Sending signal SIGINT to main child process w/ PID 521
2023-01-06T01:46:51Z app[02929206] sjc [info]rails aborted!
2023-01-06T01:46:51Z app[02929206] sjc [info]Interrupt:
2023-01-06T01:46:51Z app[02929206] sjc [info]/app/lib/tasks/fly.rake:21:in block (2 levels) in <top (required)>' 2023-01-06T01:46:51Z app[02929206] sjc [info]/app/vendor/bundle/ruby/2.7.0/gems/railties-6.0.0/lib/rails/commands/rake/rake_command.rb:23:in block in perform’
2023-01-06T01:46:51Z app[02929206] sjc [info]/app/vendor/bundle/ruby/2.7.0/gems/railties-6.0.0/lib/rails/commands/rake/rake_command.rb:20:in perform' 2023-01-06T01:46:51Z app[02929206] sjc [info]/app/vendor/bundle/ruby/2.7.0/gems/railties-6.0.0/lib/rails/command.rb:48:in invoke’
2023-01-06T01:46:51Z app[02929206] sjc [info]/app/vendor/bundle/ruby/2.7.0/gems/railties-6.0.0/lib/rails/commands.rb:18:in <top (required)>' 2023-01-06T01:46:51Z app[02929206] sjc [info]bin/rails:9:in require’
2023-01-06T01:46:51Z app[02929206] sjc [info]bin/rails:9:in `’
2023-01-06T01:46:51Z app[02929206] sjc [info]Tasks: TOP => fly:server
2023-01-06T01:46:51Z app[02929206] sjc [info](See full trace by running task with --trace)
2023-01-06T01:46:51Z app[02929206] sjc [info]Starting clean up.

App runs fine locally on 3000. Here is my fly.toml:

kill_signal = "SIGINT"
kill_timeout = 5
processes = []

[build]
  [build.args]
    BUILD_COMMAND = "bin/rails fly:build"
    SERVER_COMMAND = "bin/rails fly:server"

[deploy]
  release_command = "bin/rails fly:release"

[env]
  PORT = "3000"
[experimental]
  allowed_public_ports = []
  auto_rollback = true

[[services]]
  http_checks = []
  internal_port = 3000
  processes = ["web"]
  protocol = "tcp"
  script_checks = []
  [services.concurrency]
    hard_limit = 25
    soft_limit = 20
    type = "connections"

  [[services.ports]]
    force_https = true
    handlers = ["http"]
    port = 80

  [[services.ports]]
    handlers = ["tls", "http"]
    port = 443

  [[services.tcp_checks]]
    grace_period = "1s"
    interval = "15s"
    restart_limit = 0
    timeout = "2s"

[[statics]]
  guest_path = "/app/public"
  url_prefix = "/"

and my fly.rake

# commands used to deploy a Rails application
namespace :fly do
  # BUILD step:
  #  - changes to the filesystem made here DO get deployed
  #  - NO access to secrets, volumes, databases
  #  - Failures here prevent deployment
  task :build => 'assets:precompile'

  # RELEASE step:
  #  - changes to the filesystem made here are DISCARDED
  #  - full access to secrets, databases
  #  - failures here prevent deployment
  task :release => 'db:migrate'

  # SERVER step:
  #  - changes to the filesystem made here are deployed
  #  - full access to secrets, databases
  #  - failures here result in VM being stated, shutdown, and rolled back
  #    to last successful deploy (if any).
  task :server => :swapfile do
    sh 'bin/rails server -p 3000'
  end

  # optional SWAPFILE task:
  #  - adjust fallocate size as needed
  #  - performance critical applications should scale memory to the
  #    point where swap is rarely used.  'fly scale help' for details.
  #  - disable by removing dependency on the :server task, thus:
  #        task :server do
  task :swapfile do
    sh 'fallocate -l 512M /swapfile'
    sh 'chmod 0600 /swapfile'
    sh 'mkswap /swapfile'
    sh 'echo 10 > /proc/sys/vm/swappiness'
    sh 'swapon /swapfile'
  end
end

Is there some other configuration that I’m missing?

WEBrick is not recommended for production, and may be why the PORT environment variable wasn’t working for you.

Was this an intentional choice? If not, consider running bundle add puma and deploying again.

Added puma with same result

2023-01-06T02:21:39Z runner[641d0b90] sjc [info]Starting instance
2023-01-06T02:21:39Z runner[641d0b90] sjc [info]Configuring virtual machine
2023-01-06T02:21:39Z runner[641d0b90] sjc [info]Pulling container image
2023-01-06T02:21:46Z runner[641d0b90] sjc [info]Unpacking image
2023-01-06T02:21:53Z runner[641d0b90] sjc [info]Preparing kernel init
2023-01-06T02:21:54Z runner[641d0b90] sjc [info]Configuring firecracker
2023-01-06T02:21:54Z runner[641d0b90] sjc [info]Starting virtual machine
2023-01-06T02:21:54Z app[641d0b90] sjc [info]Starting init (commit: f447594)...
2023-01-06T02:21:54Z app[641d0b90] sjc [info]Setting up swapspace version 1, size = 512 MiB (536866816 bytes)
2023-01-06T02:21:54Z app[641d0b90] sjc [info]no label, UUID=58df12e0-03a6-4d31-9423-c4b6e696c5de
2023-01-06T02:21:54Z app[641d0b90] sjc [info]Preparing to run: `bin/rails fly:release` as root
2023-01-06T02:21:54Z app[641d0b90] sjc [info]2023/01/06 02:21:54 listening on [fdaa:1:1b0f:a7b:a3:641d:b90:2]:22 (DNS: [fdaa::3]:53)
2023-01-06T02:21:56Z app[641d0b90] sjc [info]/app/vendor/bundle/ruby/2.7.0/gems/json-1.8.6/lib/json/common.rb:155: warning: Using the last argument as keyword parameters is deprecated
2023-01-06T02:21:57Z app[641d0b90] sjc [info]Starting clean up.
2023-01-06T02:22:08Z runner[c4628295] sjc [info]Starting instance
2023-01-06T02:22:08Z runner[c4628295] sjc [info]Configuring virtual machine
2023-01-06T02:22:08Z runner[c4628295] sjc [info]Pulling container image
2023-01-06T02:22:09Z runner[c4628295] sjc [info]Unpacking image
2023-01-06T02:22:09Z runner[c4628295] sjc [info]Preparing kernel init
2023-01-06T02:22:09Z runner[c4628295] sjc [info]Configuring firecracker
2023-01-06T02:22:09Z runner[c4628295] sjc [info]Starting virtual machine
2023-01-06T02:22:10Z app[c4628295] sjc [info]Starting init (commit: f447594)...
2023-01-06T02:22:10Z app[c4628295] sjc [info]Preparing to run: `/bin/bash -o pipefail -c ${SERVER_COMMAND}` as root
2023-01-06T02:22:10Z app[c4628295] sjc [info]2023/01/06 02:22:10 listening on [fdaa:1:1b0f:a7b:a3:c462:8295:2]:22 (DNS: [fdaa::3]:53)
2023-01-06T02:22:12Z app[c4628295] sjc [info]fallocate -l 512M /swapfile
2023-01-06T02:22:12Z app[c4628295] sjc [info]chmod 0600 /swapfile
2023-01-06T02:22:12Z app[c4628295] sjc [info]mkswap /swapfile
2023-01-06T02:22:12Z app[c4628295] sjc [info]Setting up swapspace version 1, size = 512 MiB (536866816 bytes)
2023-01-06T02:22:12Z app[c4628295] sjc [info]no label, UUID=2fd176ea-6e90-42d8-a09d-77d942b83dc1
2023-01-06T02:22:12Z app[c4628295] sjc [info]echo 10 > /proc/sys/vm/swappiness
2023-01-06T02:22:12Z app[c4628295] sjc [info]swapon /swapfile
2023-01-06T02:22:12Z app[c4628295] sjc [info]bin/rails server -p 3000
2023-01-06T02:22:13Z app[c4628295] sjc [info]=> Booting Puma
2023-01-06T02:22:13Z app[c4628295] sjc [info]=> Rails 6.0.0 application starting in production
2023-01-06T02:22:13Z app[c4628295] sjc [info]=> Run `rails server --help` for more startup options
2023-01-06T02:22:14Z app[c4628295] sjc [info]/app/vendor/bundle/ruby/2.7.0/gems/json-1.8.6/lib/json/common.rb:155: warning: Using the last argument as keyword parameters is deprecated
2023-01-06T02:22:14Z app[c4628295] sjc [info]Puma starting in single mode...
2023-01-06T02:22:14Z app[c4628295] sjc [info]* Puma version: 6.0.2 (ruby 2.7.2-p137) ("Sunflower")
2023-01-06T02:22:14Z app[c4628295] sjc [info]*  Min threads: 0
2023-01-06T02:22:14Z app[c4628295] sjc [info]*  Max threads: 5
2023-01-06T02:22:14Z app[c4628295] sjc [info]*  Environment: production
2023-01-06T02:22:14Z app[c4628295] sjc [info]*          PID: 531
2023-01-06T02:22:14Z app[c4628295] sjc [info]* Listening on http://0.0.0.0:3000
2023-01-06T02:22:14Z app[c4628295] sjc [info]Use Ctrl-C to stop
2023-01-06T02:22:35Z runner[c78dfb7a] sjc [info]Shutting down virtual machine
2023-01-06T02:22:35Z app[c78dfb7a] sjc [info]Sending signal SIGINT to main child process w/ PID 520
2023-01-06T02:22:35Z app[c78dfb7a] sjc [info]rails aborted!
2023-01-06T02:22:35Z app[c78dfb7a] sjc [info]Interrupt:
2023-01-06T02:22:35Z app[c78dfb7a] sjc [info]/app/lib/tasks/fly.rake:21:in `block (2 levels) in <top (required)>'
2023-01-06T02:22:35Z app[c78dfb7a] sjc [info]/app/vendor/bundle/ruby/2.7.0/gems/railties-6.0.0/lib/rails/commands/rake/rake_command.rb:23:in `block in perform'
2023-01-06T02:22:35Z app[c78dfb7a] sjc [info]/app/vendor/bundle/ruby/2.7.0/gems/railties-6.0.0/lib/rails/commands/rake/rake_command.rb:20:in `perform'
2023-01-06T02:22:35Z app[c78dfb7a] sjc [info]/app/vendor/bundle/ruby/2.7.0/gems/railties-6.0.0/lib/rails/command.rb:48:in `invoke'
2023-01-06T02:22:35Z app[c78dfb7a] sjc [info]/app/vendor/bundle/ruby/2.7.0/gems/railties-6.0.0/lib/rails/commands.rb:18:in `<top (required)>'
2023-01-06T02:22:35Z app[c78dfb7a] sjc [info]bin/rails:9:in `require'
2023-01-06T02:22:35Z app[c78dfb7a] sjc [info]bin/rails:9:in `<main>'
2023-01-06T02:22:35Z app[c78dfb7a] sjc [info]Tasks: TOP => fly:server
2023-01-06T02:22:35Z app[c78dfb7a] sjc [info](See full trace by running task with --trace)
2023-01-06T02:22:36Z app[c78dfb7a] sjc [info]Starting clean up.

@yamjerky I just answered another question regarding a python server (gunicorn) only binding to ipv4. I think you need to bind to ipv6. It seems like your configuration is only listening to ipv4. I don’t know enough about rails to tell but maybe double check.

I saw your other answer, and I suspect that Webrick can’t talk ipv6; which is why I suggested puma as I know it can.

I can successfully deploy a Rails app on port 3000 with puma:

 2023-01-06T02:40:03.620 app[04ba61f0] ewr [info] => Booting Puma
2023-01-06T02:40:03.620 app[04ba61f0] ewr [info] => Rails 7.0.4 application starting in production
2023-01-06T02:40:03.620 app[04ba61f0] ewr [info] => Run `bin/rails server --help` for more startup options
2023-01-06T02:40:04.171 app[04ba61f0] ewr [info] Puma starting in single mode...
2023-01-06T02:40:04.171 app[04ba61f0] ewr [info] * Puma version: 5.6.5 (ruby 3.2.0-p0) ("Birdie's Version")
2023-01-06T02:40:04.171 app[04ba61f0] ewr [info] * Min threads: 5
2023-01-06T02:40:04.171 app[04ba61f0] ewr [info] * Max threads: 5
2023-01-06T02:40:04.171 app[04ba61f0] ewr [info] * Environment: production
2023-01-06T02:40:04.171 app[04ba61f0] ewr [info] * PID: 525
2023-01-06T02:40:04.171 app[04ba61f0] ewr [info] * Listening on http://0.0.0.0:3000
2023-01-06T02:40:04.174 app[04ba61f0] ewr [info] Use Ctrl-C to stop 

I’m not sure what else to suggest.

Seems that -b [::] is needed at this line:

I can successfully deploy without that:

2023-01-06T02:49:18.518 app[c9b4baf8] ewr [info] Preparing to run: `/bin/sh -c bin/rails server -P 3000` as root 

Thanks! Tried but still fails out after launching:

2023-01-06T02:49:17Z runner[8d42241b] sjc [info]Starting instance
2023-01-06T02:49:18Z runner[8d42241b] sjc [info]Configuring virtual machine
2023-01-06T02:49:18Z runner[8d42241b] sjc [info]Pulling container image
2023-01-06T02:49:21Z runner[8d42241b] sjc [info]Unpacking image
2023-01-06T02:49:22Z runner[8d42241b] sjc [info]Preparing kernel init
2023-01-06T02:49:22Z runner[8d42241b] sjc [info]Configuring firecracker
2023-01-06T02:49:22Z runner[8d42241b] sjc [info]Starting virtual machine
2023-01-06T02:49:23Z app[8d42241b] sjc [info]Starting init (commit: f447594)...
2023-01-06T02:49:23Z app[8d42241b] sjc [info]Setting up swapspace version 1, size = 512 MiB (536866816 bytes)
2023-01-06T02:49:23Z app[8d42241b] sjc [info]no label, UUID=3eab9162-9c67-4e23-9819-17078f98987e
2023-01-06T02:49:23Z app[8d42241b] sjc [info]Preparing to run: `bin/rails fly:release` as root
2023-01-06T02:49:23Z app[8d42241b] sjc [info]2023/01/06 02:49:23 listening on [fdaa:1:1b0f:a7b:a3:8d42:241b:2]:22 (DNS: [fdaa::3]:53)
2023-01-06T02:49:25Z app[8d42241b] sjc [info]/app/vendor/bundle/ruby/2.7.0/gems/json-1.8.6/lib/json/common.rb:155: warning: Using the last argument as keyword parameters is deprecated
2023-01-06T02:49:26Z app[8d42241b] sjc [info]Starting clean up.
2023-01-06T02:49:33Z runner[b34ee087] sjc [info]Starting instance
2023-01-06T02:49:33Z runner[b34ee087] sjc [info]Configuring virtual machine
2023-01-06T02:49:33Z runner[b34ee087] sjc [info]Pulling container image
2023-01-06T02:49:34Z runner[b34ee087] sjc [info]Unpacking image
2023-01-06T02:49:34Z runner[b34ee087] sjc [info]Preparing kernel init
2023-01-06T02:49:34Z runner[b34ee087] sjc [info]Configuring firecracker
2023-01-06T02:49:35Z runner[b34ee087] sjc [info]Starting virtual machine
2023-01-06T02:49:35Z app[b34ee087] sjc [info]Starting init (commit: f447594)...
2023-01-06T02:49:35Z app[b34ee087] sjc [info]Preparing to run: `/bin/bash -o pipefail -c ${SERVER_COMMAND}` as root
2023-01-06T02:49:35Z app[b34ee087] sjc [info]2023/01/06 02:49:35 listening on [fdaa:1:1b0f:a7b:a3:b34e:e087:2]:22 (DNS: [fdaa::3]:53)
2023-01-06T02:49:37Z app[b34ee087] sjc [info]fallocate -l 512M /swapfile
2023-01-06T02:49:37Z app[b34ee087] sjc [info]chmod 0600 /swapfile
2023-01-06T02:49:37Z app[b34ee087] sjc [info]mkswap /swapfile
2023-01-06T02:49:37Z app[b34ee087] sjc [info]Setting up swapspace version 1, size = 512 MiB (536866816 bytes)
2023-01-06T02:49:37Z app[b34ee087] sjc [info]no label, UUID=f89a286d-5894-4e2c-8024-4b28041805b3
2023-01-06T02:49:37Z app[b34ee087] sjc [info]echo 10 > /proc/sys/vm/swappiness
2023-01-06T02:49:37Z app[b34ee087] sjc [info]swapon /swapfile
2023-01-06T02:49:37Z app[b34ee087] sjc [info]bin/rails server -p 3000 -b [::]
2023-01-06T02:49:38Z app[b34ee087] sjc [info]=> Booting Puma
2023-01-06T02:49:38Z app[b34ee087] sjc [info]=> Rails 6.0.0 application starting in production
2023-01-06T02:49:38Z app[b34ee087] sjc [info]=> Run `rails server --help` for more startup options
2023-01-06T02:49:39Z app[b34ee087] sjc [info]/app/vendor/bundle/ruby/2.7.0/gems/json-1.8.6/lib/json/common.rb:155: warning: Using the last argument as keyword parameters is deprecated
2023-01-06T02:49:39Z app[b34ee087] sjc [info]Puma starting in single mode...
2023-01-06T02:49:39Z app[b34ee087] sjc [info]* Puma version: 6.0.2 (ruby 2.7.2-p137) ("Sunflower")
2023-01-06T02:49:39Z app[b34ee087] sjc [info]*  Min threads: 0
2023-01-06T02:49:39Z app[b34ee087] sjc [info]*  Max threads: 5
2023-01-06T02:49:39Z app[b34ee087] sjc [info]*  Environment: production
2023-01-06T02:49:39Z app[b34ee087] sjc [info]*          PID: 532
2023-01-06T02:49:39Z app[b34ee087] sjc [info]* Listening on http://[::]:3000
2023-01-06T02:49:39Z app[b34ee087] sjc [info]Use Ctrl-C to stop
2023-01-06T02:50:01Z runner[3af648b0] sjc [info]Shutting down virtual machine
2023-01-06T02:50:01Z app[3af648b0] sjc [info]Sending signal SIGINT to main child process w/ PID 520
2023-01-06T02:50:01Z app[3af648b0] sjc [info]rails aborted!
2023-01-06T02:50:01Z app[3af648b0] sjc [info]Interrupt:
2023-01-06T02:50:01Z app[3af648b0] sjc [info]/app/lib/tasks/fly.rake:21:in `block (2 levels) in <top (required)>'
2023-01-06T02:50:01Z app[3af648b0] sjc [info]/app/vendor/bundle/ruby/2.7.0/gems/railties-6.0.0/lib/rails/commands/rake/rake_command.rb:23:in `block in perform'
2023-01-06T02:50:01Z app[3af648b0] sjc [info]/app/vendor/bundle/ruby/2.7.0/gems/railties-6.0.0/lib/rails/commands/rake/rake_command.rb:20:in `perform'
2023-01-06T02:50:01Z app[3af648b0] sjc [info]/app/vendor/bundle/ruby/2.7.0/gems/railties-6.0.0/lib/rails/command.rb:48:in `invoke'
2023-01-06T02:50:01Z app[3af648b0] sjc [info]/app/vendor/bundle/ruby/2.7.0/gems/railties-6.0.0/lib/rails/commands.rb:18:in `<top (required)>'
2023-01-06T02:50:01Z app[3af648b0] sjc [info]bin/rails:9:in `require'
2023-01-06T02:50:01Z app[3af648b0] sjc [info]bin/rails:9:in `<main>'
2023-01-06T02:50:01Z app[3af648b0] sjc [info]Tasks: TOP => fly:server
2023-01-06T02:50:01Z app[3af648b0] sjc [info](See full trace by running task with --trace)
2023-01-06T02:50:02Z app[3af648b0] sjc [info]Starting clean up.

@yamjerky Is the actual image listening on port 22?

Nevermind, I have the same output in my logs for port 22. I think that is just the fly container itself.

If all else fails I might just fire up a brand new rails app to see that work, then start porting things over. I’ll try to bang on it for a few more hours. Thanks for your help @ianjosephwilson and @rubys

any luck with this? I’m running into the same issue

The key thing to look at in this trace is the hex string in the first set of brackets.

What I see is one server starting [b34ee087], and then what presumably is the previous server being taken down [3af648b0].

I ended up just spinning up a new app and doing the ‘fly launch’. Once that was deployable I started moving over all the files. There were some gem dependencies that were not compatible so I trashed my gemlock and rebundled. That seemed to do the trick