Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass config file to Puma & Sinatra?

I have a Sinatra app that's deployed to Heroku.

I want to configure Puma via a puma.rb config file to have multiple workers, but both examples from the readme only show how to pass a 'server name' to the Procfile, but it doesn't show how to pass a config:

Method 1

bundle exec ruby app.rb -s puma

Method 2

require 'sinatra'
configure { set :server, :puma }

There's all the methods listed here which all suffer the same problem: https://github.com/puma/puma/issues/13#issuecomment-7391148


I have my configuration here in puma.rb:

workers Integer(ENV['WEB_CONCURRENCY'] || 2)
threads_count = Integer(ENV['THREAD_COUNT'] || 5)

threads threads_count, threads_count

Here's my config.ru if that helps:

require './app'
run Sinatra::Application

I actually tried doing this instead in Procfile:

bundle exec puma -c puma.rb

Which works perfect locally but then dies in production, but no logs are generated so I have no idea what's wrong.

like image 568
Tallboy Avatar asked Nov 15 '25 06:11

Tallboy


1 Answers

I solved the problem as such (the problem was I was missing the rest of the code in puma.rb config)

Procfile

web: bundle exec puma -C puma.rb

puma.rb

workers Integer(ENV['WEB_CONCURRENCY'] || 2)
threads_count = Integer(ENV['THREAD_COUNT'] || 5)
threads threads_count, threads_count

rackup      DefaultRackup
port        ENV['PORT']     || 3000
environment ENV['RACK_ENV'] || 'development'

config.ru

require './app'
run Sinatra::Application
like image 199
Tallboy Avatar answered Nov 17 '25 21:11

Tallboy