Skip to content

Instantly share code, notes, and snippets.

@twinge
Created July 1, 2009 19:04
Show Gist options
  • Save twinge/138980 to your computer and use it in GitHub Desktop.
Save twinge/138980 to your computer and use it in GitHub Desktop.
set :target, ENV['TARGET'] || 'gcx'
case target
when 'gcx'
set :host, "192.168.100.149" #"app2.mygcx.org"
set :ssh_options, { :forward_agent => true}
set :deploy_to, "/var/www/panda"
set :scm_verbose, true
when 'amazon'
# Your instance's address
set :host, ENV['INSTANCE_DNS'] || "ec2-174-129-185-7.compute-1.amazonaws.com"
set :user, "panda"
set :password, "foobar1"
set :deploy_to, "/var/www/panda"
set :scm_verbose, false
ec2_ssh_key = File.join("#{Dir.pwd}/config", 'id_rsa-josh-keypair')
set :ssh_options, { :forward_agent => true } #, :keys => [ec2_ssh_key]
end
# You must set this to be the your key assigned to your EC2 instance when it was started
# If you are deploying your own fork of Panda you will need to edit the git repo
set :repository, "git://github.com/twinge/panda.git"
set :branch, "ers"
# There shouldn't be any need to edit anything below
# ==================================================
set :application, "panda"
set :scm, :git
set :repository_cache, "git_master"
set :deploy_via, :remote_cache
set :use_sudo, false
role :app, host
role :web, host
role :db, host, :primary => true
task :copy_config_files_to_server do
put File.read("config/database.yml.ec2"), "#{shared_path}/config/database.yml"#, :mode => 0644
['panda_init.rb', 'mailer.rb', 'deploy.rb'].each do |f|
put File.read("config/#{f}"), "#{shared_path}/config/#{f}"#, :mode => 0644
end
end
after "deploy:symlink", "deploy:setup_symlinks"
if target == 'amazon'
# after "deploy:setup_symlinks", "deploy:start_encoder"
end
if target == 'gcx'
# after "deploy:setup_symlinks", "deploy:start_spawner"
end
# Phusion Passenger does auto restart when the symlink changes
namespace :deploy do
task :start_encoder, :roles => :app do
sudo "god", :pty => true
sleep(2)
sudo "god load #{current_path}/encoder.god", :pty => true
sudo "god start encoder", :pty => true
end
task :start_spawner, :roles => :app do
run "god", :pty => true
run "god load #{current_path}/panda.god", :pty => true
run "god stop spawner", :pty => true
run "god start spawner", :pty => true
end
# Phusion Passenger also does auto restart when the symlink changes
task :restart, :roles => :app do
run "touch #{current_path}/tmp/restart.txt"
end
task :start do; end
task :stop do; end
task :setup_symlinks do
case target
when 'amazon'
# Symlink video store dir to /mnt so we make use of the space there
sudo "mkdir -p /mnt/panda/{store,tmp}"
sudo "chown -R panda /mnt/panda"
run "ln -nsf /mnt/panda/tmp #{current_path}/tmp/videos"
run "ln -nsf /mnt/panda/store #{current_path}/public/store"
# put ENV['USER'], "#{current_path}/config/info.txt", :mode => 0644
when 'gcx'
run "ln -nsf /var/www/panda/tmp #{current_path}/tmp/videos"
run "ln -nsf /var/www/panda/store #{current_path}/public/store"
else
run "ln -nsf /mnt/panda/tmp #{current_path}/tmp/videos"
run "ln -nsf /mnt/panda/store #{current_path}/public/store"
end
# Symlink config files
['database.yml', 'panda_init.rb', 'mailer.rb', 'deploy.rb'].each do |f|
run "ln -nsf #{shared_path}/config/#{f} #{current_path}/config/#{f}"
end
# run "cd #{current_path}; rake db:autoupgrade MERB_ENV=production"
end
task :migrate, :roles => :db, :only => { :primary => true } do
rake = fetch(:rake, "rake")
merb_env = fetch(:merb_env, "production")
migrate_env = fetch(:migrate_env, "")
migrate_target = fetch(:migrate_target, :latest)
directory = case migrate_target.to_sym
when :current then current_path
when :latest then current_release
else raise ArgumentError, "unknown migration target #{migrate_target.inspect}"
end
run "cd #{directory}; #{rake} MERB_ENV=#{merb_env} #{migrate_env} db:migrate"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment