diff options
Diffstat (limited to 'config')
-rw-r--r-- | config/deploy.rb | 40 | ||||
-rw-r--r-- | config/deploy/production.rb | 4 | ||||
-rw-r--r-- | config/unicorn.rb | 39 | ||||
-rwxr-xr-x | config/unicorn_init.sh | 88 |
4 files changed, 43 insertions, 128 deletions
diff --git a/config/deploy.rb b/config/deploy.rb index f4aaa5f..28d9457 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -1,38 +1,24 @@ -require "bundler/capistrano" +# config valid only for current version of Capistrano +lock '3.4.0' -server "redstoner", :web, :app, :db, primary: true +set :repo_url, 'git@bitbucket.org:redstonesheep/redstoner.git' -set :application, "redstoner" -set :user, "www-data" -set :deploy_to, "/home/#{user}/apps/#{application}" -set :deploy_via, :remote_cache -set :use_sudo, false +set :scm, :git -set :scm, "git" -set :repository, "ssh://git@bitbucket.org/redstonesheep/redstoner.git" -set :branch, "master" +set :ssh_options, { forward_agent: true } +set :keep_releases, 5 -default_run_options[:pty] = true -ssh_options[:forward_agent] = true +set :deploy_to, -> { "/home/www-data/apps/#{fetch(:application)}" } -after "deploy", "deploy:cleanup" # keep only the last 5 releases +set :rbenv_ruby, '2.0.0-p247' -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 +set :bundle_without, %w{development test}.join(' ') - task :setup_config, roles: :app do - puts "Please run as root: 'ln -nfs #{current_path}/config/nginx.conf /etc/nginx/sites-enabled/#{application}'" - puts "Please run as root: 'ln -nfs #{current_path}/config/unicorn_init.sh /etc/init.d/unicorn_#{application}'" - run "mkdir -p #{shared_path}/config" - end - after "deploy:setup", "deploy:setup_config" +# Default value for linked_dirs is [] +set :linked_dirs, fetch(:linked_dirs, []).push('bin', 'log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', 'public/system') +namespace :deploy do 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` @@ -42,4 +28,6 @@ namespace :deploy do end end before "deploy", "deploy:check_revision" + + after :publishing, :restart end
\ No newline at end of file diff --git a/config/deploy/production.rb b/config/deploy/production.rb new file mode 100644 index 0000000..627751c --- /dev/null +++ b/config/deploy/production.rb @@ -0,0 +1,4 @@ +set :application, 'redstoner' +set :branch, 'master' + +role :web, %w{www-data@redstoner}
\ No newline at end of file diff --git a/config/unicorn.rb b/config/unicorn.rb index 2067b63..cebbcde 100644 --- a/config/unicorn.rb +++ b/config/unicorn.rb @@ -1,15 +1,26 @@ -root = "/home/www-data/apps/redstoner/current" -working_directory root -pid "#{root}/tmp/pids/unicorn.pid" -stderr_path "#{root}/log/unicorn.log" -stdout_path "#{root}/log/unicorn.log" - -listen "/tmp/unicorn.redstoner.sock" -worker_processes 2 -timeout 30 - -# Force the bundler gemfile environment variable to -# reference the capistrano "current" symlink -before_exec do |_| - ENV["BUNDLE_GEMFILE"] = File.join(root, 'Gemfile') +worker_processes Integer(ENV["WEB_CONCURRENCY"] || 3) +timeout 15 +preload_app true + + +stderr_path "/home/www-data/apps/redstoner/shared/log/unicorn.stderr.log" +stdout_path "/home/www-data/apps/redstoner/shared/log/unicorn.stdout.log" + +before_fork do |server, worker| + Signal.trap 'TERM' do + puts 'Unicorn master intercepting TERM and sending myself QUIT instead' + Process.kill 'QUIT', Process.pid + end + + defined?(ActiveRecord::Base) and + ActiveRecord::Base.connection.disconnect! +end + +after_fork do |server, worker| + Signal.trap 'TERM' do + puts 'Unicorn worker intercepting TERM and doing nothing. Wait for master to send QUIT' + end + + defined?(ActiveRecord::Base) and + ActiveRecord::Base.establish_connection end
\ No newline at end of file diff --git a/config/unicorn_init.sh b/config/unicorn_init.sh deleted file mode 100755 index 25d4f13..0000000 --- a/config/unicorn_init.sh +++ /dev/null @@ -1,88 +0,0 @@ -#!/bin/sh -### BEGIN INIT INFO -# Provides: unicorn -# Required-Start: $remote_fs $syslog -# Required-Stop: $remote_fs $syslog -# Default-Start: 2 3 4 5 -# Default-Stop: 0 1 6 -# Short-Description: Manage unicorn server -# Description: Start, stop, restart unicorn server for a specific application. -### END INIT INFO -set -e - -# not sure why, but .bash_profile is not being executed -export PATH="$HOME/.rbenv/bin:$PATH" -eval "$(rbenv init -)" - -# Feel free to change any of the following variables for your app: -TIMEOUT="${TIMEOUT-60}" -APP_ROOT="/home/www-data/apps/redstoner/current" -PID="$APP_ROOT/tmp/pids/unicorn.pid" -CMD="cd $APP_ROOT; bundle exec unicorn -D -c $APP_ROOT/config/unicorn.rb -E production" -AS_USER="www-data" -set -u - -OLD_PIN="$PID.oldbin" - -sig () { - test -s "$PID" && kill -$1 `cat $PID` -} - -oldsig () { - test -s $OLD_PIN && kill -$1 `cat $OLD_PIN` -} - -run () { - if [ "$(id -un)" = "$AS_USER" ]; then - eval $1 - else - su -c "$1" - $AS_USER - fi -} - -case "$1" in -start) - sig 0 && echo >&2 "Already running" && exit 0 - run "$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" - run "$CMD" - ;; -upgrade) - if sig USR2 && sleep 2 && sig 0 && oldsig QUIT - then - n=$TIMEOUT - while test -s $OLD_PIN && test $n -ge 0 - do - printf '.' && sleep 1 && n=$(( $n - 1 )) - done - echo - - if test $n -lt 0 && test -s $OLD_PIN - then - echo >&2 "$OLD_PIN still exists after $TIMEOUT seconds" - exit 1 - fi - exit 0 - fi - echo >&2 "Couldn't upgrade, starting '$CMD' instead" - run "$CMD" - ;; -reopen-logs) - sig USR1 - ;; -*) - echo >&2 "Usage: $0 <start|stop|restart|upgrade|force-stop|reopen-logs>" - exit 1 - ;; -esac
\ No newline at end of file |