set :application, 'jfn_app' 
	set :domain, 'www.noblet.me'


	$:.unshift(File.expand_path('./lib', ENV['rvm_path']))

	require "rvm/capistrano"

	set :rvm_ruby_string, 'ruby-1.9.3-p0'
	set :rvm_type, :user  

	set :user, 'web'



	set :deploy_to, "/home/#{user}/#{application}/" 
	set :deploy_via, :remote_cache

	set :normalize_asset_timestamps, false


	set :rails_env, "production"



	role :app, domain
	role :web, domain
	role :db, domain, :primary => true

	set :scm, :git
	set :repository,  "git@box1.quartz-agence.com:#{application}.git"
	set :branch, "master"

	default_run_options[:pty] = true 


	after "deploy", "deploy:bundle_gems"
	after "deploy:bundle_gems", "deploy:make_simlinks"
	after "deploy:make_simlinks", "deploy:restart"
	after "deploy:restart", "deploy:cleanup"


	namespace :deploy do
		task :bundle_gems do 
			run "cd #{deploy_to}current && bundle install"
		end

		task :make_simlinks do 
			run "rm -rf #{deploy_to}current/private_medias"
			run "ln -s #{deploy_to}shared/storage/private #{deploy_to}current/private_medias"
			run "rm -rf #{deploy_to}current/public/public_medias"
			run "ln -s #{deploy_to}shared/storage/public #{deploy_to}current/public/public_medias"
		end

		task :start do 
			sudo "service #{application} start"
		end
		task :stop do 
			run "service #{application} stop"	
		end
		task :restart, :roles => :app, :except => { :no_release => true } do
			sudo "service #{application} restart"
		end
		task :migrate do 
			run "cd #{deploy_to}current && rake db:migrate RAILS_ENV=#{rails_env}"

		end
		
		task :seeds do 
			run "cd #{deploy_to}current && rake db:seeds RAILS_ENV=#{rails_env}"

		end
	end