Skip to content

Commit

Permalink
Merge 0a14ebe into f77585c
Browse files Browse the repository at this point in the history
  • Loading branch information
nimmolo committed Feb 25, 2024
2 parents f77585c + 0a14ebe commit c641e24
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 16 deletions.
4 changes: 3 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ gem("jbuilder")
gem("bcrypt", "~> 3.1.7")

# Use unicorn as the app server
gem("unicorn")
# gem("unicorn")
# Use puma as the app server
gem("puma")

# Use Capistrano for deployment
# gem("capistrano", group: :development)
Expand Down
9 changes: 3 additions & 6 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ GEM
actionview (>= 5.0.0)
activesupport (>= 5.0.0)
json (2.7.1)
kgio (2.11.4)
language_server-protocol (3.17.0.3)
libv8-node (18.16.0.0-arm64-darwin)
libv8-node (18.16.0.0-x86_64-darwin)
Expand Down Expand Up @@ -196,6 +195,8 @@ GEM
psych (4.0.6)
stringio
public_suffix (5.0.4)
puma (6.4.2)
nio4r (~> 2.0)
racc (1.7.3)
rack (2.2.8)
rack-session (1.0.2)
Expand Down Expand Up @@ -225,7 +226,6 @@ GEM
thor (~> 1.0, >= 1.2.2)
zeitwerk (~> 2.6)
rainbow (3.1.1)
raindrops (0.20.1)
rake (13.1.0)
rbtree (0.4.6)
rdoc (6.6.2)
Expand Down Expand Up @@ -306,9 +306,6 @@ GEM
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.5.0)
unicorn (6.1.0)
kgio (~> 2.6)
raindrops (~> 0.7)
uniform_notifier (1.16.0)
web-console (4.2.1)
actionview (>= 6.0.0)
Expand Down Expand Up @@ -383,6 +380,7 @@ DEPENDENCIES
newrelic_rpm
nokogiri (>= 1.13.10)
psych (~> 4)
puma
rack (~> 2)
rails-controller-testing
rails-html-sanitizer (>= 1.4.4)
Expand All @@ -403,7 +401,6 @@ DEPENDENCIES
stimulus-rails
terser
turbo-rails
unicorn
web-console
webmock
xmlrpc
Expand Down
19 changes: 12 additions & 7 deletions config/etc/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ http {
# This just says "bad_user_agent = true if a robot makes a non-api request".
map $http_user_agent $robot {
default 0;
~Brightbot 1;
~Bytespider 1;
~DataForSeoBot 1;
~Go-http-client 1;
Expand All @@ -81,18 +82,18 @@ http {
"1:0" 1;
}

upstream unicorn {
upstream puma {
# fail_timeout=0 means we always retry an upstream even if it failed
# to return a good HTTP response (in case the Unicorn master nukes a
# 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/unicorn.sock fail_timeout=0;
server unix:/var/web/mo/tmp/sockets/puma.sock fail_timeout=0;
}

# Change www.mushroomobserver.org to www.mushroomobserver.org
# Change www.mushroomobserver.org to mushroomobserver.org
server {
server_name www.mushroomobserver.org;
return 301 $scheme://mushroomobserver.org$request_uri;

listen 80; # managed by Certbot

# (add "http2" after "ssl" in the following line)
Expand All @@ -119,7 +120,9 @@ http {

# See map statement above for definition of $bad_user_agent.
# The value of this mapped variable is calculated for each request.
if ($bad_user_agent) { return 403; }
if ($bad_user_agent) {
return 403;
}

# this is equivalent of 10 max-sized images
client_max_body_size 200M;
Expand Down Expand Up @@ -155,7 +158,7 @@ http {
limit_req zone=one burst=10;

# this is where unicorn is listening
proxy_pass http://unicorn;
# proxy_pass http://unicorn;

# track progress of all POST requests at this location, MUST BE LAST!
# track_uploads upload 10s;
Expand All @@ -167,6 +170,8 @@ http {
rewrite "^/images/orig/((\d{1,6}|1[01]\d\d\d\d\d)\.\w+)$" https://storage.googleapis.com/mo-image-archive-bucket/orig/$1?;

# serve all the rest of the images from Alan's image server
# rewrite "^/images/(.*)/(.*)$" https://images.mushroomobserver.org/$1/$2?;

# being careful to permit routes like `/images/21345/vote`
rewrite "^/images/(\w*)/(\d*\.\w+)$" https://images.mushroomobserver.org/$1/$2?;
}
Expand Down
52 changes: 52 additions & 0 deletions config/etc/puma.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
[Unit]
Description=Mushroom Observer Puma HTTP Server
After=network.target

# Uncomment for socket activation (see below)
# Requires=puma.socket

[Service]
# Puma supports systemd's `Type=notify` and watchdog service
# monitoring, as of Puma 5.1 or later.
# On earlier versions of Puma or JRuby, change this to `Type=simple` and remove
# the `WatchdogSec` line.
Type=notify

# If your Puma process locks up, systemd's watchdog will restart it within seconds.
WatchdogSec=10

# Preferably configure a non-privileged user
# User=

# The path to your application code root directory.
# Also replace the "<YOUR_APP_PATH>" placeholders below with this path.
# Example /home/username/myapp
WorkingDirectory=/var/web/mo

PIDFile=/var/web/mo/puma.pid
Environment=RAILS_ENV=production
# Helpful for debugging socket activation, etc.
# Environment=PUMA_DEBUG=1

# SystemD will not run puma even if it is in your path. You must specify
# an absolute URL to puma. For example /usr/local/bin/puma
# Alternatively, create a binstub with `bundle binstubs puma --path ./sbin` in the WorkingDirectory
# ExecStart=/<FULLPATH>/bin/puma -C /var/web/mo/puma.rb

# Variant: Rails start.
# ExecStart=/<FULLPATH>/bin/puma -C /var/web/mo/config/puma.rb ../config.ru

# Variant: Use `bundle exec puma` instead of binstub
# Variant: Specify directives inline.
# ExecStart=/<FULLPATH>/puma -b tcp://0.0.0.0:9292 -b ssl://0.0.0.0:9293?key=key.pem&cert=cert.pem

# Working example for Rails from the web:
ExecStart=/var/web/mo/bin/bundle exec puma -e production -C ./config/puma.rb config.ru
# For switching to Puma with a rolling restart, replace <USR1> with a different user than the one running Unicorn.
ExecReload=/bin/kill -s $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID

Restart=always

[Install]
WantedBy=multi-user.target
2 changes: 1 addition & 1 deletion script/unicorn → config/etc/unicorn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/bin/bash

set -e

Expand Down
23 changes: 23 additions & 0 deletions config/puma.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

workers Integer(ENV["WEB_CONCURRENCY"] || 3)
threads_count = Integer(ENV["MAX_THREADS"] || 1)
threads threads_count, threads_count

# preload_app!
prune_bundler

rackup DefaultRackup if defined?(DefaultRackup)
port ENV["PORT"] || 3000
environment ENV["RAILS_ENV"] || "production"

# directory "/var/web/mo"
# redirect_stderr "/var/web/mo/log/puma.stderr.log"
# redirect_stdout "/var/web/mo/log/puma.stdout.log"
# bind "/var/web/mo/tmp/sockets/puma.sock"
# pidfile "/var/web/mo/tmp/pids/puma.pid"

# on_worker_boot do
# ActiveRecord::Base.establish_connection
# end

2 changes: 1 addition & 1 deletion script/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ echo Installing bundle... && bundle install && \
echo Checking for migrations... && rake db:migrate && \
echo Updating translations... && rake lang:update && \
echo Precompiling assets... && rake assets:precompile && \
echo Reloading unicorn... && /etc/init.d/unicorn reload && \
# echo Reloading unicorn... && /etc/init.d/unicorn reload && \
echo Tagging repo with $tag... && git tag $tag && \
echo Pushing new tag... && git push --tags && \
echo SUCCESS\!

0 comments on commit c641e24

Please sign in to comment.