twinge (owner)

Revisions

gist: 138980 Download_button fork
public
Public Clone URL: git://gist.github.com/138980.git
Embed All Files: show embed
Text only #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
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