-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9d27eb4
commit 91c7011
Showing
8 changed files
with
190 additions
and
68 deletions.
There are no files selected for viewing
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
load 'deploy' if respond_to?(:namespace) # cap2 differentiator | ||
|
||
# Uncomment if you are using Rails' asset pipeline | ||
# load 'deploy/assets' | ||
|
||
Dir['vendor/gems/*/recipes/*.rb','vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) } | ||
|
||
load 'config/deploy' # remove this line to skip loading any of the default tasks |
This file contains 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 characters
This file contains 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 characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
|
||
# cap deploy:setup | ||
# cap deploy | ||
# cap db:seed (on first deploy) | ||
|
||
$:.unshift(File.expand_path('./lib', ENV['rvm_path'])) | ||
|
||
require 'bundler/capistrano' | ||
|
||
# Uncomment this if you are using Thinking Sphinx | ||
#require 'thinking_sphinx/deploy/capistrano' | ||
|
||
# Uncomment this if you are using Whenever | ||
#set :whenever_command, "bundle exec whenever" | ||
#require "whenever/capistrano" | ||
|
||
set :application, '_newera' | ||
set :domain, '_newera@ramashtab.info' | ||
set :repository, 'git@ramashtab.info:_newera.git' | ||
set :scm, :git | ||
set :deploy_via, :remote_cache | ||
set :branch, :master | ||
set :scm_username, '_victor' | ||
set :scm_verbose, true | ||
set :user, '_newera' | ||
set :use_sudo, false | ||
|
||
ssh_options[:forward_agent] = true | ||
default_run_options[:pty] = false | ||
|
||
set :keep_releases, 1 | ||
set :deploy_to, "/home/#{user}/htdocs" | ||
|
||
set :unicorn_conf, "#{deploy_to}/current/config/unicorn.rb" | ||
set :unicorn_pid, "#{deploy_to}/shared/pids/unicorn.pid" | ||
|
||
|
||
desc "Run tasks in production enviroment." | ||
task :production do | ||
# Prompt to make really sure we want to deploy into prouction | ||
puts "\n\e[0;31m ######################################################################" | ||
puts " #\n # Are you REALLY sure you want to deploy to production?" | ||
puts " #\n # Enter y/N + enter to continue\n #" | ||
puts " ######################################################################\e[0m\n" | ||
proceed = STDIN.gets[0..0] rescue nil | ||
exit unless proceed == 'y' || proceed == 'Y' | ||
|
||
# Production nodes | ||
role :web, domain | ||
role :app, domain | ||
role :db, domain, :primary => true | ||
|
||
set :rails_env, "production" | ||
end | ||
|
||
desc "Run tasks in staging enviroment." | ||
task :staging do | ||
# Staging nodes | ||
role :web, domain | ||
role :app, domain | ||
role :db, domain, :primary => true | ||
|
||
set :rails_env, "staging" | ||
end | ||
|
||
set(:database_username, "_newera") | ||
set(:production_database) { application } | ||
|
||
namespace :deploy do | ||
task :restart do | ||
run "if [ -f #{unicorn_pid} ] && [ -e /proc/$(cat #{unicorn_pid}) ]; then kill -USR2 `cat #{unicorn_pid}`; else cd #{deploy_to}/current && bundle exec unicorn_rails -c #{unicorn_conf} -E #{rails_env} -D; fi" | ||
end | ||
|
||
task :start do | ||
run "bundle exec unicorn_rails -c #{unicorn_conf} -E #{rails_env} -D" | ||
end | ||
|
||
task :stop do | ||
run "if [ -f #{unicorn_pid} ] && [ -e /proc/$(cat #{unicorn_pid}) ]; then kill -QUIT `cat #{unicorn_pid}`; fi" | ||
end | ||
|
||
desc 'Precache assets' | ||
task :precache_assets, :roles => :app do | ||
run "cd #{current_release} && rm -rf #{current_release}/public/assets/* && bundle exec rake assets:precompile RAILS_ENV=#{rails_env}" | ||
end | ||
end | ||
|
||
namespace :db do | ||
desc "Populates the #{rails_env} database" | ||
task :seed do | ||
puts "\n\n=== Populating the #{rails_env} database! ===\n\n" | ||
run "cd #{current_path} && bundle exec rake db:seed --trace RAILS_ENV=#{rails_env}" | ||
end | ||
|
||
desc "Create database yaml in shared path" | ||
task :configure do | ||
set :database_password do | ||
Capistrano::CLI.password_prompt "Database Password: " | ||
end | ||
|
||
db_config = <<-EOF | ||
base: &base | ||
adapter: mysql2 | ||
encoding: utf8 | ||
username: #{database_username} | ||
password: #{database_password} | ||
production: &production | ||
database: #{production_database} | ||
<<: *base | ||
staging: *production | ||
EOF | ||
|
||
run "mkdir -p #{shared_path}/config" | ||
put db_config, "#{shared_path}/config/database.yml" | ||
end | ||
|
||
desc "Make symlink for database yaml" | ||
task :symlink do | ||
run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml" | ||
end | ||
end | ||
|
||
# Uncomment this if you are using Thinking Sphinx | ||
#after 'deploy:migrate', :roles => [:app] do | ||
# thinking_sphinx.stop | ||
# run "ln -nfs #{shared_path}/db/sphinx #{release_path}/db/sphinx" | ||
# thinking_sphinx.configure | ||
# thinking_sphinx.start | ||
#end | ||
|
||
before "deploy:setup", "db:configure" | ||
before "bundle:install", "db:symlink" | ||
after "bundle:install", "deploy:migrate" | ||
after "deploy:migrate", "deploy:precache_assets" | ||
|
||
require './config/boot' |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
deploy_to = "/home/name/htdocs" | ||
rails_root = "#{deploy_to}/current" | ||
pid_file = "#{deploy_to}/shared/pids/unicorn.pid" | ||
socket_file = "#{deploy_to}/shared/sockets/unicorn.sock" | ||
log_file = "#{rails_root}/log/unicorn.log" | ||
err_log = "#{rails_root}/log/unicorn_error.log" | ||
old_pid = pid_file + '.oldbin' | ||
|
||
timeout 30 | ||
worker_processes 1 | ||
listen socket_file, :backlog => 1024 | ||
pid pid_file | ||
stderr_path err_log | ||
stdout_path log_file | ||
preload_app true | ||
|
||
GC.copy_on_write_friendly = true if GC.respond_to?(:copy_on_write_friendly=) | ||
|
||
before_exec do |server| | ||
ENV["BUNDLE_GEMFILE"] = "#{rails_root}/Gemfile" | ||
end | ||
|
||
before_fork do |server, worker| | ||
defined?(ActiveRecord::Base) and ActiveRecord::Base.connection.disconnect! | ||
|
||
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| | ||
defined?(ActiveRecord::Base) and | ||
ActiveRecord::Base.establish_connection | ||
end |