Skip to content

Instantly share code, notes, and snippets.

@onesup
Created May 14, 2013 02:56
Show Gist options
  • Save onesup/5573326 to your computer and use it in GitHub Desktop.
Save onesup/5573326 to your computer and use it in GitHub Desktop.
nginx + unicorn + capistrano 를 이용한 배포에 필요한 설정파일들.
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000
#repang_production 부분 수정 필요.
production:
adapter: mysql2
encoding: utf8
reconnect: false
database: repang_production
pool: 5
username: root
password:
host: localhost
require "bundler/capistrano"
#require "delayed/recipes"
#여기 14.63.*.* 부분 수정 필요.
server "14.63.*.*", :web, :app, :db, primary: true
set :rails_env, "production" #added for delayed job
#여기 repang 부분 수정 필요. 프로젝트 이름으로.
set :application, "repang"
#여기 daul 부분 수정 필요.
set :user, "daul"
set :deploy_to, "/home/#{user}/#{application}"
set :deploy_via, :remote_cache
set :use_sudo, false
set :scm, "git"
#여기 onesup 부분 수정 필요.
set :repository, "[email protected]:onesup/#{application}.git"
set :branch, "master"
#여기의 경로는 gem environment 로 remote의 루비 EXECUTABLE DIRECTORY 확인하면 됨.
set :default_environment, {
'PATH' => "/home/daul/.rbenv/versions/1.9.3-p392/bin/:$PATH"
}
default_run_options[:pty] = true
ssh_options[:forward_agent] = true
after "deploy", "deploy:cleanup" # keep only the last 5 releases
# for delayed_job
#after "deploy:stop", "delayed_job:stop"
#after "deploy:start", "delayed_job:start"
#after "deploy:restart", "delayed_job: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
task :setup_config, roles: :app do
sudo "ln -nfs #{shared_path}/cached-copy/config/nginx.conf /etc/nginx/sites-enabled/#{application}"
sudo "ln -nfs #{current_path}/config/unicorn_init.sh /etc/init.d/unicorn_#{application}"
#sudo "rm /etc/nginx/sites-enabled/default"
end
after "deploy:setup", "deploy:setup_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
upstream unicorn {
# 여기 /tmp/unicorn.repang.sock 부분 수정 필요.
server unix:/tmp/unicorn.repang.sock fail_timeout=0;
}
server {
listen 80 default deferred;
# server_name example.com;
# 여기 /home/daul/repang 부분 수정 필요.
root /home/daul/repang/current/public;
location ^~ /assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}
try_files $uri/index.html $uri @unicorn;
location @unicorn {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://unicorn;
}
error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 10;
}
#여기 /home/daul/repang/ 부분 수정 필요
root = "/home/daul/repang/current"
working_directory root
pid "#{root}/tmp/pids/unicorn.pid"
stderr_path "#{root}/log/unicorn.err.log"
stdout_path "#{root}/log/unicorn.out.log"
# change the YOUR_APP_NAME to your application name
#여기 unicorn.repang.sock 부분 수정 필요
#unicorn.*.sock 이 nginx와 unicorn이 만나는 부분.
listen "/tmp/unicorn.repang.sock"
worker_processes 2
timeout 30
before_exec do |server|
ENV["BUNDLE_GEMFILE"] = "#{root}/Gemfile"
end
#!/bin/sh
set -e
# Feel free to change any of the following variables for your app:
TIMEOUT=${TIMEOUT-60}
#여기 /home/daul/repang 부분 수정 필요
APP_ROOT=/home/daul/repang/current
#여기 daul 부분 수정 필요
AS_USER=daul
PID=$APP_ROOT/tmp/pids/unicorn.pid
CMD="cd $APP_ROOT; bundle exec unicorn -D -c $APP_ROOT/config/unicorn.rb -E production"
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"
# ;;
restart|reload)
sig USR2 && 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment