Created
November 15, 2012 13:17
Revisions
-
shmatov revised this gist
Nov 20, 2012 . 1 changed file with 3 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -88,10 +88,7 @@ # ------------------------------------------------------------------------------ desc "Restart unicorn using 'upgrade'" task :restart => :environment do invoke 'unicorn:stop' invoke 'unicorn:start' end end -
shmatov revised this gist
Nov 15, 2012 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -50,7 +50,7 @@ invoke 'deploy:link_shared_paths' to :launch do invoke :'unicorn:restart' end end end -
shmatov created this gist
Nov 15, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,7 @@ # lib/tasks/deploy.rake namespace :deploy do desc 'Deploy to staging environment' task :staging do exec 'mina deploy -f config/deploy/staging.rb' end end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,97 @@ # config/deploy/staging.rb require 'mina/bundler' require 'mina/rails' require 'mina/git' require 'mina/rvm' # Config # ============================================================================== set :term_mode, :system set :rails_env, 'staging' set :domain, '50.56.204.208' set :port, 37894 set :deploy_to, "/home/apps/mfp/#{rails_env}" set :app_path, "#{deploy_to}/#{current_path}" set :repository, 'git@goup.unfuddle.com:goup/mfp.git' set :brach, 'master' set :user, 'apps' set :shared_paths, ['public/static', 'tmp'] set :keep_releases, 5 # RVM # ============================================================================== set :rvm_path, '/usr/local/rvm/scripts/rvm' task :environment do invoke 'rvm:use[1.9.3]' end # Setup task # ============================================================================== task :setup do queue! %{ mkdir -p "#{deploy_to}/shared/tmp/pids" } end # Deploy task # ============================================================================== desc "deploys the current version to the server." task :deploy => :environment do deploy do invoke 'git:clone' invoke 'bundle:install' invoke 'rails:db_migrate' invoke 'rails:assets_precompile' invoke 'deploy:link_shared_paths' to :launch do invoke :'unicorn:start' end end end # Unicorn # ============================================================================== namespace :unicorn do set :unicorn_pid, "#{app_path}/tmp/pids/unicorn.pid" set :start_unicorn, %{ cd #{app_path} bundle exec unicorn -c #{app_path}/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! %{ test -s "#{unicorn_pid}" && kill -QUIT `cat "#{unicorn_pid}"` && echo "Stop Ok" && exit 0 echo >&2 "Not running" } end # Restart task # ------------------------------------------------------------------------------ desc "Restart unicorn using 'upgrade'" task :restart => :environment do queue 'echo "-----> Restart Unicorn"' queue! %{ test -s "#{unicorn_pid}" && kill -HUP `cat "#{unicorn_pid}"` && echo "Reload Ok" && exit 0 #{start_unicorn} } end end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,29 @@ # config/unicorn/staging.rb app_path = "/home/apps/mfp/staging/current" worker_processes 1 preload_app true timeout 180 listen '127.0.0.1:9021' user 'apps', 'apps' working_directory app_path pid "#{app_path}/tmp/pids/unicorn.pid" stderr_path "log/unicorn.log" stdout_path "log/unicorn.log" 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