set :application, 'APP_NAME'
set :domain, 'REMOTE_SERVER'
set :user, 'i0n'

set :repository,  "#{user}@#{domain}:/home/#{user}/git/#{application}.git"

role :app, domain                           # This may be the same as the `Web` server
role :web, domain                           # Your HTTP server, Apache/etc
role :db,  domain , :primary => true        # This is where Rails migrations will run

set :scm_verbose, true

set :scm, :git
set :scm_username, user
set :runner, user
set :use_sudo, false
set :branch, "master"
set :deploy_via, :checkout
set :git_shallow_clone, 1
set :deploy_to, "/home/#{user}/sites/#{application}"
default_run_options[:pty] = true

namespace :deploy do
  #task which causes Passenger to initiate a restart
  task  :restart do
    run "mkdir -p #{release_path}/tmp && touch #{release_path}/tmp/restart.txt"
  end
    
  namespace :db do
    
    desc "Create database for the production environment using the servers rake db:setup task.\n Loads the schema, and initializes with the seed data"
    task :setup do
      run "cd #{current_path}; rake db:setup RAILS_ENV=production"
    end 
        
    desc "Populates the production database using lib/tasks/populate which I will use as my own internal convention for this process"
    task :populate do
      run "cd #{current_path}; rake db:populate RAILS_ENV=production"
    end
    
  end
  
  desc "Task to set up the remote Nginx server for app deployment"
  task :nginx do
run "#{sudo} nginx_auto_config /usr/local/bin/nginx.remote.conf /opt/nginx/conf/nginx.conf APP_NAME"
  end
  
  desc "Create bare remote git repo then add remote origin to local git repo and push to remote"
  task :git do
    run "cd /home/#{user}/git; mkdir #{application}.git; cd #{application}.git; git init --bare"
    `git remote add origin ssh://#{user}@#{domain}/~/git/#{application}.git`
    `git push origin master`
  end
  
end

# Reminder of default actions for cap deploy:
# deploy:update_code
# deploy:symlink
# deploy:restart

# eg: after 'deploy:symlink', 'deploy:restart'

# This is a test string APP_NAME_CLASS
# This is a test string REMOTE_SERVER_CLASS