Puma starting in single mode but not really start - ruby-on-rails

I'm configuring Jenkins to deploy in production my rails application.
At the end of jenkings, i can see:
+ bin/bundle exec puma -C config/puma.rb
Puma starting in single mode...
* Version 3.4.0 (ruby 2.2.2-p95), codename: Owl Bowl Brawl
* Min threads: 0, max threads: 16
* Environment: production
* Daemonizing...
Finished: SUCCESS
After the script, puma is not running ...
config/puma.rb
threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }.to_i
threads threads_count, threads_count
railsenv = 'production'
directory '/var/lib/jenkins/workspace/MyRailsApp'
environment railsenv
daemonize true
pidfile "/tmp/pids/puma-#{railsenv}.pid"
state_path "/tmp/pids/puma-#{railsenv}.state"
threads 0, 16
bind "unix:///tmp/my-rails-app.sock"
port ENV.fetch("PORT") { 3000 }
preload_app!
on_worker_boot do
ActiveRecord::Base.establish_connection if defined?(ActiveRecord)
end
plugin :tmp_restart
What's the best way to start/restart puma with Jenkins ?

Related

not able to access localhost:3000 outside vmware

i am running webrick default ROR server inside vmware in ubuntu. i have host window as Window 10.but in window 10 browser i am not able to access the 0.0.0.0:3000 . i have ruby on rails code, how can i host in my own machine server?
in window10 browser i get error like-
[error][1]
[VMware and real host ip snapshot][2]
puma.rb
threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
threads threads_count, threads_count
port ENV.fetch("PORT") { 3000 }
environment ENV.fetch("RAILS_ENV") { "development" }
# Specifies the `pidfile` that Puma will use.
pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" }
plugin :tmp_restart
[1]: https://i.stack.imgur.com/N65uJ.png
[2]: https://i.stack.imgur.com/At2Rz.png

Puma server inside heroku container fails to connect to port

I have a docker container: (called Dockerfile.web, relevant parts)
ARG PORT=3000
ENV PORT=$PORT
EXPOSE $PORT
ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["rails", "server"]
Puma: config/puma.rb
before_fork do
ActiveRecord::Base.connection_pool.disconnect! if defined? ActiveRecord
end
on_worker_boot do
ActiveRecord::Base.establish_connection if defined? ActiveRecord
end
preload_app!
So when I run heroku container:push web followed by heroku container:release web, the app deploys, but the puma server doesn't come up b/c the port cannot be connected to:
Booting Puma
Rails 5.2.2 application starting in development
Run `rails server -h` for more startup options
Puma starting in cluster mode...
* Version 3.12.0 (ruby 2.6.0-p0), codename: Llamas in Pajamas
* Min threads: 5, max threads: 5
* Environment: development
* Process workers: 1
* Preloading application
* Listening on tcp://localhost:41626
Use Ctrl-C to stop
- Worker 0 (pid: 28) booted, phase: 0
Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
Stopping process with SIGKILL
I'm following the official guide but I haven't added the sections:
rackup DefaultRackup
port ENV['PORT'] || 3000
environment ENV['RACK_ENV'] || 'development'
Where could my error be? Any ideas?
I'm not sure why you left this part out:
port ENV['PORT'] || 3000
You can't pick your own port. Use the $PORT that Heroku gives you.
For people arriving here, the solution was to invoke the puma server directly from the docker CMD so that all the settings in the config file are applied. The reason is that on heroku, stuff like port is added dynamically, so container images (which are built out earlier) will not have those images. Somehow using the $PORT values inside Dockerfile also did not help. The solution was to do
CMD ["bundle", "exec", "puma", "-C", "config/puma.rb"]
# or if you prefer the bash style
CMD bundle exec puma -C config/puma.rb

The puma server freezes

I can not understand what the problem is. The app works perfectly after I start it. After a while of inactivity (around 5 min with no requests) the app stops responding when I send requests to it.
puma.rb:
threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }.to_i
threads threads_count, threads_count
port ENV.fetch("PORT") { 3000 }
environment ENV.fetch("RAILS_ENV") { "development" }
plugin :tmp_restart
This is what I get when I do this: ps aux | grep puma
user+ 4201 7.8 2.5 1197292 100560 ? Sl 15:41 0:04 puma 3.11.4 (tcp://0.0.0.0:3000) [backend]
user+ 4277 0.0 0.0 15476 1020 pts/20 S+ 15:42 0:00 grep --color=auto puma
ruby -v
ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-linux]
rails -v
Rails 5.1.6
OS Ubuntu 16.04 LTS
this is what your puma.rb should look like
workers Integer(ENV['WEB_CONCURRENCY'] || 2)
threads_count = Integer(ENV['RAILS_MAX_THREADS'] || 5)
threads threads_count, threads_count
preload_app!
rackup DefaultRackup
port ENV['PORT'] || 3000
environment ENV['RACK_ENV'] || 'development'
on_worker_boot do
ActiveRecord::Base.establish_connection
end

Why does htop show more threads than puma configuration?

My puma configuration:
#!/usr/bin/env puma
workers ENV.fetch("WEB_CONCURRENCY") { 2 }
threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
threads threads_count, threads_count
worker_timeout 30
preload_app!
port ENV['PORT'] || 80
environment ENV['RAILS_ENV'] || 'development'
rackup DefaultRackup
before_fork do
ActiveRecord::Base.connection_pool.disconnect! if defined?(ActiveRecord)
end
on_worker_boot do
ActiveRecord::Base.establish_connection if defined?(ActiveRecord)
end
The htop:
The number of threads should be 5, but the htop shows that there are 12 threads in each worker(process). BTW, I run the workers and htop in a docker container.
That confused me a lot, could somebody explain it?

Puma prints huge unruly output in terminal and runs slowly in development

What is going on with this dump when I am running Puma for my Rails server in development. I find my app starts being really slow in development and I have to restart the server every once and a while. So I'm curious about what is going on with this dump and how can I make my Puma server act better in development?
This is my Procfile
web: bundle exec puma -C config/puma.rb
This is my Puma.rb file
workers Integer(ENV['WEB_CONCURRENCY'] || 2)
threads_count = Integer(ENV['MAX_THREADS'] || 8)
threads threads_count, threads_count
preload_app!
rackup DefaultRackup
port ENV['PORT'] || 3000
environment ENV['RACK_ENV'] || 'development'
on_worker_boot do
ActiveRecord::Base.establish_connection
end

Resources