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

Switch server from unicorn to puma #1927

Merged
merged 15 commits into from
Feb 25, 2024
Merged

Switch server from unicorn to puma #1927

merged 15 commits into from
Feb 25, 2024

Conversation

nimmolo
Copy link
Contributor

@nimmolo nimmolo commented Feb 20, 2024

This PR is to help switch the production server from unicorn to puma, without turning on threading.


It follows the only complete guide I've found, but it's pretty old:
Migrating from unicorn to puma with no downtime

Current preferred way is to run Puma via systemd, not init.d
Note that there is no file /etc/systemd/system/unicorn.service on production, what we have is /etc/init.d/unicorn

  • Add gem puma in this branch
  • Configure /config/puma.rb in this branch
  • Configure /config/puma-dev.rb in this branch (in case Jason wants to run it locally)
  • Configure systemd service /config/etc/puma.service and copy to /etc/systemd/system/puma.service on production
  • Alter our /deploy.sh in this branch not to reload Unicorn
  • Modify config/etc/nginx.confin this branch to point to new Puma socket instead of Unicorn
    Check example of upstream and proxy_pass configs here
  upstream puma {
    # fail_timeout=0 means we always retry an upstream even if it failed
    # to return a good HTTP response (in case the Puma master nukes a
    # single worker for timing out)
    server unix:/var/web/mo/tmp/sockets/puma.sock fail_timeout=0;
  }

# also remove or fix proxy_pass: 

    location @app {
      ...
      # this is where puma is listening
      proxy_pass http://puma;

Deploy this PR. Then:

  • Copy /config/etc/nginx.conf to /etc/nginx/nginx.conf
  • sudo systemctl start puma.service so it's running alongside Unicorn
  • sudo systemctl status puma.service be sure it's running
  • sudo systemctl reload nginx (to listen to the Puma socket)
  • sudo systemctl stop unicorn.service (or maybe sudo uni stop, since there's no such thing as unicorn.service)
  • sudo systemctl disable unicorn.service (or maybe remove the init file in /etc/init.d/unicorn)
  • sudo systemctl enable puma.service

Reference:
Benefits of Switching from Unicorn to Puma
Puma docs: Configuration and Deployment
How Do I Know Whether My Rails App Is Thread-safe or Not?
Do we want to consider using Capistrano for deployment?

@nimmolo
Copy link
Contributor Author

nimmolo commented Feb 20, 2024

Step 1: Improve thread safety. PR #1932

@coveralls
Copy link
Collaborator

coveralls commented Feb 20, 2024

Coverage Status

coverage: 94.532%. remained the same
when pulling cf37548 on unicorn-to-puma
into 3286363 on main.

@mo-nathan
Copy link
Member

Was just thinking about this due to the outage this morning. Great to see progress here!

@nimmolo nimmolo marked this pull request as ready for review February 25, 2024 02:02
@pellaea pellaea merged commit 219b2e3 into main Feb 25, 2024
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants