nesquena-cap-recipes 0.2.17 → 0.2.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.textile CHANGED
@@ -7,7 +7,11 @@ h2. INSTALLATION
7
7
 
8
8
  h2. DESCRIPTION
9
9
 
10
- This is a collection of capistrano recipes which will grow to encompass many useful recipes. The intended use for these recipes is for a ruby project which deploys using Phusion Passenger and caches using memcached. In addition, recipes for the management of various daemon processes will be included as needed. Feel free to contribute to this and make it better!
10
+ This is a collection of capistrano recipes which will grow to encompass many useful recipes.
11
+ The intended use for these recipes is for a ruby project which deploys using Phusion Passenger and caches using memcached.
12
+ In addition, recipes for the management of various daemon processes will be included as needed.
13
+ Feel free to contribute to this and make it better!
14
+ Any of the recipes can be used on their own (TODO).
11
15
 
12
16
  Currently included:
13
17
 
@@ -22,6 +26,7 @@ h2. SYNOPSIS
22
26
  To include any of these into your deploy.rb configuration file for Capistrano:
23
27
 
24
28
  require 'cap_recipes/tasks/passenger'
29
+ require 'cap_recipes/tasks/rails'
25
30
  require 'cap_recipes/tasks/apache'
26
31
  require 'cap_recipes/tasks/backgroundrb'
27
32
  require 'cap_recipes/tasks/juggernaut'
@@ -30,9 +35,38 @@ To include any of these into your deploy.rb configuration file for Capistrano:
30
35
  Or to include and activate all of them:
31
36
 
32
37
  require 'cap_recipes'
38
+
39
+ By default, these recipes will include both tasks for managing (start/stop/restart) as well as tasks for installing when available.
40
+ The recipes also include hooks which tie all the recipes into the deployment process as appropriate.
41
+
42
+ If you wish to cherry-pick specific tasks, you can also include the management tasks, installation tasks and deploy hooks seperately.
43
+
44
+ require 'cap_recipes/tasks/memcache/install.rb' # memcache installation tasks
45
+ require 'cap_recipes/tasks/memcache/manage.rb' # memcache daemon management tasks
46
+ require 'cap_recipes/tasks/memcache/hooks.rb' # memcache deployment hooks
33
47
 
34
48
  h2. USAGE
35
49
 
50
+ h3. Apache
51
+
52
+ h4. Configuration
53
+
54
+ * apache_init_path - the path to the init.d apache file [default: '/etc/init.d/apache2']
55
+
56
+ h4. Tasks
57
+
58
+ h5. manage.rb
59
+
60
+ apache
61
+ :stop
62
+ :start
63
+ :restart
64
+
65
+ h5. install.rb
66
+
67
+ apache
68
+ :install
69
+
36
70
  h3. Passenger
37
71
 
38
72
  h4. Configuration
@@ -41,42 +75,47 @@ h4. Configuration
41
75
  * local_ping_path - the localhost path to ping to start passenger [default: "http://localhost"]
42
76
 
43
77
  The following files and folders are expected to exist:
44
-
45
78
  * "#{base_ruby_path}/lib/ruby"
46
79
  * "#{base_ruby_path}/bin/ruby"
47
80
  * "#{base_ruby_path}/bin/gem"
48
81
 
49
82
  h4. Tasks
50
83
 
84
+ h5. manage.rb
85
+
51
86
  deploy
52
87
  :start
53
88
  :stop
54
89
  :restart
55
90
  :with_migrations
56
- :copy_config
57
- :tail
58
- install
59
- :passenger
60
- :gems
61
- sweep
62
- :cache
63
- :log
64
- :gems
65
-
66
- h3. Apache
91
+
92
+ h5. install.rb
67
93
 
68
- h4. Configuration
94
+ passenger
95
+ :install
69
96
 
70
- * apache_init_path - the path to the init.d apache file [default: '/etc/init.d/apache2']
97
+ h3. Rails
71
98
 
72
99
  h4. Tasks
73
100
 
74
- apache
75
- :stop
76
- :start
77
- :restart
78
- :install
79
-
101
+ h5. tasks.rb
102
+
103
+ rails
104
+ :symlink_db_config
105
+ :repair_permissions
106
+ :tail - tail production log
107
+ :ping - ping the server to start it
108
+ sweep
109
+ :cache
110
+ :log
111
+
112
+ h5. hooks.rb
113
+
114
+ after "deploy:update_code", "rails:symlink_db_config" # copy database.yml file to release path
115
+ after "deploy:update_code", "rails:sweep:cache" # clear cache after updating code
116
+ after "deploy:restart" , "rails:repair_permissions" # fix the permissions to work properly
117
+ after "deploy:restart" , "rails:ping" # ping passenger to start the rails instance
118
+
80
119
  h3. Backgroundrb
81
120
 
82
121
  h4. Configuration
@@ -87,13 +126,20 @@ h4. Configuration
87
126
 
88
127
  h4. Tasks
89
128
 
90
- tasks:
91
- backgroundrb
92
- :stop
93
- :start
94
- :restart
95
- :copy_config
96
- :tail
129
+ h5. manage.rb
130
+
131
+ backgroundrb
132
+ :stop
133
+ :start
134
+ :restart
135
+ :symlink_config
136
+ :tail
137
+
138
+ h5. hooks.rb
139
+
140
+ after "deploy:update_code" , "backgroundrb:symlink_config" # copy backgroundrb config to release
141
+ after "deploy:restart" , "backgroundrb:restart" # restart backgroundrb daemon
142
+ after "backgroundrb:restart" , "backgroundrb:repair_permissions" # restart backgroundrb damon
97
143
 
98
144
  h3. Juggernaut
99
145
 
@@ -105,14 +151,20 @@ h4. Configuration
105
151
 
106
152
  h4. Tasks
107
153
 
108
- tasks:
109
- juggernaut
110
- :start
111
- :stop
112
- :restart
113
- :copy_config
114
- :tail
115
-
154
+ h5. manage.rb
155
+
156
+ juggernaut
157
+ :start
158
+ :stop
159
+ :restart
160
+ :symlink_config
161
+ :tail
162
+
163
+ h5. hooks.rb
164
+
165
+ after "deploy:update_code", "juggernaut:symlink_config" # copy juggernaut.yml to release
166
+ after "deploy:restart" , "juggernaut:restart" # restart juggernaut daemon
167
+
116
168
  h3. Memcache
117
169
 
118
170
  h4. Configuration
@@ -121,13 +173,22 @@ h4. Configuration
121
173
 
122
174
  h4. Tasks
123
175
 
124
- tasks:
125
- memcache
126
- :start
127
- :stop
128
- :restart
129
- :install
130
-
176
+ h5. manage.rb
177
+
178
+ memcache
179
+ :start
180
+ :stop
181
+ :restart
182
+
183
+ h5. install.rb
184
+
185
+ memcache
186
+ :install
187
+
188
+ h5. hooks
189
+
190
+ after "deploy:restart", "memcache:restart" # clear cache after updating code
191
+
131
192
  h2. EXAMPLE
132
193
 
133
194
  Here is a sample deploy.rb file using cap_recipes:
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- :patch: 17
2
+ :patch: 19
3
3
  :major: 0
4
4
  :minor: 2
