Cannot deploy a Rails app: "A server is already running. Check /app/tmp/pids/server.pid."

Cannot deploy my Rails app with the following commands on an empty organization (meaning no apps in the organization):

flyctl launch (then manually select organization, location etc.)
flyctl scale vm dedicated-cpu-1x
flyctl deploy

The logs are:

2022-12-20T01:59:56.696 app[be5939b8] nrt [info] Starting init (commit: f447594)...

2022-12-20T01:59:56.796 app[be5939b8] nrt [info] Preparing to run: `/bin/bash -o pipefail -c ${SERVER_COMMAND}` as root

2022-12-20T01:59:56.940 app[be5939b8] nrt [info] 2022/12/20 01:59:56 listening on [fdaa:1:548:a7b:d829:be59:39b8:2]:22 (DNS: [fdaa::3]:53)

2022-12-20T02:00:01.525 app[be5939b8] nrt [info] bin/rails server

2022-12-20T02:00:03.300 app[be5939b8] nrt [info] => Booting Puma

2022-12-20T02:00:03.300 app[be5939b8] nrt [info] => Rails 6.1.3.2 application starting in production

2022-12-20T02:00:03.300 app[be5939b8] nrt [info] => Run `bin/rails server --help` for more startup options

2022-12-20T02:00:03.300 app[be5939b8] nrt [info] A server is already running. Check /app/tmp/pids/server.pid.

2022-12-20T02:00:03.300 app[be5939b8] nrt [info] Exiting

2022-12-20T02:00:03.327 app[be5939b8] nrt [info] rails aborted!

2022-12-20T02:00:03.327 app[be5939b8] nrt [info] Command failed with status (1): [bin/rails server...]

2022-12-20T02:00:03.327 app[be5939b8] nrt [info] /app/vendor/bundle/ruby/2.7.0/gems/rake-13.0.3/lib/rake/file_utils.rb:67:in `block in create_shell_runner'

2022-12-20T02:00:03.327 app[be5939b8] nrt [info] /app/vendor/bundle/ruby/2.7.0/gems/rake-13.0.3/lib/rake/file_utils.rb:57:in `sh'

2022-12-20T02:00:03.327 app[be5939b8] nrt [info] /app/lib/tasks/fly.rake:21:in `block (2 levels) in <main>'

2022-12-20T02:00:03.327 app[be5939b8] nrt [info] /app/vendor/bundle/ruby/2.7.0/gems/rake-13.0.3/lib/rake/task.rb:281:in `block in execute'

2022-12-20T02:00:03.327 app[be5939b8] nrt [info] /app/vendor/bundle/ruby/2.7.0/gems/rake-13.0.3/lib/rake/task.rb:281:in `each'

2022-12-20T02:00:03.327 app[be5939b8] nrt [info] /app/vendor/bundle/ruby/2.7.0/gems/rake-13.0.3/lib/rake/task.rb:281:in `execute'

2022-12-20T02:00:03.327 app[be5939b8] nrt [info] /app/vendor/bundle/ruby/2.7.0/gems/rake-13.0.3/lib/rake/task.rb:219:in `block in invoke_with_call_chain'

2022-12-20T02:00:03.327 app[be5939b8] nrt [info] /app/vendor/bundle/ruby/2.7.0/gems/rake-13.0.3/lib/rake/task.rb:199:in `synchronize'

2022-12-20T02:00:03.327 app[be5939b8] nrt [info] /app/vendor/bundle/ruby/2.7.0/gems/rake-13.0.3/lib/rake/task.rb:199:in `invoke_with_call_chain'

2022-12-20T02:00:03.327 app[be5939b8] nrt [info] /app/vendor/bundle/ruby/2.7.0/gems/rake-13.0.3/lib/rake/task.rb:188:in `invoke'

2022-12-20T02:00:03.327 app[be5939b8] nrt [info] /app/vendor/bundle/ruby/2.7.0/gems/rake-13.0.3/lib/rake/application.rb:160:in `invoke_task'

2022-12-20T02:00:03.327 app[be5939b8] nrt [info] /app/vendor/bundle/ruby/2.7.0/gems/rake-13.0.3/lib/rake/application.rb:116:in `block (2 levels) in top_level'

2022-12-20T02:00:03.327 app[be5939b8] nrt [info] /app/vendor/bundle/ruby/2.7.0/gems/rake-13.0.3/lib/rake/application.rb:116:in `each'

2022-12-20T02:00:03.327 app[be5939b8] nrt [info] /app/vendor/bundle/ruby/2.7.0/gems/rake-13.0.3/lib/rake/application.rb:116:in `block in top_level'

2022-12-20T02:00:03.327 app[be5939b8] nrt [info] /app/vendor/bundle/ruby/2.7.0/gems/rake-13.0.3/lib/rake/application.rb:125:in `run_with_threads'

2022-12-20T02:00:03.327 app[be5939b8] nrt [info] /app/vendor/bundle/ruby/2.7.0/gems/rake-13.0.3/lib/rake/application.rb:110:in `top_level'

2022-12-20T02:00:03.327 app[be5939b8] nrt [info] /app/vendor/bundle/ruby/2.7.0/gems/railties-6.1.3.2/lib/rails/commands/rake/rake_command.rb:24:in `block (2 levels) in perform'

2022-12-20T02:00:03.327 app[be5939b8] nrt [info] /app/vendor/bundle/ruby/2.7.0/gems/rake-13.0.3/lib/rake/application.rb:186:in `standard_exception_handling'

2022-12-20T02:00:03.327 app[be5939b8] nrt [info] /app/vendor/bundle/ruby/2.7.0/gems/railties-6.1.3.2/lib/rails/commands/rake/rake_command.rb:24:in `block in perform'

2022-12-20T02:00:03.327 app[be5939b8] nrt [info] /app/vendor/bundle/ruby/2.7.0/gems/rake-13.0.3/lib/rake/rake_module.rb:59:in `with_application'

2022-12-20T02:00:03.327 app[be5939b8] nrt [info] /app/vendor/bundle/ruby/2.7.0/gems/railties-6.1.3.2/lib/rails/commands/rake/rake_command.rb:18:in `perform'

2022-12-20T02:00:03.327 app[be5939b8] nrt [info] /app/vendor/bundle/ruby/2.7.0/gems/railties-6.1.3.2/lib/rails/command.rb:52:in `invoke'

2022-12-20T02:00:03.327 app[be5939b8] nrt [info] /app/vendor/bundle/ruby/2.7.0/gems/railties-6.1.3.2/lib/rails/commands.rb:18:in `<main>'

2022-12-20T02:00:03.327 app[be5939b8] nrt [info] /app/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'

2022-12-20T02:00:03.327 app[be5939b8] nrt [info] /app/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'

2022-12-20T02:00:03.327 app[be5939b8] nrt [info] /app/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'

2022-12-20T02:00:03.327 app[be5939b8] nrt [info] /app/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'

2022-12-20T02:00:03.327 app[be5939b8] nrt [info] /app/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'

2022-12-20T02:00:03.327 app[be5939b8] nrt [info] Tasks: TOP => fly:server

2022-12-20T02:00:03.327 app[be5939b8] nrt [info] (See full trace by running task with --trace)

2022-12-20T02:00:03.881 app[be5939b8] nrt [info] Starting clean up.

Try making a one line change to your .dockerignore file:

Change:

!tmp/pids

To:

!tmp/pids/.keep

If that works for you, I’ll change the template that flyctl uses.

1 Like

It worked. Wow. Spent half a day on this. Thank you.

The fix will be in the next version of flyctl: Ensure deployed tmp/pids directory is empty by rubys · Pull Request #1528 · superfly/flyctl · GitHub

1 Like

The issue came back:

2023-03-07T05:14:27.234 app[] nrt [info] A server is already running. Check /app/tmp/pids/server.pid.
2023-03-07T05:14:27.234 app[] nrt [info] Exiting
2023-03-07T05:14:27.245 app[] nrt [info] rails aborted!
2023-03-07T05:14:27.245 app[] nrt [info] Command failed with status (1): [bin/rails server...]

Here is my partial .gitignore:

# Ignore pidfiles, but keep the directory.
!/tmp/pids/.keep
!tmp/pids/.keep

And the flyctl version:

flyctl v0.0.475 linux/amd64 Commit: a5acc104 BuildDate: 2023-03-03T18:38:39Z

Here’s how that section should look:

# Ignore pidfiles, but keep the directory.
/tmp/pids/*
!/tmp/pids/
!/tmp/pids/.keep

Thanks. But somehow that didn’t work so I tried different combinations.

I just once again updated the file as per your help but the errors remained the same (the timestamp is just now):

023-03-07T06:14:44.266 app[] nrt [info] => Run `bin/rails server --help` for more startup options
2023-03-07T06:14:44.268 app[] nrt [info] A server is already running. Check /app/tmp/pids/server.pid.
2023-03-07T06:14:44.268 app[] nrt [info] Exiting
2023-03-07T06:14:44.276 app[] nrt [info] rails aborted!
2023-03-07T06:14:44.276 app[] nrt [info] Command failed with status (1): [bin/rails server...]

The entire .gitignore:

# See https://help.github.com/articles/ignoring-files for more about ignoring files.
#
# If you find yourself ignoring temporary files generated by your text editor
# or operating system, you probably want to add a global ignore instead:
#   git config --global core.excludesfile '~/.gitignore_global'

# Ignore bundler config.
/.bundle

# Ignore all logfiles and tempfiles.
/log/*
/tmp/*
!/log/.keep
!/tmp/.keep

# Ignore pidfiles, but keep the directory.
/tmp/pids/*
!/tmp/pids/
!/tmp/pids/.keep

# Ignore uploaded files in development.
/storage/*
!/storage/.keep
/tmp/storage/*
!/tmp/storage/
!/tmp/storage/.keep

/public/assets

# Ignore master key for decrypting credentials and more.
/config/master.key

.env*
vendor/bundle
tmp/storage

I missed that the first time. The file that matters here is .dockerignore

Oh! My bad. Thank you very much.