set :application, "aria-www"
set :repository,  "git@git.g77k.com:huxl/novotech-www.git"
set :branch, "master"

set :scm, :git
set :deploy_via, :remote_cache
set :user, "root"
set(:password) { Capistrano::CLI.password_prompt("User password: ") }
set :branch, $1 if `git branch` =~ /\* (\S+)\s/m
set :use_sudo, false
set :rails_env, 'production'

#ssh_options[:forward_agent] = true
#ssh_options[:port] = 22
server "ariaboard.com", :app, :web, :db, :primary => true
default_run_options[:pty] = true
set :deploy_to, "/www/#{application}"

set :default_environment, {
    'PATH' => "/usr/local/lib:/usr/lib:$PATH"
   #'GEM_HOME'     => '/usr/local/bin/gem',
   # 'GEM_ PATH'     => '/usr/local/bin/gem:/usr/bin/gem'
}

after "deploy:update", "deploy:prepare"
after "deploy:update", "deploy:bundle"
after "deploy:update", "deploy:assets_precompile"
after "deploy:update", "deploy:restart"

namespace :deploy do
  task :prepare, :roles => :app do
    run "cp /www/aria-www/current/script/aria-www-site   /etc/nginx/sites-enabled/"
    run "cp /www/aria-www/current/script/unicorn   /etc/init.d/"
    run "chmod a+x /etc/init.d/unicorn"
    run "update-rc.d -f unicorn remove && update-rc.d unicorn defaults 41"
  end

  task :bundle, :roles => :app do
    run "cd #{release_path} && bundle"
  end

  task :assets_precompile, :roles => :app do
    run "cd /www/aria-www/current && RAILS_ENV=production bundle exec rake assets:precompile"
  end

  task :db_seed, :roles => :app do
    run "cd /www/aria-www/current && bundle exec rake db:seed"
  end

  task :restart, :roles => :app do
    run "service nginx restart"
    run "service unicorn restart"
  end

end
