Changeset 536

First step for a Capistrano-Multistage deployment into Joyent Accelerators (work in progress)

Committed by: pedro@joyent.com
Date:  Nov 14 2007 * 18:36 (over 2 years ago)

Affected files:

trunk/config/deploy.rb (Unified diff)

r447r536
1111 --
1212 =end #(end)
1313
14 require 'mongrel_cluster/recipes'
15
16 # SOME THINGS I HAD TO DO TO GET THINGS STARTED ON A NEW ZONE:
17 # * checked out from svn then removed it (as to get my password on there)
18 # * change /etc/passwd so that /bin/bash is the default shell
19 # * added "PermitUserEnvironment yes" to /etc/ssh/sshd_config
20 # * svcadm restart ssh
21 # * created /.ssh/environment
22 # -- PATH=/opt/csw/bin:/usr/bin:/usr/sbin
23 #
24 # cap setup
25 #
26 # * Make any changes to the files in shared
27 # * create db
28 #
29 # cap deploy
30 #
31 # COMMANDS I HAVE CHECKED OUT
32 # cap <command>
33 # commands: setup, start, stop, restart, deploy, rollback, deploy_with_migrations
34
35 # =============================================================================
36 # REQUIRED VARIABLES
37 # =============================================================================
14 require 'erb'
15 require 'config/accelerator/accelerator_tasks'
16 require 'config/recipes/joyent'
17
3818 set :application, "connector"
39 set :repository, "http://svn.joyent.com/joyent/connector-merge"
19 set :repository, "http://svn.joyent.com/opensource/connector/source/trunk"
20
21 # If you aren't deploying to /u/apps/#{application} on the target
22 # servers (which is the default), you can specify the actual location
23 # via the :deploy_to variable:
24 set :deploy_to, "/opt/joyent/#{application}" # I like this location
25
26 # If you aren't using Subversion to manage your source code, specify
27 # your SCM below:
28 set :scm, :subversion
29 set :sudo, "/opt/csw/bin/sudo"
4030
41 role :web, "webhostname"
42 role :app, "apphostname"
43 role :db, "dbhostname", :primary => true
31 # Do not run the sudo command through sh
32 # default_run_options[:shell] = false
4433
45 #set :rails_env, :development
34 # We are going to get role based servers and other details from the stage files
35 # give a look to the config/deploy/ directory for specific stages
36 set :stages, %w(staging production testing)
37 set :default_stage, "testing"
38 require 'capistrano/ext/multistage'
4639
47
48 # =============================================================================
49 # OPTIONAL VARIABLES
50 # =============================================================================
51 set :deploy_to, "/opt/joyent/#{application}"
52 set :mongrel_conf, "#{current_path}/config/mongrel_cluster.yml"
53
54 set :user, "root"
55 set :svn, "/opt/csw/bin/svn"
56 set :sudo, "/opt/csw/bin/sudo"
57
58
59 # =============================================================================
60 # TASKS
61 # =============================================================================
62 task :after_setup do
63 put (File.read('lib/joyent_config.rb'), "#{shared_path}/joyent_config.rb", :mode => 0644)
64 put (File.read('config/database.yml'), "#{shared_path}/database.yml", :mode => 0644)
65 put (File.read('config/environments/production.rb'), "#{shared_path}/production.rb", :mode => 0644)
40
41 # Example dependancies
42 depend :remote, :command, :gem, :roles => :app
43 depend :remote, :command, :ggrep, :roles => :app # This is due to the way we're getting the IP Address into accelerator_tasks.rb
44 depend :remote, :gem, :rcov, '>=0.8.0', :roles => :app
45 depend :remote, :gem, :mongrel, '>=1.0.1',:roles => :app
46 depend :remote, :gem, :hpricot, '>=0.6.0', :roles => :app
47 depend :remote, :gem, :rake, '>=0.7.3', :roles => :app
48 depend :remote, :gem, :tzinfo, '>=0.3.3', :roles => :app
49 depend :remote, :gem, :ezcrypto, '>=0.7.0', :roles => :app
50 depend :remote, :gem, :gettext, '=1.9.0', :roles => :app
51 depend :remote, :gem, :mongrel_cluster, '>=1.0.4', :roles => :app
52
53 deploy.task :restart do
54 accelerator.smf_restart
55 accelerator.restart_apache
6656 end
67
68 task :after_update_code do
69 run "rm #{release_path}/lib/joyent_config.rb"
70 run "cp #{shared_path}/joyent_config.rb #{release_path}/lib/joyent_config.rb"
71
72 # Copy in the database.yml file
73 run "rm #{release_path}/config/database.yml"
74 run "cp #{shared_path}/database.yml #{release_path}/config/database.yml"
75
76 # Copy in a stubbed out production
77 run "rm #{release_path}/config/environments/production.rb"
78 run "cp #{shared_path}/production.rb #{release_path}/config/environments/production.rb"
57
58 deploy.task :start do
59 accelerator.smf_start
60 accelerator.restart_apache
7961 end
62
63 deploy.task :stop do
64 accelerator.smf_stop
65 accelerator.restart_apache
66 end
8067
81 task :before_symlink do
82 run "if [[ -d #{current_path} ]]; then rm #{current_path}; fi"
83 end
84
85 task :start_mongrel_cluster , :roles => :app do
86 set_mongrel_conf
87 run "cd #{current_path}; mongrel_rails cluster::start -C #{mongrel_conf}"
88 end
89
90 task :stop_mongrel_cluster , :roles => :app do
91 set_mongrel_conf
92 run "cd #{current_path}; mongrel_rails cluster::stop -C #{mongrel_conf}"
93 end
94
95 task :restart, :roles => :app do
96 stop
68 # Override the default deploy:cold to include the schema load
69 deploy.task :cold do
70 update
71 run "cd #{current_path}; rake RAILS_ENV=production db:schema:load"
72 migrate
9773 start
9874 end
99
100 task :stop, :roles => :app do
101 stop_mongrel_cluster
102 stop_imap_worker
103 stop_joyent_job
104 end
105
106 task :start, :roles => :app do
107 start_mongrel_cluster
108 start_imap_worker
109 start_joyent_job
110 end
111
112 task :start_imap_worker, :roles => :app do
113 run <<-CMD
114 export RAILS_ENV=#{rails_env};
115 nohup #{current_path}/script/imap_worker start;
116 sleep 5
117 CMD
118 end
119
120 task :stop_imap_worker, :roles => :app do
121 run <<-CMD
122 export RAILS_ENV=#{rails_env};
123 #{current_path}/script/imap_worker stop;
124 sleep 1
125 CMD
126 end
127
128 task :start_joyent_job, :roles => :app do
129 run <<-CMD
130 export RAILS_ENV=#{rails_env};
131 nohup ruby #{current_path}/script/joyent_job start;
132 sleep 5;
133 export RAILS_ENV=#{rails_env};
134 nohup ruby #{current_path}/script/joyent_job start_worker 5;
135 sleep 5
136 CMD
137 end
138
139 task :stop_joyent_job, :roles => :app do
140 run "ruby #{current_path}/script/joyent_job stop"
141 end
142
143 task :before_rollback_code, :except => { :no_release => true } do
144 if releases.length < 2
145 raise "could not rollback the code because there is no prior release"
146 else
147 run "rm #{current_path}"
148 end
149 end
75
76 after :deploy, 'deploy:cleanup'