Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Capfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load 'deploy'
# Uncomment if you are using Rails' asset pipeline
load 'deploy/assets'
#load 'deploy/assets'
load 'config/deploy' # remove this line to skip loading any of the default tasks
10 changes: 7 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#source 'https://rubygems.org'
source 'http://ruby.taobao.org'
source 'https://rubygems.org'
#source 'http://ruby.taobao.org'

gem 'rails', '3.2.13'

Expand Down Expand Up @@ -46,7 +46,11 @@ gem 'formtastic-bootstrap'
gem 'unicorn'

# Deploy with Capistrano
gem 'capistrano'
group :development do
gem 'rvm-capistrano'
gem 'capistrano-rbenv'
gem 'capistrano-unicorn', require: false
end

# To use debugger
# gem 'debugger'
15 changes: 13 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
GEM
remote: http://ruby.taobao.org/
remote: https://rubygems.org/
specs:
actionmailer (3.2.13)
actionpack (= 3.2.13)
Expand Down Expand Up @@ -36,6 +36,13 @@ GEM
net-sftp (>= 2.0.0)
net-ssh (>= 2.0.14)
net-ssh-gateway (>= 1.1.0)
capistrano-platform-resources (0.1.3)
capistrano (< 3)
capistrano-rbenv (1.0.5)
capistrano (< 3)
capistrano-platform-resources (>= 0.1.3)
capistrano-unicorn (0.1.7)
capistrano
coffee-rails (3.2.2)
coffee-script (>= 2.2.0)
railties (~> 3.2.0)
Expand Down Expand Up @@ -108,6 +115,8 @@ GEM
rdoc (3.12.2)
json (~> 1.4)
ref (1.0.4)
rvm-capistrano (1.3.0)
capistrano (>= 2.0.0)
sass (3.2.8)
sass-rails (3.2.6)
railties (~> 3.2.0)
Expand Down Expand Up @@ -146,7 +155,8 @@ PLATFORMS
ruby

DEPENDENCIES
capistrano
capistrano-rbenv
capistrano-unicorn
coffee-rails (~> 3.2.1)
commonjs
formtastic
Expand All @@ -157,6 +167,7 @@ DEPENDENCIES
libv8 (~> 3.11.8)
mysql2
rails (= 3.2.13)
rvm-capistrano
sass-rails (~> 3.2.3)
simple_form
therubyracer
Expand Down
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb
2 changes: 1 addition & 1 deletion config/database.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ production:
database: blog_production
pool: 5
username: root
password:
password: password
socket: /var/run/mysqld/mysqld.sock
74 changes: 45 additions & 29 deletions config/deploy.rb
Original file line number Diff line number Diff line change
@@ -1,52 +1,68 @@
require "bundler/capistrano"
require 'capistrano-rbenv'
require 'capistrano-unicorn'

server "42.121.122.34", :web, :app, :db, primary: true
server "198.199.86.209", :web, :app, :db, primary: true

set :application, "blog"
set :user, "root"
set :user, "ruby"
set :deploy_to, "/home/#{user}/apps/#{application}"
set :deploy_via, :remote_cache
set :deploy_via, :copy#remote_cache
set :use_sudo, false
set :unicorn_binary, 'unicorn_rails'

set :scm, "git"
#set :scm, "git"
#set :repository, "[email protected]:jerry134/#{application}.git"
set :repository, "https://github.com/jerry134/#{application}.git"
set :branch, "master"
set :repository, '.'#"https://github.com/jerry134/#{application}.git"
#set :branch, "master"

default_run_options[:pty] = true
ssh_options[:forward_agent] = true

after "deploy", "deploy:cleanup" # keep only the last 5 releases
after 'deploy:restart', 'unicorn:reload'
after 'deploy:restart', 'unicorn:restart'

namespace :deploy do
%w[start stop restart].each do |command|
desc "#{command} unicorn server"
task command, roles: :app, except: {no_release: true} do
run "/etc/init.d/unicorn_#{application} #{command}"
end
end
#%w[start stop restart].each do |command|
#desc "#{command} unicorn server"
#task command, roles: :app, except: {no_release: true} do
#run "/etc/init.d/unicorn_#{application} #{command}"
#end
#end

task :setup_config, roles: :app do
sudo "ln -nfs #{current_path}/config/nginx.conf /etc/nginx/sites-enabled/#{application}"
sudo "ln -nfs #{current_path}/config/unicorn_init.sh /etc/init.d/unicorn_#{application}"
run "mkdir -p #{shared_path}/config"
put File.read("config/database.example.yml"), "#{shared_path}/config/database.yml"
puts "Now edit the config files in #{shared_path}."
end
after "deploy:setup", "deploy:setup_config"
task :start do
run "unicorn_rails -c #{release_path}/config/unicorn.rb -E production -D"
end
task :stop do
run "ps aux | grep unicorn | grep -v grep | awk '{print $2}' | xargs kill -s 9"
end
task :restart do
run "ps aux | grep unicorn | grep -v grep | awk '{print $2}' | xargs kill -s 9"
run "unicorn_rails -c #{release_path}/config/unicorn.rb -E production -D"
end

#task :setup_config, roles: :app do
#sudo "ln -nfs #{current_path}/config/nginx.conf /etc/nginx/sites-enabled/#{application}"
#sudo "ln -nfs #{current_path}/config/unicorn_init.sh /etc/init.d/unicorn_#{application}"
#run "mkdir -p #{shared_path}/config"
#put File.read("config/database.example.yml"), "#{shared_path}/config/database.yml"
#puts "Now edit the config files in #{shared_path}."
#end
#after "deploy:setup", "deploy:setup_config"

task :symlink_config, roles: :app do
run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
end
after "deploy:finalize_update", "deploy:symlink_config"

desc "Make sure local git is in sync with remote."
task :check_revision, roles: :web do
unless `git rev-parse HEAD` == `git rev-parse origin/master`
puts "WARNING: HEAD is not the same as origin/master"
puts "Run `git push` to sync changes."
exit
end
end
before "deploy", "deploy:check_revision"
#desc "Make sure local git is in sync with remote."
#task :check_revision, roles: :web do
#unless `git rev-parse HEAD` == `git rev-parse origin/master`
#puts "WARNING: HEAD is not the same as origin/master"
#puts "Run `git push` to sync changes."
#exit
#end
#end
#before "deploy", "deploy:check_revision"
end
55 changes: 55 additions & 0 deletions config/deploy_rvm.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
require "bundler/capistrano"
require 'rvm/capistrano'
set :rvm_ruby_string, :local

server "192.34.61.70", :web, :app, :db, primary: true

set :application, "blog"
set :user, "ken"
set :deploy_to, "/home/#{user}/apps/#{application}"
set :deploy_via, :copy
set :use_sudo, false

#set :scm, "git"
#set :repository, "[email protected]:jerry134/#{application}.git"
set :repository, '.'#"https://github.com/jerry134/#{application}.git"
set :branch, "master"

default_run_options[:pty] = true
ssh_options[:forward_agent] = true

after "deploy", "deploy:cleanup" # keep only the last 5 releases
before 'deploy:setup', 'rvm:create_gemset'

namespace :deploy do
%w[start stop restart].each do |command|
desc "#{command} unicorn server"
task command, roles: :app, except: {no_release: true} do
run "/etc/init.d/unicorn_#{application} #{command}"
end
end

task :setup_config, roles: :app do
sudo "ln -nfs #{current_path}/config/nginx.conf /etc/nginx/sites-enabled/#{application}"
sudo "ln -nfs #{current_path}/config/unicorn_init.sh /etc/init.d/unicorn_#{application}"
run "mkdir -p #{shared_path}/config"
put File.read("config/database.example.yml"), "#{shared_path}/config/database.yml"
puts "Now edit the config files in #{shared_path}."
end
after "deploy:setup", "deploy:setup_config"

task :symlink_config, roles: :app do
run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
end
after "deploy:finalize_update", "deploy:symlink_config"

desc "Make sure local git is in sync with remote."
task :check_revision, roles: :web do
unless `git rev-parse HEAD` == `git rev-parse origin/master`
puts "WARNING: HEAD is not the same as origin/master"
puts "Run `git push` to sync changes."
exit
end
end
before "deploy", "deploy:check_revision"
end
51 changes: 43 additions & 8 deletions config/unicorn.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,45 @@
root = "/home/root/apps/blog/current"
working_directory root
pid "#{root}/tmp/pids/unicorn.pid"
stderr_path "#{root}/log/unicorn.log"
stdout_path "#{root}/log/unicorn.log"
#root = "/home/ruby/apps/blog/current"
#pid "#{root}/tmp/pids/unicorn.pid"

listen "/tmp/unicorn.blog.sock"
worker_processes 2
timeout 30
#listen "/tmp/unicorn.blog.sock"

app_path = "/home/ruby/apps/blog/current"

# Set unicorn options
worker_processes 1
preload_app true
timeout 180
listen 9000 #"127.0.0.1:9000"

# Spawn unicorn master worker for user apps (group: apps)
user 'ruby', 'ruby'

# Fill path to your app
working_directory app_path

# Should be 'production' by default, otherwise use other env
rails_env = ENV['RAILS_ENV'] || 'production'

# Log everything to one file
stderr_path "log/unicorn.log"
stdout_path "log/unicorn.log"

# Set master PID location
#pid "#{app_path}/tmp/pids/unicorn.pid"

before_fork do |server, worker|
ActiveRecord::Base.connection.disconnect!

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|
ActiveRecord::Base.establish_connection
end
45 changes: 45 additions & 0 deletions config/unicorn/unicorn.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#root = "/home/ruby/apps/blog/current"
#pid "#{root}/tmp/pids/unicorn.pid"

#listen "/tmp/unicorn.blog.sock"

app_path = "/home/ruby/apps/blog/current"

# Set unicorn options
worker_processes 1
preload_app true
timeout 180
listen 9000 #"127.0.0.1:9000"

# Spawn unicorn master worker for user apps (group: apps)
user 'ruby', 'ruby'

# Fill path to your app
working_directory app_path

# Should be 'production' by default, otherwise use other env
rails_env = ENV['RAILS_ENV'] || 'production'

# Log everything to one file
stderr_path "log/unicorn.log"
stdout_path "log/unicorn.log"

# Set master PID location
pid "#{app_path}/tmp/pids/unicorn.pid"

before_fork do |server, worker|
ActiveRecord::Base.connection.disconnect!

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|
ActiveRecord::Base.establish_connection
end