Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add puma webserver over thin #7581

Merged
merged 2 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .ruby-style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ AllCops:
- vendor/**/*
- ".git/**/*"
- bin/bundle
- bin/puma
- bin/pumactl
- bin/rubocop
- bin/sidekiq
- bin/sidekiqmon
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ gem 'maxmind-db', '~> 1.2.0'
gem 'mahoro', '~> 0.5'
gem 'nokogiri', '~> 1.16.7'
gem 'open4', '~> 1.3.0'
gem 'puma', '~> 6.4.2'
gem 'rack', '~> 2.2.9'
gem 'rack-utf8_sanitizer', '~> 1.9.1'
gem 'recaptcha', '~> 5.17.0', require: 'recaptcha/rails'
Expand All @@ -128,7 +129,6 @@ gem 'strip_attributes', git: 'https://github.com/mysociety/strip_attributes.git'
gem 'stripe', '~> 5.55.0'
gem 'syck', '~> 1.4.1', require: false
gem 'syslog_protocol', '~> 0.9.0'
gem 'thin', '~> 1.8.2'
gem 'vpim', '~> 24.2.20'
gem 'will_paginate', '~> 4.0.1'
gem 'xapian-full-alaveteli', '~> 1.4.22.1'
Expand Down
10 changes: 3 additions & 7 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ GEM
bigdecimal
rexml
crass (1.0.6)
daemons (1.4.1)
dalli (3.2.8)
dante (0.2.0)
date (3.3.4)
Expand All @@ -210,7 +209,6 @@ GEM
rake (>= 12.0.0, < 14.0.0)
docile (1.4.0)
erubi (1.13.0)
eventmachine (1.2.7)
exception_notification (4.5.0)
actionmailer (>= 5.2, < 8)
activesupport (>= 5.2, < 8)
Expand Down Expand Up @@ -392,6 +390,8 @@ GEM
coderay (~> 1.1)
method_source (~> 1.0)
public_suffix (6.0.0)
puma (6.4.2)
nio4r (~> 2.0)
racc (1.8.1)
rack (2.2.9)
rack-test (2.1.0)
Expand Down Expand Up @@ -539,10 +539,6 @@ GEM
syck (1.4.1)
syslog_protocol (0.9.2)
text (1.3.1)
thin (1.8.2)
daemons (~> 1.0, >= 1.0.9)
eventmachine (~> 1.0, >= 1.0.4)
rack (>= 1, < 3)
thor (1.3.1)
tilt (2.0.10)
timeout (0.4.1)
Expand Down Expand Up @@ -649,6 +645,7 @@ DEPENDENCIES
open4 (~> 1.3.0)
pg (~> 1.5.7)
pry (~> 0.14.2)
puma (~> 6.4.2)
rack (~> 2.2.9)
rack-utf8_sanitizer (~> 1.9.1)
rails (~> 7.0.8)
Expand Down Expand Up @@ -679,7 +676,6 @@ DEPENDENCIES
stripe-ruby-mock!
syck (~> 1.4.1)
syslog_protocol (~> 0.9.0)
thin (~> 1.8.2)
turbo-rails (~> 2.0.6)
uglifier (~> 4.2.0)
unicode (~> 0.4.4)
Expand Down
27 changes: 27 additions & 0 deletions bin/puma
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

#
# This file was generated by Bundler.
#
# The application 'puma' is installed as part of a gem, and
# this file is here to facilitate running it.
#

ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)

bundle_binstub = File.expand_path("bundle", __dir__)

if File.file?(bundle_binstub)
if File.read(bundle_binstub, 300).include?("This file was generated by Bundler")
load(bundle_binstub)
else
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
end
end

require "rubygems"
require "bundler/setup"

load Gem.bin_path("puma", "puma")
27 changes: 27 additions & 0 deletions bin/pumactl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

#
# This file was generated by Bundler.
#
# The application 'pumactl' is installed as part of a gem, and
# this file is here to facilitate running it.
#

ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)

bundle_binstub = File.expand_path("bundle", __dir__)

if File.file?(bundle_binstub)
if File.read(bundle_binstub, 300).include?("This file was generated by Bundler")
load(bundle_binstub)
else
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
end
end

require "rubygems"
require "bundler/setup"

load Gem.bin_path("puma", "pumactl")
16 changes: 0 additions & 16 deletions bin/thin

This file was deleted.

43 changes: 43 additions & 0 deletions config/puma.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
require 'concurrent-ruby'

require File.expand_path('load_env.rb', __dir__)

# This configuration file will be evaluated by Puma. The top-level methods that
# are invoked here are part of Puma's configuration DSL. For more information
# about methods provided by the DSL, see https://puma.io/puma/Puma/DSL.html.

# Puma can serve each request in a thread from an internal thread pool.
# The `threads` method setting takes two numbers: a minimum and maximum.
# Any libraries that use thread pools should be configured to match
# the maximum value specified for Puma. Default is set to 5 threads for minimum
# and maximum; this matches the default thread size of Active Record.
max_threads_count = ENV.fetch('RAILS_MAX_THREADS') { 5 }
min_threads_count = ENV.fetch('RAILS_MIN_THREADS') { max_threads_count }
threads min_threads_count, max_threads_count

# Specifies that the worker count should equal the number of processors in
# production.
if ENV['RAILS_ENV'] == 'production'
concurrency = ENV.fetch('WEB_CONCURRENCY') do
Concurrent.physical_processor_count
end
worker_count = Integer(concurrency)
workers worker_count if worker_count > 1
end

# Specifies the `worker_timeout` threshold that Puma will use to wait before
# terminating a worker in development environments.
worker_timeout 3600 if ENV.fetch('RAILS_ENV', 'development') == 'development'

# Specifies the `port` that Puma will listen on to receive requests; default is
# 3000.
port ENV.fetch('PORT') { 3000 }

# Specifies the `environment` that Puma will run in.
environment ENV.fetch('RAILS_ENV') { 'development' }

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

# Allow puma to be restarted by `bin/rails restart` command.
plugin :tmp_restart
23 changes: 23 additions & 0 deletions config/puma.service.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[Unit]
Description=<%= daemon_name %>
After=network.target

[Service]
Type=notify

WatchdogSec=10

User=<%= user %>
Group=<%= user %>
UMask=0002

WorkingDirectory=<%= vhost_dir %>/<%= vcspath %>

ExecStart=/bin/bash -lc 'bundle exec puma -C config/puma.rb'
ExecStop=/bin/bash -lc 'bundle exec pumactl stop -F config/puma.rb'

RestartSec=1
Restart=always

[Install]
WantedBy=multi-user.target
82 changes: 0 additions & 82 deletions config/sysvinit-thin.example

This file was deleted.

8 changes: 8 additions & 0 deletions doc/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Highlighted Features

* Switch application server from Thin to Puma (Graeme Porteous)
* Fix rendering invoices page when there are discounted Pro subscription (Graeme
Porteous)
* Drop support for Ruby 3.0 (Graeme Porteous)
Expand Down Expand Up @@ -93,6 +94,13 @@

bin/rails temp:migrate_public_body_categories

* _Required:_ This release transitions the application server from Thin to
Puma. Ensure to remove `/etc/init.d/alaveteli` or
`/etc/init.d/alaveteli-thin`, if either exists, and create the systemd service
for Puma. You can generate this by running `rake config_files:convert_daemon
DAEMON=puma.service`. For detailed instructions, refer to [the
documentation](https://alaveteli.org/docs/installing/cron_and_daemons/#puma).

* _Optional:_ Bodies with not many requests will automatically get tagged
`not_many_requests` as they are updated. If you want to automatically tag them
all in one go, run the following from the app root directory:
Expand Down
6 changes: 3 additions & 3 deletions lib/tasks/config_files.rake
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ namespace :config_files do
def daemons
[
{
path: '/etc/init.d',
name: 'thin',
template: 'config/sysvinit-thin.example',
path: '/etc/systemd/system',
name: 'puma.service',
template: 'config/puma.service.example',
condition: -> { ENV['RAILS_ENV'] == 'production' }
},
{
Expand Down
Empty file added tmp/pids/.keep
Empty file.
Loading