configuration = Capistrano::Configuration.respond_to?(:instance) ? Capistrano::Configuration.instance(:must_exist) : Capistrano.configuration(:must_exist) configuration.load do def with_role(role, &block) original, ENV['HOSTS'] = ENV['HOSTS'], find_servers(:roles =>role).map{|d| d.host}.join(",") begin yield ensure ENV['HOSTS'] = original end end task :symlink_init_d_script do puts "ensuring init_d script is symlinked" run "test -L /etc/init.d/#{application_stub} || #{sudo} ln -s #{script_path}/init_d /etc/init.d/#{application_stub}" end task :symlink_log_dirs do puts "ensuring #{std_log_dir} exists" mkdir_unless_exists( std_log_dir ) puts "setting ownership on #{std_log_dir} & files to #{user}" run "#{sudo} chown -R #{user} #{std_log_dir}" shared_log_dir = "#{shared_dir}/log" puts "ensuring #{shared_log_dir} exists" mkdir_unless_exists( shared_log_dir ) puts "ensuring log dir #{shared_log_dir} is symlinked to #{std_log_dir}" symlink_dir( std_log_dir, shared_log_dir ) puts "setting ownership on #{shared_log_dir} & files to #{user}" run "#{sudo} chown -R #{user} #{shared_log_dir}" puts "ensuring log dir #{web_dir}/log is symlinked to #{std_log_dir}" symlink_dir( std_log_dir, "#{web_dir}/log" ) puts "setting ownership on log dir & files to #{user}" run "#{sudo} chown -R #{user} #{web_dir}/log" puts "removing default #{current_path}/log symlink" run "#{sudo} rm #{current_path}/log" end task :symlink_pid_dirs do std_pid_dir = "#{web_dir}/tmp/pids" shared_pid_dir = "#{shared_dir}/pids" puts "ensuring #{shared_pid_dir} exists" mkdir_unless_exists( shared_pid_dir ) puts "ensuring #{std_pid_dir} exists" mkdir_unless_exists( std_pid_dir ) puts "ensuring pid dir #{std_pid_dir} is symlinked to #{shared_pid_dir}" symlink_dir( shared_pid_dir, std_pid_dir ) puts "setting ownership on #{web_dir}/tmp & files to #{user}" run "#{sudo} chown -R #{user} #{web_dir}/tmp" puts "setting ownership on #{shared_pid_dir} & files to #{user}" run "#{sudo} chown -R #{user} #{shared_pid_dir}" end task :symlink_site_cache_dir do puts "Removing existing symlink from /tmp/cache/sites" run "(test -d #{web_dir}/tmp/cache && #{sudo} rm -rf #{web_dir}/tmp/cache) || echo 'no existing /tmp/cache dir'" puts "Creating /shared/cache/sites dir if needed" run "mkdir -p #{shared_dir}/cache/sites && #{sudo} chown -R #{user} #{shared_dir}/cache" puts "Symlinking /shared/cache into /tmp/" symlink_dir("#{shared_dir}/cache","#{web_dir}/tmp/cache") end task :regenerate_monit do puts "regenerating monit config file" run "(test -d #{web_dir}/config/monit && #{sudo} rm -rf #{web_dir}/config/monit/*) || mkdir -p #{web_dir}/config/monit" run "cd #{web_dir} && ruby script/generate monit" puts "setting permissions & ownership on monit config files" run "#{sudo} chmod 0700 #{web_dir}/config/monit/* && #{sudo} chown root #{web_dir}/config/monit/*" end task :resymlink_monit do std_monit_file = "/etc/monit/conf.d/#{application_stub}" puts "re-symlinking monit config" run "(test -L #{std_monit_file} && #{sudo} rm #{std_monit_file}) || echo 'no existing link'" run "#{sudo} ln -s #{web_dir}/config/monit/monit.`readlink /etc/trigga_config_file | xargs basename`.config #{std_monit_file} " end task :reload_monit do run "#{sudo} monit reload" end task :regenerate_logrotate do puts "regenerating logrotate config file" run "#{sudo} rm #{web_dir}/config/log_rotate/* && cd #{web_dir} && ruby script/generate logrotate" puts "setting permissions & ownership on logrotate config files" run "#{sudo} chmod 0700 #{web_dir}/config/log_rotate/* && #{sudo} chown root #{web_dir}/config/log_rotate/*" end task :resymlink_logrotate do logrotate_config_file = "#{web_dir}/config/log_rotate/log_rotate.#{File.basename(trigga_config_file)}.config" std_logrotate_file = "/etc/logrotate.d/#{application_stub}" puts "re-symlinking logrotate config" run "(test -L #{std_logrotate_file} && #{sudo} rm #{std_logrotate_file}) || echo nothing to remove" run "#{sudo} ln -s #{web_dir}/config/log_rotate/log_rotate.`readlink /etc/trigga_config_file | xargs basename`.config #{std_logrotate_file} " end task :chown_entire_project_dir do puts "chowning entire #{application_stub} dir to #{user_and_group}" run "#{sudo} chown -R #{user_and_group} #{deploy_to}" end task :regenerate_db_scripts do puts "regenerating db scripts" run "test -d #{web_dir}/script/db && #{sudo} rm -rf #{web_dir}/script/db/*" run "cd #{web_dir} && ruby script/generate db" puts "setting permissions & ownership on cron and db scripts" run "#{sudo} chmod 0700 #{web_dir}/script/db/* && #{sudo} chown root #{web_dir}/script/db/*" end task :regenerate_cron_scripts do puts "regenerating cron scripts" run "(test -d #{web_dir}/script/cron && #{sudo} rm -rf #{web_dir}/script/cron/*) || echo 'no existing scripts/cron dir'" run "cd #{web_dir} && ruby script/generate cron" puts "setting permissions & ownership on cron scripts" run "test -d #{web_dir}/script/cron && #{sudo} find #{web_dir}/script/cron -type f -print | xargs -I{} #{sudo} chown root {} " end task :regenerate_monitoring_scripts do puts "regenerating monitoring scripts" run "cd #{web_dir} && ruby script/generate scripting -f" puts "setting permissions and ownership for solr_lockfile check script" run "#{sudo} chmod 0700 #{web_dir}/script/monitoring/solr_lockfile_check && #{sudo} chown root #{web_dir}/script/monitoring/solr_lockfile_check" end task :symlink_cron_scripts do puts "symlinking any cron scripts in scripts/cron into /etc/cron.d/" symlink_files_in_dir("#{web_dir}/script/cron","/etc/cron.d") # give cron a kick to pick up the new changes run "#{sudo} service cron reload" end end