set :application, "appname"
set :domain, "www.myserver.com"
set :deploy_to, "/app/directory"
set :user, "root"
set :repository, "http://www.example.com/svn/#{application}/trunk"

set :start_mongrel, "service mongrel_cluster start"
set :stop_mongrel, "service mongrel_cluster stop"
set :restart_mongrel, "service mongrel_cluster restart"

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

namespace :deploy do

  desc "Restart mongrel"
  task :restart, :roles => :app do
    #sudo restart_mongrel
    stop
    restart_sphinx
    start
  end

  desc "Start mongrel"
  task :start, :roles => :app do
    sudo start_mongrel
  end

  desc "Stop mongrel"
  task :stop, :roles => :app do
    sudo stop_mongrel
  end

  desc "Cleanup older revisions"
  task :after_deploy do
    cleanup
  end

  desc "Re-establish symlinks"
  task :after_symlink do
    run <<-CMD
      rm -fr #{release_path}/db/sphinx &&
      ln -nfs #{shared_path}/db/sphinx #{release_path}/db/sphinx
    CMD
  end

  desc "Stop the sphinx server"
  task :stop_sphinx , :roles => :app do
    run "cd #{current_path} && rake thinking_sphinx:stop RAILS_ENV=production"
  end

  desc "Start the sphinx server" 
  task :start_sphinx, :roles => :app do
    run "cd #{current_path} && rake thinking_sphinx:configure RAILS_ENV=production && rake thinking_sphinx:start RAILS_ENV=production"
  end

  desc "Restart the sphinx server"
  task :restart_sphinx, :roles => :app do
    stop_sphinx
    start_sphinx
  end  

end