cohesive (owner)

Revisions

gist: 14609 Download_button fork
public
Description:
Capistrano deploy script for servers built on elasticserver.com
Public Clone URL: git://gist.github.com/14609.git
Embed All Files: show embed
deploy.rb #
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
120
121
122
123
124
# Elastic Server Deployment Script
# Author: Yan Pritzker, CohesiveFT <yan.pritzker@cohesiveft.com>
# Revision: 1.2
# Requires: Capistrano 2.3+
#
# CHANGELOG
#
# Version 1.2:
# * Support for non-nginx servers by auto-detecting the server binary.
# * Backs up pid files from log/ directory before deploy in case they are overwritten.
#
# Version 1.1:
# * Working with cap 2.3, default deploy from local copy
#
# Version 1.0:
# * Initial revision, for cap 2.0
#
 
############################################################
# PLEASE MODIFY THE SECTION BELOW
#
# By default, this script will deploy your app from its
# current directory using the copy strategy. You may want
# to alter settings to have it use your SCM instead.
#
# For more information, please see http://capify.org
#
############################################################
 
# set :repository, "[repository goes here]"
# set :scm_username, "[username goes here]"
# set :scm_password, lambda { CLI.password_prompt "SVN Password (user: #{scm_username}): "}
# set :scm, :subversion
# set :deploy_via, :copy
# set :copy_strategy, :export
 
set :repository, "."
set :scm, :none
set :deploy_via, :copy
 
# This script is designed to prompt you for the ip of your Elastic Server.
# You can hardcode it by changing the :deploy_to_ip variable.
 
set :deploy_to_ip, lambda { HighLine.new.ask "Elastic Server IP: "}
set :user, "cftuser"
set :runner, "cftuser" # required for cap 2.3
set :password, "cftuser" # set :password, lambda { CLI.password_prompt "Target Password (user: #{user}): "}
 
# DO NOT MODIFY BELOW THIS LINE UNLESS YOU KNOW WHAT YOU'RE DOING
 
set :deploy_to, "/usr/local/cft/deploy/capistrano"
set :elastic_server_deploy_target, "/usr/local/cft/deploy/rails"
 
role :app, deploy_to_ip
role :web, deploy_to_ip
role :db, deploy_to_ip, :primary => true
 
before "deploy", "deploy:setup"
before "deploy", "pid:backup"
after "deploy:symlink", "deploy:elastic_server_symlink"
after "deploy:symlink", "pid:restore"
 
# NOTE: This deployment script relies on calling Elastic Server rubberbands
# which control the server (mongrel, etc) that lives in /etc/cft.d/mods-enabled
#
# In a future version, the commands will be performed via webservice.
#
namespace(:rails_server) do
  desc "start the app server"
  task :start, :roles => :app do
    sudo "`find /etc/init.d/ -name cft-rails\*` start"
  end
  
  desc "stop the app server"
  task :stop, :roles => :app do
    sudo "`find /etc/init.d/ -name cft-rails\*` stop"
  end
 
  
  desc "restart the app server"
  task :restart, :roles => :app do
    rails_server.stop
    sleep(2)
    rails_server.start
  end
end
 
namespace(:deploy) do
  desc "Restart the Rails server."
  task :restart, :roles => :app do
    rails_server.restart
  end
  
  desc "Long deploy will throw up the maintenance.html page and run migrations then it restarts and enables the site again."
  task :long do
    transaction do
      update_code
      web.disable
      symlink
      migrate
    end
 
    restart
    web.enable
  end
  
  desc "Creates a symlink in order for proper deployment on Elastic Server"
  task :elastic_server_symlink do
    run "rm -rf #{elastic_server_deploy_target}"
    run "ln -nfs #{current_path} #{elastic_server_deploy_target}"
  end
end
 
namespace(:pid) do
  task :backup do
    run "mkdir -p /tmp/rails_pids && cp #{elastic_server_deploy_target}/log/*.pid /tmp/rails_pids" rescue ""
  end
  
  task :restore do
    run "cp /tmp/rails_pids/* #{elastic_server_deploy_target}/log" rescue ""
  end
end