From 44236edd2efd576b256f1a717ab65cce88125532 Mon Sep 17 00:00:00 2001 From: yafeilee Date: Wed, 8 Apr 2015 00:15:02 +0800 Subject: [PATCH] add English blog deploy configration --- Gemfile | 4 ++++ Gemfile.lock | 10 +++++++++ config/deploy.rb | 48 ++++++-------------------------------------- config/deploy/en.rb | 6 ++++++ config/deploy/zh.rb | 6 ++++++ config/unicorn/en.rb | 27 +++++++++++++++++++++++++ 6 files changed, 59 insertions(+), 42 deletions(-) create mode 100644 config/deploy/en.rb create mode 100644 config/deploy/zh.rb create mode 100644 config/unicorn/en.rb diff --git a/Gemfile b/Gemfile index 9bd041c..db85549 100644 --- a/Gemfile +++ b/Gemfile @@ -36,6 +36,10 @@ gem 'rest-client' gem 'unicorn' gem 'newrelic_rpm' +gem 'mina', require: false +gem 'mina-multistage', require: false +gem 'mina-unicorn', :require => false + group :development do gem 'spring' gem 'quiet_assets' diff --git a/Gemfile.lock b/Gemfile.lock index 02a4b93..87691d9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -125,6 +125,12 @@ GEM mime-types (>= 1.16, < 3) method_source (0.8.2) mime-types (2.4.3) + mina (0.3.3) + open4 (~> 1.3.4) + rake + mina-multistage (0.1.1) + mina (>= 0.2.1) + mina-unicorn (0.0.4) mini_magick (4.1.0) mini_portile (0.6.2) minitest (5.5.1) @@ -158,6 +164,7 @@ GEM notiffany (0.0.6) nenv (~> 0.1) shellany (~> 0.0) + open4 (1.3.4) optionable (0.2.0) origin (2.1.1) pry (0.10.1) @@ -311,6 +318,9 @@ DEPENDENCIES html_truncator jbuilder jquery-rails + mina + mina-multistage + mina-unicorn mini_magick mongoid mongoid-pagination diff --git a/config/deploy.rb b/config/deploy.rb index 9165870..3ca0af0 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -1,20 +1,17 @@ +require 'mina/multistage' require 'mina/bundler' require 'mina/rails' require 'mina/git' require 'mina/rvm' # for rvm support. (http://rvm.io) +require 'mina/unicorn' -set :domain, 'yafeilee.me' -set :deploy_to, '/home/ruby/wblog' -set :repository, 'git@github.com:windy/wblog.git' -set :branch, 'master' -set :app_path, "#{deploy_to}/#{current_path}" +set :stages, %w(en zh) +set :default_stage, 'zh' # Manually create these paths in shared/ (eg: shared/config/database.yml) in your server. # They will be linked in the 'deploy:link_shared_paths' step. set :shared_paths, ['config/mongoid.yml', 'config/application.yml', 'log', 'tmp', 'public/uploads', 'public/personal' ] -set :user, 'ruby' # Username in the server to SSH to. - task :environment do queue! %[source /usr/local/rvm/scripts/rvm] queue! %[rvm use 2.0.0] @@ -32,6 +29,8 @@ task :setup => :environment do end queue! %[mkdir -p "#{deploy_to}/shared/pids/"] + queue! %[mkdir -p "#{deploy_to}/shared/tmp/sockets"] + queue! %[mkdir -p "#{deploy_to}/shared/tmp/pids"] queue! %[mkdir -p "#{deploy_to}/shared/log/"] end @@ -51,38 +50,3 @@ task :deploy => :environment do end end end - -namespace :unicorn do - set :unicorn_pid, "#{app_path}/tmp/pids/unicorn_wblog.pid" - set :start_unicorn, %{ - cd #{app_path} && bundle exec unicorn -c config/unicorn/#{rails_env}.rb -E #{rails_env} -D - } - -# Start task -# ------------------------------------------------------------------------------ - desc "Start unicorn" - task :start => :environment do - queue 'echo "-----> Start Unicorn"' - queue! start_unicorn - end - -# Stop task -# ------------------------------------------------------------------------------ - desc "Stop unicorn" - task :stop do - queue 'echo "-----> Stop Unicorn"' - queue! %{ - mkdir -p "#{app_path}/tmp/pids" - test -s "#{unicorn_pid}" && kill -QUIT `cat "#{unicorn_pid}"` && rm -rf "#{unicorn_pid}" && echo "Stop Ok" && exit 0 - echo >&2 "Not running" - } - end - -# Restart task -# ------------------------------------------------------------------------------ - desc "Restart unicorn using 'upgrade'" - task :restart => :environment do - invoke 'unicorn:stop' - invoke 'unicorn:start' - end -end diff --git a/config/deploy/en.rb b/config/deploy/en.rb new file mode 100644 index 0000000..f53c0ad --- /dev/null +++ b/config/deploy/en.rb @@ -0,0 +1,6 @@ +set :domain, 'yafeilee.me' +set :deploy_to, '/home/ruby/wblog_en' +set :repository, 'git@github.com:windy/wblog.git' +set :branch, 'master' +set :user, 'ruby' +set :unicorn_config, -> { "#{deploy_to}/#{current_path}/config/unicorn/en.rb" } diff --git a/config/deploy/zh.rb b/config/deploy/zh.rb new file mode 100644 index 0000000..f568d5f --- /dev/null +++ b/config/deploy/zh.rb @@ -0,0 +1,6 @@ +set :domain, 'yafeilee.me' +set :deploy_to, '/home/ruby/wblog' +set :repository, 'git@github.com:windy/wblog.git' +set :branch, 'master' +set :user, 'ruby' +set :unicorn_config, -> { "#{deploy_to}/#{current_path}/config/unicorn/zh.rb" } diff --git a/config/unicorn/en.rb b/config/unicorn/en.rb new file mode 100644 index 0000000..dca4218 --- /dev/null +++ b/config/unicorn/en.rb @@ -0,0 +1,27 @@ +app_path = File.expand_path( File.join(File.dirname(__FILE__), '..', '..')) + +worker_processes 1 +preload_app true +timeout 180 +listen '/tmp/unicorn_wblog_en.sock' +user 'ruby', 'ruby' +stderr_path "log/unicorn.log" +stdout_path "log/unicorn.log" + +before_fork do |server, worker| + 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| +end + +before_exec do |server| + ENV["BUNDLE_GEMFILE"] = "#{app_path}/current/Gemfile" +end