From ee7d6d67633cadd5ccd2ff88f07cea94b8d9c0b1 Mon Sep 17 00:00:00 2001 From: Nicolas Bally Date: Mon, 18 May 2015 15:38:37 +0200 Subject: [PATCH] new server --- Gemfile | 2 +- config/deploy.rb | 164 ++++++++++++++++++++++++++++-------------- config/nginx.conf | 2 +- config/unicorn.rb | 2 +- config/unicorn_init_d | 64 +++++++++++++++++ 5 files changed, 179 insertions(+), 55 deletions(-) create mode 100755 config/unicorn_init_d diff --git a/Gemfile b/Gemfile index 48ac11d..804ae0b 100644 --- a/Gemfile +++ b/Gemfile @@ -19,7 +19,7 @@ gem 'jquery-rails' # gem 'unicorn' # Deploy with Capistrano -gem 'capistrano' + # To use debugger # gem 'ruby-debug' diff --git a/config/deploy.rb b/config/deploy.rb index 7e69037..7dd2701 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -1,68 +1,128 @@ set :application, 'accescible_app' - set :domain, 'www.accescible-solutions.com' - - - $:.unshift(File.expand_path('./lib', ENV['rvm_path'])) - - require "rvm/capistrano" - - set :rvm_ruby_string, 'ruby-1.9.3-p0' - set :rvm_type, :user - - set :user, 'web' + set :domain, 'auclair-laverie.com' - set :deploy_to, "/home/#{user}/#{application}/" - set :deploy_via, :remote_cache - - set :normalize_asset_timestamps, false - - - set :rails_env, "production" - role :app, domain - role :web, domain - role :db, domain, :primary => true + require "rvm/capistrano" - set :scm, :git - set :repository, "git@box1.quartz-agence.com:#{application}.git" - set :branch, "master" + set :rvm_ruby_string, 'ruby-1.9.3-p0' + set :rvm_type, :user - default_run_options[:pty] = true + set :user, 'web' - after "deploy", "deploy:bundle_gems" - after "deploy:bundle_gems", "deploy:make_simlinks" - after "deploy:make_simlinks", "deploy:restart" - after "deploy:restart", "deploy:cleanup" + + set :deploy_to, "/home/#{user}/#{application}/" + set :deploy_via, :remote_cache + + set :normalize_asset_timestamps, false - namespace :deploy do - task :bundle_gems do - run "cd #{deploy_to}current && bundle install" - end + set :rails_env, "production" - task :make_simlinks do - run "rm -rf #{deploy_to}current/private_medias" - run "ln -s #{deploy_to}shared/storage/private #{deploy_to}current/private_medias" - run "rm -rf #{deploy_to}current/public/public_medias" - run "ln -s #{deploy_to}shared/storage/public #{deploy_to}current/public/public_medias" - end - task :start do - sudo "service #{application} start" - end - task :stop do - run "service #{application} stop" - end - task :restart, :roles => :app, :except => { :no_release => true } do - sudo "service #{application} restart" - end - task :migrate do - run "cd #{deploy_to}current && rake db:migrate RAILS_ENV=#{rails_env}" - end - end \ No newline at end of file + role :app, domain + role :web, domain + role :db, domain, :primary => true + + set :scm, :git + set :repository, "git@git.nicolasbally.com:root/accescible_app.git" + set :branch, "master" + + default_run_options[:pty] = true + + + + before "deploy:symlink", "deploy:bundle_gems" + after "deploy:bundle_gems", "deploy:make_simlinks" + after "deploy:make_simlinks", "assets:precompile" + + before "deploy:restart", "deploy:init_d" + + # after "deploy", "deploy:restart" + after "deploy:restart", "deploy:cleanup" + + + #after "deploy", "deploy:bundle_gems" + #after "deploy:bundle_gems", "deploy:make_simlinks" + #after "deploy:make_simlinks", "assets:precompile" + #after "assets:precompile", "deploy:restart" + #after "deploy:restart", "deploy:cleanup" + + + namespace :assets do + task :precompile, :roles => :web do + run "rm -rf #{release_path}/public/assets" + run "ln -s #{deploy_to}shared/assets #{release_path}/public/assets" + + + run "cd #{release_path} && bundle exec rake assets:precompile --trace" + end + + task :cleanup, :roles => :web do + run "cd #{current_path} && RAILS_ENV=production bundle exec rake assets:clean" + end + end + + + + + + namespace :deploy do + task :bundle_gems do + run "cd #{release_path} && bundle install" + end + task :init_d do + sudo "cp #{current_path}/config/unicorn_init_d /etc/init.d/#{application}" + + sudo "chmod +x /etc/init.d/#{application}" + sudo "update-rc.d #{application} defaults " + end + task :make_simlinks do + run "rm -rf #{release_path}/private_medias" + run "ln -s #{deploy_to}shared/storage/private #{release_path}/private_medias" + run "rm -rf #{release_path}/public/public_medias" + run "ln -s #{deploy_to}shared/storage/public #{release_path}/public/public_medias" + + run "rm -rf #{release_path}/db/production.sqlite3" + run "ln -s #{deploy_to}shared/production.sqlite3 #{release_path}/db/production.sqlite3" + + + + + end + + task :start do + sudo "service #{application} start" + end + task :stop do + run "service #{application} stop" + end + task :restart, :roles => :app, :except => { :no_release => true } do + sudo "service #{application} restart" + end + + task :reload_nginx do + + sudo "rm -rf /etc/nginx/sites-enabled/#{application}" + sudo "ln -s #{current_path}/config/nginx.conf /etc/nginx/sites-enabled/#{application} " + + sudo "service nginx reload" + end + + task :migrate do + run "cd #{deploy_to}current && rake db:migrate RAILS_ENV=#{rails_env}" + + end + + task :seeds do + run "cd #{deploy_to}current && rake db:seeds RAILS_ENV=#{rails_env}" + + end + end + + \ No newline at end of file diff --git a/config/nginx.conf b/config/nginx.conf index dd68838..5054b0e 100644 --- a/config/nginx.conf +++ b/config/nginx.conf @@ -1,5 +1,5 @@ upstream accescible_app_unicorn { - server unix:/home/web/accescible_app/shared/tmp/unicorn.sock fail_timeout=0; + server unix:/home/web/accescible_app/shared/unicorn.sock fail_timeout=0; } server { diff --git a/config/unicorn.rb b/config/unicorn.rb index 85d56de..2ddd126 100644 --- a/config/unicorn.rb +++ b/config/unicorn.rb @@ -5,6 +5,6 @@ pid "/home/web/#{@rails_app}/shared/unicorn.pid" stderr_path "/home/web/#{@rails_app}/shared/log/unicorn.log" stdout_path "/home/web/#{@rails_app}/shared/log/unicorn.log" -listen "/home/web/#{@rails_app}/shared/tmp/unicorn.sock" +listen "/home/web/#{@rails_app}/shared/unicorn.sock" worker_processes 2 timeout 30 \ No newline at end of file diff --git a/config/unicorn_init_d b/config/unicorn_init_d new file mode 100755 index 0000000..c74e98b --- /dev/null +++ b/config/unicorn_init_d @@ -0,0 +1,64 @@ +#!/bin/bash + + +set -u +set -e + +# Change these to match your app: +APP_NAME=accescible_app +APP_RUBY=1.9.3-p0 +APP_ROOT="/home/web/accescible_app/current" +PID="/home/web/accescible_app/shared/unicorn.pid" +ENV=production + +GEM_HOME="/home/web/.rvm/gems/ruby-$APP_RUBY" + +UNICORN_OPTS="-D -E $ENV -c $APP_ROOT/config/unicorn.rb" + +SET_PATH="cd $APP_ROOT; rvm 1.9.3-p0" +CMD="$SET_PATH; unicorn $UNICORN_OPTS" + +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-help} in + start) + sig 0 && echo >&2 "Already running" && exit 0 + su - web -c "$CMD" + ;; + stop) + sig QUIT && exit 0 + echo >&2 "Not running" + ;; + force-stop) + sig TERM && exit 0 + echo >&2 "Not running" + ;; + restart|reload) + sig HUP && echo reloaded OK && exit 0 + echo >&2 "Couldn't reload, starting '$CMD' instead" + su - web -c "$CMD" + ;; + upgrade) + sig USR2 && exit 0 + echo >&2 "Couldn't upgrade, starting '$CMD' instead" + su - web -c "$CMD" + ;; + rotate) + sig USR1 && echo rotated logs OK && exit 0 + echo >&2 "Couldn't rotate logs" && exit 1 + ;; + *) + echo >&2 "Usage: $0 " + exit 1 + ;; +esac \ No newline at end of file