update environments/production.rb add unicorn.rb, nemo.sh
This commit is contained in:
1
Gemfile
1
Gemfile
@@ -18,6 +18,7 @@ gem 'coffee-rails', '~> 4.2'
|
|||||||
# gem 'therubyracer', platforms: :ruby
|
# gem 'therubyracer', platforms: :ruby
|
||||||
gem 'unicorn'
|
gem 'unicorn'
|
||||||
gem 'execjs'
|
gem 'execjs'
|
||||||
|
gem 'rack', '~> 2.0.0'
|
||||||
gem 'therubyracer'
|
gem 'therubyracer'
|
||||||
platform :ruby do
|
platform :ruby do
|
||||||
gem 'pg'
|
gem 'pg'
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ set :keep_releases, 5
|
|||||||
set :linked_files, %w{config/database.yml config/secrets.yml}
|
set :linked_files, %w{config/database.yml config/secrets.yml}
|
||||||
|
|
||||||
# dirs we want symlinking to shared
|
# dirs we want symlinking to shared
|
||||||
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
|
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system pids sockets}
|
||||||
|
|
||||||
# what specs should be run before deployment is allowed to
|
# what specs should be run before deployment is allowed to
|
||||||
# continue, see lib/capistrano/tasks/run_tests.cap
|
# continue, see lib/capistrano/tasks/run_tests.cap
|
||||||
|
|||||||
61
config/deploy/production.rb.save
Normal file
61
config/deploy/production.rb.save
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
# server-based syntax
|
||||||
|
# ======================
|
||||||
|
# Defines a single server with a list of roles and multiple properties.
|
||||||
|
# You can define all roles on a single server, or split them:
|
||||||
|
|
||||||
|
# server "example.com", user: "deploy", roles: %w{app db web}, my_property: :my_value
|
||||||
|
# server "example.com", user: "deploy", roles: %w{app web}, other_property: :other_value
|
||||||
|
# server "db.example.com", user: "deploy", roles: %w{db}
|
||||||
|
/deploy/production.rb:
|
||||||
|
|
||||||
|
|
||||||
|
# role-based syntax
|
||||||
|
# ==================
|
||||||
|
|
||||||
|
# Defines a role with one or multiple servers. The primary server in each
|
||||||
|
# group is considered to be the first unless any hosts have the primary
|
||||||
|
# property set. Specify the username and a domain or IP for the server.
|
||||||
|
# Don't use `:all`, it's a meta role.
|
||||||
|
|
||||||
|
# role :app, %w{deploy@example.com}, my_property: :my_value
|
||||||
|
# role :web, %w{user1@primary.com user2@additional.com}, other_property: :other_value
|
||||||
|
# role :db, %w{deploy@example.com}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Configuration
|
||||||
|
# =============
|
||||||
|
# You can set any configuration variable like in config/deploy.rb
|
||||||
|
# These variables are then only loaded and set in this stage.
|
||||||
|
# For available Capistrano configuration variables see the documentation page.
|
||||||
|
# http://capistranorb.com/documentation/getting-started/configuration/
|
||||||
|
# Feel free to add new variables to customise your setup.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Custom SSH Options
|
||||||
|
# ==================
|
||||||
|
# You may pass any option but keep in mind that net/ssh understands a
|
||||||
|
# limited set of options, consult the Net::SSH documentation.
|
||||||
|
# http://net-ssh.github.io/net-ssh/classes/Net/SSH.html#method-c-start
|
||||||
|
#
|
||||||
|
# Global options
|
||||||
|
# --------------
|
||||||
|
# set :ssh_options, {
|
||||||
|
# keys: %w(/home/rlisowski/.ssh/id_rsa),
|
||||||
|
# forward_agent: false,
|
||||||
|
# auth_methods: %w(password)
|
||||||
|
# }
|
||||||
|
#
|
||||||
|
# The server-based syntax can be used to override options:
|
||||||
|
# ------------------------------------
|
||||||
|
# server "example.com",
|
||||||
|
# user: "user_name",
|
||||||
|
# roles: %w{web app},
|
||||||
|
# ssh_options: {
|
||||||
|
# user: "user_name", # overrides user setting above
|
||||||
|
# keys: %w(/home/user_name/.ssh/id_rsa),
|
||||||
|
# forward_agent: false,
|
||||||
|
# auth_methods: %w(publickey password)
|
||||||
|
# # password: "please use keys"
|
||||||
|
# }
|
||||||
@@ -23,7 +23,7 @@ Rails.application.configure do
|
|||||||
# config.assets.css_compressor = :sass
|
# config.assets.css_compressor = :sass
|
||||||
|
|
||||||
# Do not fallback to assets pipeline if a precompiled asset is missed.
|
# Do not fallback to assets pipeline if a precompiled asset is missed.
|
||||||
config.assets.compile = false
|
config.assets.compile = true
|
||||||
|
|
||||||
# `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb
|
# `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb
|
||||||
|
|
||||||
@@ -55,7 +55,7 @@ Rails.application.configure do
|
|||||||
# Use a real queuing backend for Active Job (and separate queues per environment)
|
# Use a real queuing backend for Active Job (and separate queues per environment)
|
||||||
# config.active_job.queue_adapter = :resque
|
# config.active_job.queue_adapter = :resque
|
||||||
# config.active_job.queue_name_prefix = "nemo_encoder_#{Rails.env}"
|
# config.active_job.queue_name_prefix = "nemo_encoder_#{Rails.env}"
|
||||||
config.action_mailer.perform_caching = false
|
config.action_mailer.perform_caching = true
|
||||||
|
|
||||||
# Ignore bad email addresses and do not raise email delivery errors.
|
# Ignore bad email addresses and do not raise email delivery errors.
|
||||||
# Set this to true and configure the email server for immediate delivery to raise delivery errors.
|
# Set this to true and configure the email server for immediate delivery to raise delivery errors.
|
||||||
|
|||||||
69
config/nemo.sh
Normal file
69
config/nemo.sh
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
### BEGIN INIT INFO
|
||||||
|
# Provides: unicorn
|
||||||
|
# Required-Start: $all
|
||||||
|
# Required-Stop: $all
|
||||||
|
# Default-Start: 2 3 4 5
|
||||||
|
# Default-Stop: 0 1 6
|
||||||
|
# Short-Description: starts the unicorn app server
|
||||||
|
# Description: starts unicorn using start-stop-daemon
|
||||||
|
### END INIT INFO
|
||||||
|
|
||||||
|
set -e
|
||||||
|
USAGE="Usage: $0 <start|stop|restart|upgrade|rotate|force-stop>"
|
||||||
|
|
||||||
|
# app settings
|
||||||
|
USER="ubuntu"
|
||||||
|
APP_NAME="nemo_encoder_production"
|
||||||
|
APP_ROOT="/home/$USER/apps/$APP_NAME/current"
|
||||||
|
ENV="production"
|
||||||
|
|
||||||
|
# environment settings
|
||||||
|
PATH="/home/$USER/.rbenv/shims:/home/$USER/.rbenv/bin:$PATH"
|
||||||
|
CMD="/home/$USER/.rbenv/shims/unicorn_rails -c $APP_ROOT/config/unicorn.rb -E $ENV -D"
|
||||||
|
PID="$APP_ROOT/pids/unicorn.nemo.pid"
|
||||||
|
OLD_PID="$PID.oldbin"
|
||||||
|
|
||||||
|
|
||||||
|
cd $APP_ROOT || exit 1
|
||||||
|
|
||||||
|
sig () {
|
||||||
|
test -s "$PID" && kill -$1 `cat $PID`
|
||||||
|
}
|
||||||
|
|
||||||
|
oldsig () {
|
||||||
|
test -s $OLD_PID && kill -$1 `cat $OLD_PID`
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
case $1 in
|
||||||
|
start)
|
||||||
|
sig 0 && echo >&2 "Already running" && exit 0
|
||||||
|
echo "Starting $APP_NAME"
|
||||||
|
su - $USER -c "$CMD"
|
||||||
|
;;
|
||||||
|
stop)
|
||||||
|
echo "Stopping $APP_NAME"
|
||||||
|
sig QUIT && exit 0
|
||||||
|
echo >&2 "Not running"
|
||||||
|
;;
|
||||||
|
force-stop)
|
||||||
|
echo "Force stopping $APP_NAME"
|
||||||
|
sig TERM && exit 0
|
||||||
|
echo >&2 "Not running"
|
||||||
|
;;
|
||||||
|
restart|reload|upgrade)
|
||||||
|
sig USR2 && echo "reloaded $APP_NAME" && exit 0
|
||||||
|
echo >&2 "Couldn't reload, starting '$CMD' instead"
|
||||||
|
$CMD
|
||||||
|
;;
|
||||||
|
rotate)
|
||||||
|
sig USR1 && echo rotated logs OK && exit 0
|
||||||
|
echo >&2 "Couldn't rotate logs" && exit 1
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo >&2 $USAGE
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
39
config/unicorn.rb
Normal file
39
config/unicorn.rb
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
root=File.expand_path(File.dirname(__FILE__) + '/..')
|
||||||
|
#shared_dir="#{root}/shared"
|
||||||
|
working_directory root
|
||||||
|
pid "#{root}/pids/unicorn.nemo.pid"
|
||||||
|
stderr_path "#{root}/log/unicorn.stderr.log"
|
||||||
|
stdout_path "#{root}/log/unicorn.stdout.log"
|
||||||
|
listen "#{root}/sockets/unicorn.nemo.sock", :backlog => 64
|
||||||
|
listen(8081, backlog: 64) if ENV['RAILS_ENV'] == 'production'
|
||||||
|
worker_processes 2
|
||||||
|
preload_app true
|
||||||
|
timeout 30
|
||||||
|
|
||||||
|
|
||||||
|
before_fork do |server, worker|
|
||||||
|
# the following is highly recomended for Rails + "preload_app true"
|
||||||
|
# as there's no need for the master process to hold a connection
|
||||||
|
defined?(ActiveRecord::Base) and ActiveRecord::Base.connection.disconnect!
|
||||||
|
|
||||||
|
##
|
||||||
|
# When sent a USR2, Unicorn will suffix its pidfile with .oldbin and
|
||||||
|
# immediately start loading up a new version of itself (loaded with a new
|
||||||
|
# version of our app). When this new Unicorn is completely loaded
|
||||||
|
# it will begin spawning workers. The first worker spawned will check to
|
||||||
|
# see if an .oldbin pidfile exists. If so, this means we've just booted up
|
||||||
|
# a new Unicorn and need to tell the old one that it can now die. To do so
|
||||||
|
# we send it a QUIT.
|
||||||
|
#
|
||||||
|
# Using this method we get 0 downtime deploys.
|
||||||
|
|
||||||
|
old_pid = "#{root}/pids/unicorn.nemo.pid.oldbin"
|
||||||
|
if File.exists?(old_pid) && server.pid != old_pid
|
||||||
|
begin
|
||||||
|
Process.kill("QUIT", File.read(old_pid).to_i)
|
||||||
|
rescue Errno::ENOENT, Errno::ESRCH
|
||||||
|
# someone else did our job for us
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
Reference in New Issue
Block a user