Error Deploying Rails on Dokku - on Digital Ocean
Asked Answered
S

3

7

I'm trying to run dokku on DigitalOcean with a sample rails app, but when I deploy, I get this error:

      Puma starting in single mode...
       * Version 3.12.1 (ruby 2.6.3-p62), codename: Llamas in Pajamas
       * Min threads: 5, max threads: 5
       * Environment: production
       * Listening on tcp://0.0.0.0:5000
       bundler: failed to load command: rackup (/app/vendor/bundle/ruby/2.6.0/bin/rackup)
       Errno::ENOENT: No such file or directory @ rb_sysopen - tmp/pids/server.pid
         /app/vendor/bundle/ruby/2.6.0/gems/puma-3.12.1/lib/puma/launcher.rb:133:in `initialize'
         /app/vendor/bundle/ruby/2.6.0/gems/puma-3.12.1/lib/puma/launcher.rb:133:in `open'
         /app/vendor/bundle/ruby/2.6.0/gems/puma-3.12.1/lib/puma/launcher.rb:133:in `write_pid'
         /app/vendor/bundle/ruby/2.6.0/gems/puma-3.12.1/lib/puma/launcher.rb:106:in `write_state'
         /app/vendor/bundle/ruby/2.6.0/gems/puma-3.12.1/lib/puma/single.rb:103:in `run'
         /app/vendor/bundle/ruby/2.6.0/gems/puma-3.12.1/lib/puma/launcher.rb:186:in `run'
         /app/vendor/bundle/ruby/2.6.0/gems/puma-3.12.1/lib/rack/handler/puma.rb:73:in `run'
         /app/vendor/bundle/ruby/2.6.0/gems/rack-2.0.7/lib/rack/server.rb:297:in `start'
         /app/vendor/bundle/ruby/2.6.0/gems/rack-2.0.7/lib/rack/server.rb:148:in `start'
         /app/vendor/bundle/ruby/2.6.0/gems/rack-2.0.7/bin/rackup:4:in `<top (required)>'
         /app/vendor/bundle/ruby/2.6.0/bin/rackup:23:in `load'
         /app/vendor/bundle/ruby/2.6.0/bin/rackup:23:in `<top (required)>'

I've looked through other support sites for a similar error - but it looks like the web app container starts then immediately stops.

I can see my database container running, and I see a container with dokkku/myapp:latest - and it's never up for more than a few seconds.

Anyone have an idea why?

Sara answered 3/9, 2019 at 2:8 Comment(0)
S
0

Not sure why this is an issue - but my .gitignore file (a default, I think) kept the /tmp folder, but ignored contents, so there wasn't a /tmp/pids in the repo, and there probably wasn't on the web container.

I forced the /tmp/pids folder into the repo... and now it works!

Sara answered 3/9, 2019 at 14:29 Comment(3)
Glad you got it working buddy! You probably don't want to be comitting the /tmp folder into the repo though - by definition it's files that aren't consistent. The pids file will be different locally and on the server, and different every time you run the application. You may encounter issues when deploying the app if you do it like this.Baines
FYI - not adding the tmp folder to a repo, just an empty folder for /tmp/pids and not checking in any contents.Sara
For me /tmp/pids/.keep file was missing as it is an older project and git skipped creating /tmp/pids even as it was flagged as must exist in .gitignore file.Yashmak
U
6

Rails 6 added a line to config/puma.rb that specifies the location of the pidfile (line 20 by default, at the time of my writing this), with the default value as follows:

pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" }

I ran into the same problem you mentioned, and addressed it by changing that line to

pidfile ENV.fetch("PIDFILE") { "server.pid" }

Removing the tmp dir from both .gitignore and .dockerignore (in my case, since my app is Dockerized) also worked, but having tmp dirs in git and on my production containers smelled funny, so I opted for the aforementioned approach.

Either way, I'm glad you got it working! ... hope this helps

PS - you may want to consider selecting one of these answers as correct (even if it's an answer you provided) Happy coding!

Unhorse answered 3/10, 2019 at 6:50 Comment(1)
FYI - I'm not saying you should check in the contents - just to have the structure there. Now is even that going too far? - I can see both sides to that issue - it makes sense for PIDS to be in a tmp folder. I would probably say Rails shouldn't be dictating a structure of a folder that is excluded from repos.Sara
B
0

tmp/pids/server.pid is the file Rails uses to check if it is already running, and to check what process ID it is running with.

IIRC with Dokku, there is a user called dokku that all Dokku processes run under - make sure that user (or whichever user Dokku/the Rails app is running under), has read/write permission on that directory.

Alternatively, you may be able to just call touch tmp/pids/server.pid to create the file so that Rails can use it.

Baines answered 3/9, 2019 at 8:9 Comment(1)
I set this up as a one click setup on Digital Ocean - and didn't give the 'dokku' user any special privileges - should that user be running as an admin? -- and thanks, I never thought this could be a permission issue.Sara
S
0

Not sure why this is an issue - but my .gitignore file (a default, I think) kept the /tmp folder, but ignored contents, so there wasn't a /tmp/pids in the repo, and there probably wasn't on the web container.

I forced the /tmp/pids folder into the repo... and now it works!

Sara answered 3/9, 2019 at 14:29 Comment(3)
Glad you got it working buddy! You probably don't want to be comitting the /tmp folder into the repo though - by definition it's files that aren't consistent. The pids file will be different locally and on the server, and different every time you run the application. You may encounter issues when deploying the app if you do it like this.Baines
FYI - not adding the tmp folder to a repo, just an empty folder for /tmp/pids and not checking in any contents.Sara
For me /tmp/pids/.keep file was missing as it is an older project and git skipped creating /tmp/pids even as it was flagged as must exist in .gitignore file.Yashmak

© 2022 - 2024 — McMap. All rights reserved.