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.

Ramon Marques
  • 3,046
  • 2
  • 23
  • 34

3 Answers3

50

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

mkdir -p tmp/pids
Nate T
  • 2,658
  • 1
  • 20
  • 14
Ramon Marques
  • 3,046
  • 2
  • 23
  • 34
  • 3
    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? – DannyB Jan 27 '20 at 10:11
  • 7
    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. – Harm de Wit Mar 25 '20 at 19:21
  • 3
    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. – jpw Oct 11 '20 at 02:52
  • 4
    `mkdir -p tmp/pids` create recursively – 7urkm3n Nov 09 '20 at 08:33
  • 1
    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. – Barry Jan 13 '21 at 13:37
9

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
kangkyu
  • 5,252
  • 3
  • 34
  • 36
  • I feel this is the better solution (although I confess I needed a fast fix so I manually created the directory ) – iconoclast Feb 24 '22 at 02:26
3

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

require "fileutils"
FileUtils.mkdir_p("tmp/pids")
Dorian
  • 7,749
  • 4
  • 38
  • 57