@@ -0,0 +1,12 @@
1
+ Capistrano::Configuration.instance(true).load do
2
+
3
+ namespace :apache do
4
+
5
+ desc 'Installs apache 2 and development headers to compile passenger'
6
+ task :install, :roles => :web do
7
+ puts 'Installing apache 2'
8
+ try_sudo 'apt-get install apache2 apache2.2-common apache2-mpm-prefork apache2-utils libexpat1 ssl-cert libapr1 libapr1-dev libaprutil1 libmagic1 libpcre3 libpq5 openssl apache2-prefork-dev -y'
9
+ end
10
+
11
+ end
12
+ end
@@ -0,0 +1,26 @@
1
+ Capistrano::Configuration.instance(true).load do
2
+
3
+ set :apache_init_path, "/etc/init.d/apache2"
4
+
5
+ namespace :apache do
6
+
7
+ desc "Stops the apache web server"
8
+ task :stop, :roles => :web do
9
+ puts "Stopping the apache server"
10
+ sudo "#{apache_init_path} stop"
11
+ end
12
+
13
+ desc "Starts the apache web server"
14
+ task :start, :roles => :web do
15
+ puts "Starting the apache server"
16
+ sudo "#{apache_init_path} start"
17
+ end
18
+
19
+ desc "Restarts the apache web server"
20
+ task :restart, :roles => :web do
21
+ puts "Restarting the apache server"
22
+ sudo "#{apache_init_path} restart"
23
+ end
24
+
25
+ end
26
+ end
@@ -1,38 +1 @@
1
- Capistrano::Configuration.instance(true).load do
2
-
3
- set :apache_init_path, "/etc/init.d/apache2"
4
-
5
- # ===============================================================
6
- # SERVER MANAGEMENT
7
- # ===============================================================
8
-
9
- namespace :apache do
10
- desc "Stops the apache web server"
11
- task :stop, :roles => :web do
12
- puts "Stopping the apache server"
13
- sudo "#{apache_init_path} stop"
14
- end
15
-
16
- desc "Starts the apache web server"
17
- task :start, :roles => :web do
18
- puts "Starting the apache server"
19
- sudo "#{apache_init_path} start"
20
- end
21
-
22
- desc "Restarts the apache web server"
23
- task :restart, :roles => :web do
24
- puts "Restarting the apache server"
25
- sudo "#{apache_init_path} restart"
26
- end
27
-
28
- # ===============================================================
29
- # INSTALLATION
30
- # ===============================================================
31
-
32
- desc 'Installs apache 2 and development headers to compile passenger'
33
- task :install, :roles => :web do
34
- puts 'Installing apache 2'
35
- try_sudo 'apt-get install apache2 apache2.2-common apache2-mpm-prefork apache2-utils libexpat1 ssl-cert libapr1 libapr1-dev libaprutil1 libmagic1 libpcre3 libpq5 openssl apache2-prefork-dev -y'
36
- end
37
- end
38
- end
1
+ Dir[File.join(File.dirname(__FILE__), 'apache/*.rb')].sort.each { |lib| require lib }
@@ -0,0 +1,5 @@
1
+ Capistrano::Configuration.instance(true).load do
2
+ after "deploy:update_code" , "backgroundrb:symlink_config"
3
+ after "deploy:restart" , "backgroundrb:restart"
4
+ after "backgroundrb:restart" , "backgroundrb:repair_permissions"
5
+ end
@@ -0,0 +1,63 @@
1
+ require 'yaml'
2
+
3
+ Capistrano::Configuration.instance(true).load do
4
+ set :backgroundrb_host, 'localhost'
5
+ set :backgroundrb_env , 'production'
6
+
7
+ namespace :backgroundrb do
8
+ # ===============================================================
9
+ # PROCESS MANAGEMENT
10
+ # ===============================================================
11
+
12
+ desc "Stops the backgroundrb worker processes"
13
+ task :stop, :roles => :app do
14
+ run "cd #{current_path} && #{sudo} ruby script/backgroundrb stop -e #{backgroundrb_env}"
15
+ end
16
+
17
+ desc "Starts the backgroundrb worker processes"
18
+ task :start, :roles => :app do
19
+ run "cd #{current_path} && #{sudo} nohup ruby script/backgroundrb start -e #{backgroundrb_env}"
20
+ end
21
+
22
+ desc "Restarts a running backgroundrb server."
23
+ task :restart, :roles => :app do
24
+ backgroundrb.stop
25
+ sleep(5) # sleep for 5 seconds to make sure the server has mopped up everything
26
+ backgroundrb.start
27
+ end
28
+
29
+ # ===============================================================
30
+ # PROCESS CONFIGURATION
31
+ # ===============================================================
32
+
33
+ desc "Creates configuration file for the backgroundrb server"
34
+ task :configure, :roles => :app do
35
+ config = { :backgroundrb => {:ip => backgroundrb_host, :port => backgroundrb_port, :environment => backgroundrb_env} }
36
+ backgroundrb_yml = config.to_yaml
37
+
38
+ run "if [ ! -d #{shared_path}/config ]; then mkdir #{shared_path}/config; fi"
39
+ put(backgroundrb_yml, "#{shared_path}/config/backgroundrb.yml", :mode => 0644)
40
+ end
41
+
42
+ # ===============================================================
43
+ # FILE MANAGEMENT
44
+ # ===============================================================
45
+
46
+ desc "Symlinks the shared/config/backgroundrb yaml to release/config/"
47
+ task :symlink_config, :roles => :app do
48
+ run "ln -s #{shared_path}/config/backgroundrb.yml #{release_path}/config/backgroundrb.yml"
49
+ end
50
+
51
+ desc "Displays the backgroundrb log from the server"
52
+ task :tail do
53
+ stream "tail -f #{shared_path}/log/backgroundrb_#{backgroundrb_port}.log"
54
+ end
55
+
56
+ desc "Repair permissions to allow user to perform all actions"
57
+ task :repair_permissions, :roles => :app do
58
+ puts "Applying correct permissions to allow for proper command execution"
59
+ try_sudo "chown -R #{user}:#{user} #{current_path}"
60
+ try_sudo "chown -R #{user}:#{user} #{current_path}/tmp"
61
+ end
62
+ end
63
+ end
@@ -1,75 +1 @@
1
- require 'yaml'
2
-
3
- Capistrano::Configuration.instance(true).load do
4
- set :backgroundrb_host, 'localhost'
5
- set :backgroundrb_env , 'production'
6
-
7
- namespace :backgroundrb do
8
- # ===============================================================
9
- # PROCESS MANAGEMENT
10
- # ===============================================================
11
-
12
- desc "Stops the backgroundrb worker processes"
13
- task :stop, :roles => :app do
14
- run "cd #{current_path} && #{sudo} ruby script/backgroundrb stop -e #{backgroundrb_env}"
15
- end
16
-
17
- desc "Starts the backgroundrb worker processes"
18
- task :start, :roles => :app do
19
- run "cd #{current_path} && #{sudo} nohup ruby script/backgroundrb start -e #{backgroundrb_env}"
20
- end
21
-
22
- desc "Restarts a running backgroundrb server."
23
- task :restart, :roles => :app do
24
- backgroundrb.stop
25
- sleep(5) # sleep for 5 seconds to make sure the server has mopped up everything
26
- backgroundrb.start
27
- end
28
-
29
- # ===============================================================
30
- # PROCESS CONFIGURATION
31
- # ===============================================================
32
-
33
- desc "Creates configuration file for the backgroundrb server"
34
- task :configure, :roles => :app do
35
- config = { :backgroundrb => {:ip => backgroundrb_host, :port => backgroundrb_port, :environment => backgroundrb_env} }
36
- backgroundrb_yml = config.to_yaml
37
-
38
- run "if [ ! -d #{shared_path}/config ]; then mkdir #{shared_path}/config; fi"
39
- put(backgroundrb_yml, "#{shared_path}/config/backgroundrb.yml", :mode => 0644)
40
- end
41
-
42
- # ===============================================================
43
- # FILE MANAGEMENT
44
- # ===============================================================
45
-
46
- desc "Copies the shared/config/backgroundrb yaml to release/config/"
47
- task :copy_config, :roles => :app do
48
- on_rollback {
49
- puts "***** File shared/config/backgroundrb.yml is missing. Make sure you have run backgroundrb:configure first. *****"
50
- }
51
-
52
- run "ln -s #{shared_path}/config/backgroundrb.yml #{release_path}/config/backgroundrb.yml"
53
- end
54
-
55
- desc "Displays the backgroundrb log from the server"
56
- task :tail do
57
- stream "tail -f #{shared_path}/log/backgroundrb_#{backgroundrb_port}.log"
58
- end
59
-
60
- desc "Repair permissions to allow user to perform all actions"
61
- task :repair_permissions, :roles => :app do
62
- puts "Applying correct permissions to allow for proper command execution"
63
- try_sudo "chown -R #{user}:#{user} #{current_path}"
64
- try_sudo "chown -R #{user}:#{user} #{current_path}/tmp"
65
- end
66
- end
67
-
68
- # ===============================================================
69
- # TASK CALLBACKS
70
- # ===============================================================
71
-
72
- after "deploy:update_code" , "backgroundrb:copy_config"
73
- after "deploy:restart" , "backgroundrb:restart"
74
- after "backgroundrb:restart" , "backgroundrb:repair_permissions"
75
- end
1
+ Dir[File.join(File.dirname(__FILE__), 'backgroundrb/*.rb')].sort.each { |lib| require lib }
@@ -0,0 +1,4 @@
1
+ Capistrano::Configuration.instance(true).load do
2
+ after "deploy:update_code", "juggernaut:symlink_config" # copy juggernaut.yml on update code
3
+ after "deploy:restart" , "juggernaut:restart" # restart juggernaut on app restart
4
+ end
@@ -0,0 +1,46 @@
1
+ Capistrano::Configuration.instance(true).load do
2
+ set :juggernaut_config, "#{current_path}/config/juggernaut.yml"
3
+ set :juggernaut_pid, "#{current_path}/tmp/pids/juggernaut.pid"
4
+ set :juggernaut_log, "#{current_path}/log/juggernaut.log"
5
+
6
+ namespace :juggernaut do
7
+
8
+ # ===============================================================
9
+ # PROCESS MANAGEMENT
10
+ # ===============================================================
11
+
12
+ desc "Starts the juggernaut push server"
13
+ task :start, :roles => :app do
14
+ puts "Starting juggernaut push server"
15
+ try_sudo "juggernaut -c #{juggernaut_config} -d --pid #{juggernaut_pid} --log #{juggernaut_log}"
16
+ end
17
+
18
+ desc "Stops the juggernaut push server"
19
+ task :stop, :roles => :app do
20
+ puts "Stopping juggernaut push server"
21
+ try_sudo "juggernaut -c #{juggernaut_config} -k * --pid #{juggernaut_pid} --log #{juggernaut_log}"
22
+ end
23
+
24
+ desc "Restarts the juggernaut push server"
25
+ task :restart, :roles => :app do
26
+ juggernaut.stop
27
+ juggernaut.start
28
+ end
29
+
30
+ # ===============================================================
31
+ # FILE MANAGEMENT
32
+ # ===============================================================
33
+
34
+ desc "Symlinks the shared/config/juggernaut yaml to release/config/"
35
+ task :symlink_config, :roles => :app do
36
+ try_sudo "ln -s #{shared_path}/config/juggernaut.yml #{release_path}/config/juggernaut.yml"
37
+ end
38
+
39
+ desc "Displays the juggernaut log from the server"
40
+ task :tail, :roles => :app do
41
+ stream "tail -f #{shared_path}/log/juggernaut.log"
42
+ end
43
+
44
+ end
45
+
46
+ end
@@ -1,50 +1 @@
1
- Capistrano::Configuration.instance(true).load do
2
- set :juggernaut_config, "#{current_path}/config/juggernaut.yml"
3
- set :juggernaut_pid, "#{current_path}/tmp/pids/juggernaut.pid"
4
- set :juggernaut_log, "#{current_path}/log/juggernaut.log"
5
-
6
- namespace :juggernaut do
7
- # ===============================================================
8
- # PROCESS MANAGEMENT
9
- # ===============================================================
10
-
11
- desc "Starts the juggernaut push server"
12
- task :start, :roles => :app do
13
- puts "Starting juggernaut push server"
14
- try_sudo "juggernaut -c #{juggernaut_config} -d --pid #{juggernaut_pid} --log #{juggernaut_log}"
15
- end
16
-
17
- desc "Stops the juggernaut push server"
18
- task :stop, :roles => :app do
19
- puts "Stopping juggernaut push server"
20
- try_sudo "juggernaut -c #{juggernaut_config} -k * --pid #{juggernaut_pid} --log #{juggernaut_log}"
21
- end
22
-
23
- desc "Restarts the juggernaut push server"
24
- task :restart, :roles => :app do
25
- juggernaut.stop
26
- juggernaut.start
27
- end
28
-
29
- # ===============================================================
30
- # FILE MANAGEMENT
31
- # ===============================================================
32
-
33
- desc "Copies the shared/config/juggernaut yaml to release/config/"
34
- task :copy_config, :roles => :app do
35
- try_sudo "ln -s #{shared_path}/config/juggernaut.yml #{release_path}/config/juggernaut.yml"
36
- end
37
-
38
- desc "Displays the juggernaut log from the server"
39
- task :tail, :roles => :app do
40
- stream "tail -f #{shared_path}/log/juggernaut.log"
41
- end
42
- end
43
-
44
- # ===============================================================
45
- # TASK CALLBACKS
46
- # ===============================================================
47
-
48
- after "deploy:update_code", "juggernaut:copy_config" # copy juggernaut.yml on update code
49
- after "deploy:restart" , "juggernaut:restart" # restart juggernaut on app restart
50
- end
1
+ Dir[File.join(File.dirname(__FILE__), 'juggernaut/*.rb')].sort.each { |lib| require lib }
@@ -0,0 +1,5 @@
1
+ Capistrano::Configuration.instance(true).load do
2
+
3
+ after "deploy:restart", "memcache:restart" # clear cache after updating code
4
+
5
+ end
@@ -0,0 +1,20 @@
1
+ Capistrano::Configuration.instance(true).load do
2
+
3
+ set :memcache_init_path, "/etc/init.d/memcached"
4
+
5
+ # ===============================================================
6
+ # SERVER MANAGEMENT
7
+ # ===============================================================
8
+
9
+ namespace :memcache do
10
+
11
+ desc 'Installs memcache and the ruby gem'
12
+ task :install, :roles => :app do
13
+ puts 'Installing memcache'
14
+ try_sudo 'apt-get install memcached'
15
+ try_sudo "#{base_ruby_path}/bin/gem install memcache-client --no-ri --no-rdoc"
16
+ memcache.start
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,28 @@
1
+ Capistrano::Configuration.instance(true).load do
2
+
3
+ set :memcache_init_path, "/etc/init.d/memcached"
4
+
5
+ namespace :memcache do
6
+
7
+ desc "Stops the memcache server"
8
+ task :stop, :roles => :app do
9
+ puts "Stopping the memcache server"
10
+ try_sudo "nohup /etc/init.d/memcached stop &"
11
+ end
12
+
13
+ desc "Starts the memcache server"
14
+ task :start, :roles => :app do
15
+ puts "Starting the memcache server"
16
+ try_sudo "nohup /etc/init.d/memcached start &"
17
+ end
18
+
19
+ desc "Restarts the memcache server"
20
+ task :restart, :roles => :app do
21
+ puts "Restarting the memcache server"
22
+ memcache.stop
23
+ sleep(3) # sleep for 3 seconds to make sure the server has mopped up everything
24
+ memcache.start
25
+ end
26
+
27
+ end
28
+ end
@@ -1,44 +1 @@
1
- Capistrano::Configuration.instance(true).load do
2
-
3
- set :memcache_init_path, "/etc/init.d/memcached"
4
-
5
- # ===============================================================
6
- # SERVER MANAGEMENT
7
- # ===============================================================
8
-
9
- namespace :memcache do
10
- desc "Stops the memcache server"
11
- task :stop, :roles => :app do
12
- puts "Stopping the memcache server"
13
- try_sudo "nohup /etc/init.d/memcached stop &"
14
- end
15
-
16
- desc "Starts the memcache server"
17
- task :start, :roles => :app do
18
- puts "Starting the memcache server"
19
- try_sudo "nohup /etc/init.d/memcached start &"
20
- end
21
-
22
- desc "Restarts the memcache server"
23
- task :restart, :roles => :app do
24
- puts "Restarting the memcache server"
25
- memcache.stop
26
- sleep(3) # sleep for 3 seconds to make sure the server has mopped up everything
27
- memcache.start
28
- end
29
-
30
- # ===============================================================
31
- # INSTALLATION
32
- # ===============================================================
33
-
34
- desc 'Installs memcache and the ruby gem'
35
- task :install, :roles => :app do
36
- puts 'Installing memcache'
37
- try_sudo 'apt-get install memcached'
38
- try_sudo "#{base_ruby_path}/bin/gem install memcache-client --no-ri --no-rdoc"
39
- memcache.start
40
- end
41
- end
42
-
43
- after "deploy:restart", "memcache:restart" # clear cache after updating code
44
- end
1
+ Dir[File.join(File.dirname(__FILE__), 'memcache/*.rb')].sort.each { |lib| require lib }
@@ -0,0 +1,49 @@
1
+ require 'cap_recipes/tasks/with_scope.rb'
2
+
3
+ #TODO add something like require that a task named apache:restart exists
4
+ Capistrano::Configuration.instance(true).load do
5
+ set :base_ruby_path, '/usr'
6
+
7
+ namespace :passenger do
8
+ desc "Installs Phusion Passenger"
9
+ task :install, :roles => :web do
10
+ puts 'Installing passenger module'
11
+ enable_apache_module
12
+ update_config
13
+ end
14
+
15
+ desc "Setup Passenger Module"
16
+ task :enable_apache_module, :roles => :web do
17
+ sudo "#{base_ruby_path}/bin/gem install passenger --no-ri --no-rdoc"
18
+ sudo "#{base_ruby_path}/bin/passenger-install-apache2-module", :pty => true do |ch, stream, data|
19
+ if data =~ /Press\sEnter\sto\scontinue/ || data =~ /Press\sENTER\sto\scontinue/
20
+ ch.send_data("\n")
21
+ else
22
+ Capistrano::Configuration.default_io_proc.call(ch, stream, data)
23
+ end
24
+ end
25
+ end
26
+
27
+ desc "Configure Passenger"
28
+ task :update_config, :roles => :web do
29
+ version = 'ERROR' # default
30
+
31
+ # passenger (2.X.X, 1.X.X)
32
+ run("gem list | grep passenger") do |ch, stream, data|
33
+ version = data.sub(/passenger \(([^,]+).*?\)/,"\\1").strip
34
+ end
35
+
36
+ puts " passenger version #{version} configured"
37
+
38
+ passenger_config =<<-EOF
39
+ LoadModule passenger_module #{base_ruby_path}/lib/ruby/gems/1.8/gems/passenger-#{version}/ext/apache2/mod_passenger.so
40
+ PassengerRoot #{base_ruby_path}/lib/ruby/gems/1.8/gems/passenger-#{version}
41
+ PassengerRuby #{base_ruby_path}/bin/ruby
42
+ EOF
43
+
44
+ put passenger_config, "/tmp/passenger"
45
+ sudo "mv /tmp/passenger /etc/apache2/conf.d/passenger"
46
+ apache.restart
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,41 @@
1
+ require 'cap_recipes/tasks/with_scope.rb'
2
+
3
+ Capistrano::Configuration.instance(true).load do
4
+ namespace :deploy do
5
+
6
+ desc "Default deploy action"
7
+ task :default, :roles => :web do
8
+ with_role(:web) do
9
+ update
10
+ restart
11
+ end
12
+ end
13
+
14
+ desc "Stops the phusion passenger server"
15
+ task :stop, :roles => :web do
16
+ puts "Stopping rails web server"
17
+ apache.stop
18
+ end
19
+
20
+ desc "Starts the phusion passenger server"
21
+ task :start, :roles => :web do
22
+ puts "Starting rails web server"
23
+ apache.start
24
+ end
25
+
26
+ desc "Restarts the phusion passenger server"
27
+ task :restart, :roles => :web do
28
+ run "touch #{current_path}/tmp/restart.txt"
29
+ end
30
+
31
+ desc "Update code on server, apply migrations, and restart passenger server"
32
+ task :with_migrations, :roles => :web do
33
+ with_role(:web) do
34
+ deploy.update
35
+ deploy.migrate
36
+ deploy.restart
37
+ end
38
+ end
39
+
40
+ end
41
+ end
@@ -1,161 +1 @@
1
- require 'cap_recipes/tasks/with_scope.rb'
2
-
3
- Capistrano::Configuration.instance(true).load do
4
- set :base_ruby_path, '/usr'
5
- set :local_ping_path, 'http://localhost'
6
-
7
- # ===============================================================
8
- # DEPLOYMENT SCRIPTS
9
- # ===============================================================
10
-
11
- namespace :deploy do
12
-
13
- desc "Default deploy action"
14
- task :default, :roles => :web do
15
- with_role(:web) do
16
- update
17
- restart
18
- end
19
- end
20
-
21
- # ===============================================================
22
- # SERVER MANAGEMENT
23
- # ===============================================================
24
-
25
- desc "Stops the phusion passenger server"
26
- task :stop, :roles => :web do
27
- puts "Stopping rails web server"
28
- apache.stop
29
- end
30
-
31
- desc "Starts the phusion passenger server"
32
- task :start, :roles => :web do
33
- puts "Starting rails web server"
34
- apache.start
35
- end
36
-
37
- desc "Restarts the phusion passenger server"
38
- task :restart, :roles => :web do
39
- puts "Restarting the application"
40
- run "touch #{current_path}/tmp/restart.txt"
41
- end
42
-
43
- desc "Update code on server, apply migrations, and restart passenger server"
44
- task :with_migrations, :roles => :web do
45
- with_role(:web) do
46
- deploy.update
47
- deploy.migrate
48
- deploy.restart
49
- end
50
- end
51
-
52
- # ===============================================================
53
- # UTILITY TASKS
54
- # ===============================================================
55
-
56
- desc "Copies the shared/config/database yaml to release/config/"
57
- task :copy_config, :roles => :web do
58
- puts "Copying database configuration to release path"
59
- try_sudo "ln -s #{shared_path}/config/database.yml #{release_path}/config/database.yml"
60
- end
61
-
62
- desc "Repair permissions to allow user to perform all actions"
63
- task :repair_permissions, :roles => :web do
64
- puts "Applying correct permissions to allow for proper command execution"
65
- try_sudo "chmod -R 744 #{current_path}/log #{current_path}/tmp"
66
- try_sudo "chown -R #{user}:#{user} #{current_path}"
67
- try_sudo "chown -R #{user}:#{user} #{current_path}/tmp"
68
- end
69
-
70
- desc "Displays the production log from the server locally"
71
- task :tail, :roles => :web do
72
- stream "tail -f #{shared_path}/log/production.log"
73
- end
74
-
75
- desc "Pings the root localhost to startup passenger"
76
- task :ping, :roles => :web do
77
- puts "Pinging the web server to start passenger"
78
- run "wget -O /dev/null #{local_ping_path} 2>/dev/null"
79
- end
80
- end
81
-
82
- # ===============================================================
83
- # INSTALLATION
84
- # ===============================================================
85
-
86
- namespace :install do
87
-
88
- desc "Updates all installed ruby gems"
89
- task :gems, :roles => :web do
90
- try_sudo "gem update"
91
- end
92
-
93
- desc "Installs Phusion Passenger"
94
- task :passenger, :roles => :web do
95
- puts 'Installing passenger module'
96
- install.passenger_apache_module
97
- install.config_passenger
98
- end
99
-
100
- desc "Setup Passenger Module"
101
- task :passenger_apache_module, :roles => :web do
102
- sudo "#{base_ruby_path}/bin/gem install passenger --no-ri --no-rdoc"
103
- input = ''
104
- sudo "#{base_ruby_path}/bin/passenger-install-apache2-module", :pty => true do |ch, stream, data|
105
- if data =~ /Press\sEnter\sto\scontinue/ || data =~ /Press\sENTER\sto\scontinue/
106
- ch.send_data("\n")
107
- else
108
- Capistrano::Configuration.default_io_proc.call(ch, stream, data)
109
- end
110
- end
111
- end
112
-
113
- desc "Configure Passenger"
114
- task :config_passenger, :roles => :web do
115
- version = 'ERROR' # default
116
-
117
- # passenger (2.X.X, 1.X.X)
118
- run("gem list | grep passenger") do |ch, stream, data|
119
- version = data.sub(/passenger \(([^,]+).*?\)/,"\\1").strip
120
- end
121
-
122
- puts " passenger version #{version} configured"
123
-
124
- passenger_config =<<-EOF
125
- LoadModule passenger_module #{base_ruby_path}/lib/ruby/gems/1.8/gems/passenger-#{version}/ext/apache2/mod_passenger.so
126
- PassengerRoot #{base_ruby_path}/lib/ruby/gems/1.8/gems/passenger-#{version}
127
- PassengerRuby #{base_ruby_path}/bin/ruby
128
- EOF
129
-
130
- put passenger_config, "/tmp/passenger"
131
- sudo "mv /tmp/passenger /etc/apache2/conf.d/passenger"
132
- apache.restart
133
- end
134
-
135
- end
136
-
137
- # ===============================================================
138
- # MAINTENANCE TASKS
139
- # ===============================================================
140
- namespace :sweep do
141
- desc "Clear file-based fragment and action caching"
142
- task :log, :roles => :web do
143
- puts "Sweeping all the log files"
144
- run "cd #{current_path} && #{sudo} rake log:clear RAILS_ENV=production"
145
- end
146
-
147
- desc "Clear file-based fragment and action caching"
148
- task :cache, :roles => :web do
149
- puts "Sweeping the fragment and action cache stores"
150
- run "cd #{release_path} && #{sudo} rake tmp:cache:clear RAILS_ENV=production"
151
- end
152
- end
153
-
154
- # ===============================================================
155
- # TASK CALLBACKS
156
- # ===============================================================
157
- after "deploy:update_code", "deploy:copy_config" # copy database.yml file to release path
158
- after "deploy:update_code", "sweep:cache" # clear cache after updating code
159
- after "deploy:restart" , "deploy:repair_permissions" # fix the permissions to work properly
160
- after "deploy:restart" , "deploy:ping" # ping passenger to start the rails instance
161
- end
1
+ Dir[File.join(File.dirname(__FILE__), 'passenger/*.rb')].sort.each { |lib| require lib }
@@ -0,0 +1,8 @@
1
+ require 'cap_recipes/tasks/with_scope.rb'
2
+
3
+ Capistrano::Configuration.instance(true).load do
4
+ after "deploy:update_code", "rails:symlink_db_config" # copy database.yml file to release path
5
+ after "deploy:update_code", "rails:sweep:cache" # clear cache after updating code
6
+ after "deploy:restart" , "rails:repair_permissions" # fix the permissions to work properly
7
+ after "deploy:restart" , "rails:ping" # ping passenger to start the rails instance
8
+ end
@@ -0,0 +1,53 @@
1
+ require 'cap_recipes/tasks/with_scope.rb'
2
+
3
+ Capistrano::Configuration.instance(true).load do
4
+ set :local_ping_path, 'http://localhost'
5
+
6
+ namespace :rails do
7
+ # ===============================================================
8
+ # UTILITY TASKS
9
+ # ===============================================================
10
+ desc "Symlinks the shared/config/database yaml to release/config/"
11
+ task :symlink_db_config, :roles => :web do
12
+ puts "Copying database configuration to release path"
13
+ try_sudo "rm #{release_path}/config/database.yml -f"
14
+ try_sudo "ln -s #{shared_path}/config/database.yml #{release_path}/config/database.yml"
15
+ end
16
+
17
+ desc "Repair permissions to allow user to perform all actions"
18
+ task :repair_permissions, :roles => :web do
19
+ puts "Applying correct permissions to allow for proper command execution"
20
+ try_sudo "chmod -R 744 #{current_path}/log #{current_path}/tmp"
21
+ try_sudo "chown -R #{user}:#{user} #{current_path}"
22
+ try_sudo "chown -R #{user}:#{user} #{current_path}/tmp"
23
+ end
24
+
25
+ desc "Displays the production log from the server locally"
26
+ task :tail, :roles => :web do
27
+ stream "tail -f #{shared_path}/log/production.log"
28
+ end
29
+
30
+ desc "Pings localhost to startup server"
31
+ task :ping, :roles => :web do
32
+ puts "Pinging the web server to start it"
33
+ run "wget -O /dev/null #{local_ping_path} 2>/dev/null"
34
+ end
35
+
36
+ # ===============================================================
37
+ # MAINTENANCE TASKS
38
+ # ===============================================================
39
+ namespace :sweep do
40
+ desc "Clear file-based fragment and action caching"
41
+ task :log, :roles => :web do
42
+ puts "Sweeping all the log files"
43
+ run "cd #{current_path} && #{sudo} rake log:clear RAILS_ENV=production"
44
+ end
45
+
46
+ desc "Clear file-based fragment and action caching"
47
+ task :cache, :roles => :web do
48
+ puts "Sweeping the fragment and action cache stores"
49
+ run "cd #{release_path} && #{sudo} rake tmp:cache:clear RAILS_ENV=production"
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1 @@
1
+ Dir[File.join(File.dirname(__FILE__), 'rails/*.rb')].sort.each { |lib| require lib }
data/lib/cap_recipes.rb CHANGED
@@ -1 +1 @@
1
- Dir[File.join(File.dirname(__FILE__), 'cap_recipes/**/*.rb')].sort.each { |lib| require lib }
1
+ Dir[File.join(File.dirname(__FILE__), 'cap_recipes/tasks/*.rb')].sort.each { |lib| require lib }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nesquena-cap-recipes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.17
4
+ version: 0.2.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Esquenazi
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-02-08 00:00:00 -08:00
12
+ date: 2009-02-15 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -26,11 +26,31 @@ files:
26
26
  - VERSION.yml
27
27
  - lib/cap_recipes
28
28
  - lib/cap_recipes/tasks
29
+ - lib/cap_recipes/tasks/apache
30
+ - lib/cap_recipes/tasks/apache/install.rb
31
+ - lib/cap_recipes/tasks/apache/manage.rb
29
32
  - lib/cap_recipes/tasks/apache.rb
33
+ - lib/cap_recipes/tasks/backgroundrb
34
+ - lib/cap_recipes/tasks/backgroundrb/hooks.rb
35
+ - lib/cap_recipes/tasks/backgroundrb/manage.rb
30
36
  - lib/cap_recipes/tasks/backgroundrb.rb
37
+ - lib/cap_recipes/tasks/juggernaut
38
+ - lib/cap_recipes/tasks/juggernaut/hooks.rb
39
+ - lib/cap_recipes/tasks/juggernaut/manage.rb
31
40
  - lib/cap_recipes/tasks/juggernaut.rb
41
+ - lib/cap_recipes/tasks/memcache
42
+ - lib/cap_recipes/tasks/memcache/hooks.rb
43
+ - lib/cap_recipes/tasks/memcache/install.rb
44
+ - lib/cap_recipes/tasks/memcache/manage.rb
32
45
  - lib/cap_recipes/tasks/memcache.rb
46
+ - lib/cap_recipes/tasks/passenger
47
+ - lib/cap_recipes/tasks/passenger/install.rb
48
+ - lib/cap_recipes/tasks/passenger/manage.rb
33
49
  - lib/cap_recipes/tasks/passenger.rb
50
+ - lib/cap_recipes/tasks/rails
51
+ - lib/cap_recipes/tasks/rails/hooks.rb
52
+ - lib/cap_recipes/tasks/rails/tasks.rb
53
+ - lib/cap_recipes/tasks/rails.rb
34
54
  - lib/cap_recipes/tasks/with_scope.rb
35
55
  - lib/cap_recipes.rb
36
56
  - test/cap_recipes_test.rb