added capistrano; more production changes

This commit is contained in:
jomo
2014-06-24 23:04:24 +02:00
parent 1eecb530c3
commit a2ff7068c0
8 changed files with 177 additions and 4 deletions
+53
View File
@@ -0,0 +1,53 @@
require "bundler/capistrano"
require "rvm/capistrano"
server "redstoner", :web, :app, :db, primary: true
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 :repository, "git@bitbucket.org/redstonesheep/redstoner.git"
set :branch, "master"
default_run_options[:pty] = true
ssh_options[:forward_agent] = true
after "deploy", "deploy:cleanup" # keep only the last 5 releases
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 #{current_path}/config/nginx.conf /etc/nginx/sites-enabled/#{application}"
sudo "ln -nfs #{current_path}/config/unicorn_init.sh /etc/init.d/unicorn_#{application}"
run "mkdir -p #{shared_path}/config"
put File.read("config/database.example.yml"), "#{shared_path}/config/database.yml"
puts "Now edit the config files in #{shared_path}."
end
after "deploy:setup", "deploy:setup_config"
task :symlink_config, roles: :app do
run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
end
after "deploy:finalize_update", "deploy:symlink_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
+99
View File
@@ -0,0 +1,99 @@
user www-data;
worker_processes 4;
pid /var/run/nginx.pid;
events {
worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
##
# (nginx-naxsi config)
# Uncomment it if you installed nginx-naxsi
#include /etc/nginx/naxsi_core.rules;
##
# (nginx-passenger config)
# Uncomment it if you installed nginx-passenger
#passenger_root /usr;
#passenger_ruby /usr/bin/ruby;
##
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
upstream unicorn {
server unix:/tmp/unicorn.redstoner.sock fail_timeout=0;
}
server {
listen 5500 deferred;
server_name redstoner.com *.redstoner.com;
root /home/www-data/apps/redstoner/current/public;
location ^~ /assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}
# send requests to rails if file not found
try_files $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 400 /404.html;
error_page 422 /422.html;
error_page 500 502 503 504 /500.html;
client_max_body_size 20M;
keepalive_timeout 10;
}
}
+1 -1
View File
@@ -1,4 +1,4 @@
root = "/var/rails_site/"
root = "/home/www-data/apps/redstoner"
working_directory root
pid "#{root}/tmp/pids/unicorn.pid"
stderr_path "#{root}/log/unicorn.log"
Regular → Executable
+1 -1
View File
@@ -12,7 +12,7 @@ set -e
# Feel free to change any of the following variables for your app:
TIMEOUT="${TIMEOUT-60}"
APP_ROOT="/var/rails_site/"
APP_ROOT="/home/www-data/apps/redstoner"
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"