Skip to content

Commit

Permalink
add capify
Browse files Browse the repository at this point in the history
  • Loading branch information
CowboyOnRails committed Mar 15, 2012
1 parent 9d27eb4 commit 91c7011
Show file tree
Hide file tree
Showing 8 changed files with 190 additions and 68 deletions.
8 changes: 8 additions & 0 deletions Capfile
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
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ end
gem 'jquery-rails'
gem 'therubyracer'
gem 'execjs'
gem 'client_side_validations', '~> 3.0.0'

#Authentication
gem 'devise', :git =>'git://github.com/plataformatec/devise.git'
Expand Down
7 changes: 5 additions & 2 deletions app/helpers/articles_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
module ArticlesHelper
def parent_article_options(article)
root = [['без родителя',0]]
parents = Article.where(:parent_id=>0).collect { |p| [p.name, p.id]}
options_for_select(root+parents,article.parent_id)
parents = Article.where(:parent_id=>0, :top => false)
if article.try(:id).present?
parents = parents.select { |a| a.id != article.id }
end
options_for_select(root + parents.collect { |p| [p.name, p.id]},article.try(:parent_id))
end
end
31 changes: 0 additions & 31 deletions app/views/locations/index.html.erb

This file was deleted.

5 changes: 0 additions & 5 deletions app/views/locations/new.html.erb

This file was deleted.

30 changes: 0 additions & 30 deletions app/views/locations/show.html.erb

This file was deleted.

138 changes: 138 additions & 0 deletions config/deploy.rb
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'
38 changes: 38 additions & 0 deletions config/unicorn.rb
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

0 comments on commit 91c7011

Please sign in to comment.