Commit c964c9cc by tady

Merge pull request #108 from tadyjp/setup_unicorn

Setup unicorn
parents b0c8d230 9647445a
......@@ -2,6 +2,7 @@ bundler_args: "--without development --path=~/.bundle"
language: ruby
rvm:
- 2.1.2
- 2.0.0
env:
matrix:
- DB_TEST_DATABASE=rendezvous_test DB_TEST_USER=travis
......
......@@ -23,3 +23,5 @@ require 'capistrano/rails/migrations'
# Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r }
require 'capistrano3/unicorn'
......@@ -25,6 +25,8 @@ gem 'jbuilder'
gem 'i18n_generators'
gem 'unicorn'
group :doc do
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', require: false
......@@ -77,6 +79,7 @@ group :development do
gem 'capistrano-bundler', '~> 1.1.2'
gem 'capistrano-rails', '~> 1.1'
gem 'capistrano-rbenv', '~> 2.0'
gem 'capistrano3-unicorn'
end
group :development, :test do
......
......@@ -80,6 +80,8 @@ GEM
capistrano-rbenv (2.0.2)
capistrano (~> 3.1)
sshkit (~> 1.3)
capistrano3-unicorn (0.2.1)
capistrano (~> 3.1, >= 3.1.0)
capybara (2.4.1)
mime-types (>= 1.16)
nokogiri (>= 1.3.3)
......@@ -176,6 +178,7 @@ GEM
json (1.8.1)
jwt (0.1.11)
multi_json (>= 1.5)
kgio (2.9.2)
launchy (2.4.2)
addressable (~> 2.3)
libv8 (3.16.14.3)
......@@ -276,6 +279,7 @@ GEM
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rainbow (2.0.0)
raindrops (0.13.0)
rake (10.3.2)
rb-fsevent (0.9.4)
rb-inotify (0.9.5)
......@@ -377,6 +381,10 @@ GEM
unf (0.1.4)
unf_ext
unf_ext (0.0.6)
unicorn (4.8.3)
kgio (~> 2.6)
rack
raindrops (~> 0.7)
validates_email_format_of (1.5.3)
warden (1.2.3)
rack (>= 1.0)
......@@ -401,6 +409,7 @@ DEPENDENCIES
capistrano-bundler (~> 1.1.2)
capistrano-rails (~> 1.1)
capistrano-rbenv (~> 2.0)
capistrano3-unicorn
capybara
coderay
coffee-rails
......@@ -442,4 +451,5 @@ DEPENDENCIES
thin
turnip
uglifier
unicorn
validates_email_format_of
......@@ -11,7 +11,7 @@ A simple markdown-based blog & wiki system for team.
# Supported versions
- Ruby 2.1.2
- Ruby 2.0.0
- Rails 4.1.0
# How to install and use.
......
......@@ -82,7 +82,7 @@ class PostsController < ApplicationController
def destroy
@post.destroy
respond_to do |format|
format.html { redirect_to posts_url, flash: { success: 'Post successfully deleted.' } }
format.html { redirect_to flow_url, flash: { success: 'Post successfully deleted.' } }
format.json { head :no_content }
end
end
......
......@@ -43,7 +43,7 @@ class TagsController < ApplicationController
def destroy
@tag.destroy
respond_to do |format|
format.html { redirect_to posts_url, flash: { success: 'Tag successfully deleted.' } }
format.html { redirect_to flow_url, flash: { success: 'Tag successfully deleted.' } }
format.json { head :no_content }
end
end
......
......@@ -6,9 +6,10 @@ set :repo_url, 'git@github.com:tadyjp/rendezvous.git'
# Default branch is :master
# ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }
set :branch, ENV['REVISION'] || 'master'
# Default deploy_to directory is /var/www/my_app
set :deploy_to, '/var/rails/rendezvous'
set :deploy_to, '/var/www/rendezvous'
# Default value for :scm is :git
# set :scm, :git
......@@ -40,27 +41,47 @@ set :rbenv_prefix, "RBENV_ROOT=#{fetch(:rbenv_path)} RBENV_VERSION=#{fetch(:rben
set :rbenv_map_bins, %w{rake gem bundle ruby rails}
set :rbenv_roles, :all # default value
after 'deploy:publishing', 'deploy:restart'
# namespace :deploy do
# desc 'Restart application'
# task :restart do
# on roles(:app), in: :sequence, wait: 5 do
# # Your restart mechanism here, for example:
# execute :touch, release_path.join('tmp/restart.txt')
# end
# end
# after 'deploy:publishing', 'deploy:restart'
# after :publishing, :restart
# after :restart, :clear_cache do
# on roles(:web), in: :groups, limit: 3, wait: 10 do
# # Here we can do anything such as:
# within release_path do
# execute :rake, 'tmp:clear'
# end
# end
# end
# end
after 'deploy:publishing', 'deploy:restart'
namespace :deploy do
desc 'Restart application'
task :restart do
on roles(:app), in: :sequence, wait: 5 do
# Your restart mechanism here, for example:
execute :touch, release_path.join('tmp/restart.txt')
end
invoke 'unicorn:restart'
end
end
after :publishing, :restart
after :restart, :clear_cache do
on roles(:web), in: :groups, limit: 3, wait: 10 do
# Here we can do anything such as:
within release_path do
execute :rake, 'tmp:clear'
namespace :linked_files do
desc 'Touches all your linked files'
task :touch do
on release_roles :all do
within shared_path do
fetch(:linked_files, []).each do |file|
execute :touch, file
info "Touched: #{file}"
end
end
end
end
before 'deploy:check:linked_files', 'linked_files:touch'
end
......@@ -4,9 +4,9 @@
# server in each group is considered to be the first
# unless any hosts have the primary property set.
# Don't declare `role :all`, it's a meta role
role :app, %w{tady@rendezvous}
role :web, %w{tady@rendezvous}
role :db, %w{tady@rendezvous}
role :app, %w{rendezvous}
role :web, %w{rendezvous}
role :db, %w{rendezvous}
# Extended Server Syntax
# ======================
......@@ -21,7 +21,7 @@ role :db, %w{tady@rendezvous}
# you can see them in [net/ssh documentation](http://net-ssh.github.io/net-ssh/classes/Net/SSH.html#method-c-start)
# set it globally
set :ssh_options, {
keys: %w(/Users/tady/.ssh/id_rsa),
keys: %w(~/.ssh/id_rsa),
forward_agent: true,
auth_methods: %w(publickey)
}
......
# paths
app_path = "/var/www/rendezvous"
working_directory "#{app_path}/current"
pid "#{app_path}/current/tmp/pids/unicorn.pid"
# listen
listen "/tmp/unicorn-rendezvous.socket", :backlog => 64
# logging
stderr_path "log/unicorn.stderr.log"
stdout_path "log/unicorn.stdout.log"
# workers
worker_processes 3
# use correct Gemfile on restarts
before_exec do |server|
ENV['BUNDLE_GEMFILE'] = "#{app_path}/current/Gemfile"
end
# preload
preload_app true
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
if defined?(ActiveRecord::Base)
ActiveRecord::Base.connection.disconnect!
end
# Before forking, kill the master process that belongs to the .oldbin PID.
# This enables 0 downtime deploys.
old_pid = "#{server.config[: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
after_fork do |server, worker|
if defined?(ActiveRecord::Base)
ActiveRecord::Base.establish_connection
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment