Skip to content

Instantly share code, notes, and snippets.

@nikneroz
Created May 30, 2019 11:03
Show Gist options
  • Save nikneroz/9cc43fb9d8004353599a3674887554a8 to your computer and use it in GitHub Desktop.
Save nikneroz/9cc43fb9d8004353599a3674887554a8 to your computer and use it in GitHub Desktop.
Ubuntu Rails deployments(RVM, Puma, Mina, Nginx)
#!/usr/bin/env puma
# start puma with:
# RAILS_ENV=production bundle exec puma -C ./config/puma.rb
# threads_count = ENV.fetch("RAILS_MAX_THREADS") { 16 }
rails_env = 'production'
app_path = '/home/deploy/my_app'
current_path = "#{app_path}/current"
shared_path = "#{app_path}/shared"
log_path = {
out: "#{shared_path}/log/puma-#{rails_env}.stdout.log"
error: "#{shared_path}/log/puma-#{rails_env}.stderr.log"
}
plugin :tmp_restart
workers 4
threads 0, 8
directory current_path
environment rails_env
# daemonize true
pidfile "#{current_path}/tmp/pids/puma-#{rails_env}.pid"
state_path "#{current_path}/tmp/pids/puma-#{rails_env}.state"
stdout_redirect(log_path[:out], log_path[:error], true)
bind "unix://#{shared_path}/tmp/sockets/#{rails_env}.sock"
[Unit]
Description=Puma HTTP Server
After=network.target
# Uncomment for socket activation (see below)
# Requires=puma.sock
[Service]
# Foreground process (do not use --daemon in ExecStart or config.rb)
Type=simple
# Preferably configure a non-privileged user
User=deploy
# The path to the puma application root
# Also replace the "<WD>" place holders below with this path.
WorkingDirectory=/home/deploy/my_app/current
# Helpful for debugging socket activation, etc.
# Environment=PUMA_DEBUG=1
# The command to start Puma. This variant uses a binstub generated via
# `bundle binstubs puma --path ./sbin` in the WorkingDirectory
# (replace "<WD>" below)
#ExecStart=<WD>/sbin/puma -b tcp://0.0.0.0:9292 -b ssl://0.0.0.0:9293?key=key.pem&cert=cert.pem
# Variant: Use config file with `bind` directives instead:
ExecStart=/home/deploy/.rvm/rubies/ruby-2.6.1/bin/bundle exec puma -C /home/deploy/my_app/current/config/puma.rb
# Variant: Use `bundle exec --keep-file-descriptors puma` instead of binstub
Restart=always
[Install]
WantedBy=multi-user.target

RVM wrappers

rvm alias create my_app 2.6.1@my_app
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment