No such file or directory @ rb_sysopen - tmp/pids/puma.pid
Asked Answered
P

5

23

I'm trying to start puma, but at the last step it fails like this:

16:38:09 web.1  | /home/ramonpm/.rvm/gems/ruby-2.2.7/gems/puma-3.9.1/lib/puma/launcher.rb:130:in `initialize': No such file or directory @ rb_sysopen - tmp/pids/puma.pid (Errno::ENOENT)
16:38:09 web.1  |   from /home/ramonpm/.rvm/gems/ruby-2.2.7/gems/puma-3.9.1/lib/puma/launcher.rb:130:in `open'
16:38:09 web.1  |   from /home/ramonpm/.rvm/gems/ruby-2.2.7/gems/puma-3.9.1/lib/puma/launcher.rb:130:in `write_pid'
16:38:09 web.1  |   from /home/ramonpm/.rvm/gems/ruby-2.2.7/gems/puma-3.9.1/lib/puma/launcher.rb:103:in `write_state'
16:38:09 web.1  |   from /home/ramonpm/.rvm/gems/ruby-2.2.7/gems/puma-3.9.1/lib/puma/single.rb:92:in `run'
16:38:09 web.1  |   from /home/ramonpm/.rvm/gems/ruby-2.2.7/gems/puma-3.9.1/lib/puma/launcher.rb:174:in `run'
16:38:09 web.1  |   from /home/ramonpm/.rvm/gems/ruby-2.2.7/gems/puma-3.9.1/lib/puma/cli.rb:77:in `run'
16:38:09 web.1  |   from /home/ramonpm/.rvm/gems/ruby-2.2.7/gems/puma-3.9.1/bin/puma:10:in `<top (required)>'
16:38:09 web.1  |   from /home/ramonpm/.rvm/gems/ruby-2.2.7/bin/puma:23:in `load'
16:38:09 web.1  |   from /home/ramonpm/.rvm/gems/ruby-2.2.7/bin/puma:23:in `<main>'
16:38:09 web.1  |   from /home/ramonpm/.rvm/gems/ruby-2.2.7/bin/ruby_executable_hooks:15:in `eval'
16:38:09 web.1  |   from /home/ramonpm/.rvm/gems/ruby-2.2.7/bin/ruby_executable_hooks:15:in `<main>'
16:38:09 web.1  | exited with code 1
16:38:09 system | sending SIGTERM to all processes

Couldn't find a solution somewhere else, they are all related to different things.

Perturb answered 17/10, 2018 at 19:45 Comment(0)
P
52

Could solve it manually creating the necessary folders, then the server process could create the pid file.

mkdir -p tmp/pids
Perturb answered 17/10, 2018 at 19:45 Comment(5)
Isn't it weird that it needs to be solved manually, while rails uses tmp/pids/server.pid as the default location for puma pidfile?Nutter
Rails automatically creates the folder during initialization when you start the server with bundle exec rails server (puma). This folder creation will be skipped if you start the server with bundle exec puma, resulting in the error. It would be nice though if both commands had the same result, saves some errors like these.Seat
Just as an aside, if your app needs to be pushed to a server (for example Heroku), and if you previously had /tmp/* in your .gitignore you need to add a .keep file to the pids folder, re-add the pids folder (and the .keep file) to the git repo using git add -f, and add an exclusion to .gitignore to not exclude the pids folder and the .keep file.Soche
mkdir -p tmp/pids create recursivelyMontiel
Don't forget to update your .dockerignore file when you update your .gitignore to allow the new path to make it into your docker image.Subterfuge
M
10

This error happened when I first added puma.rb file by rails app:update to rails 5.2 for a Heroku app.

# Specifies the `pidfile` that Puma will use.
pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" }

Resolved by adding tmp/pids/.keep file,

$ touch tmp/pids/.keep

And updating .gitignore file as follows.

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

# Ignore pidfiles, but keep the directory.
/tmp/pids/*
!/tmp/pids/
!/tmp/pids/.keep
Matutinal answered 9/1, 2022 at 7:31 Comment(2)
I feel this is the better solution (although I confess I needed a fast fix so I manually created the directory 😄 )Rally
You need to add tmp/pids/.keep to git by running git add -f tmp/pids/.keep too.Disburden
P
3

You can add that in your config/puma.rb:

require "fileutils"
FileUtils.mkdir_p("tmp/pids")
Propensity answered 11/12, 2021 at 9:8 Comment(0)
P
0

A better answer would be to not be calling puma directly but calling rails server.

e.g. instead of:

bundle exec puma -p $PORT -C ./config/puma.rb

Do:

unset PORT && bundle exec rails server

For instance in a Procfile/Procfile.dev

web: unset PORT && bundle exec rails server
css: yarn build:css --watch
worker: bundle exec rails jobs:work
Propensity answered 18/1 at 11:34 Comment(0)
M
0

I was running into the same issue while trying to use Rails on Docker. When I run the command docker-compose up it would startup and the produce this error:

/home/app/.rvm/gems/ruby-3.3.0/gems/puma-6.4.2/lib/puma/launcher.rb:312:in `write': No such file or directory @ rb_sysopen - tmp/pids/server.pid (Errno::ENOENT)

However, I noticed that in the config/puma.rb it had the following line:

# Specifies the `pidfile` that Puma will use.
pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" }

Commenting out this line to keep the pidfile from being fetched, and this resolved my issue.

My stack is as follows:

  • ruby: 3.3.0
  • rails: 7.1.3.3
  • puma: 6.4.2
  • docker: 24.0.6
Muttra answered 25/6 at 19:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.