hubertlepicki-cap-recipes 0.2.8
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +153 -0
- data/Rakefile +48 -0
- data/lib/cap_recipes.rb +1 -0
- data/lib/cap_recipes/tasks/apache.rb +38 -0
- data/lib/cap_recipes/tasks/backgroundrb.rb +75 -0
- data/lib/cap_recipes/tasks/juggernaut.rb +50 -0
- data/lib/cap_recipes/tasks/memcache.rb +43 -0
- data/lib/cap_recipes/tasks/passenger.rb +152 -0
- data/lib/cap_recipes/tasks/thinking_sphinx.rb +64 -0
- data/lib/cap_recipes/tasks/with_scope.rb +22 -0
- data/spec/cap-recipes-spec.rb +5 -0
- metadata +63 -0
data/README.textile
ADDED
@@ -0,0 +1,153 @@
|
|
1
|
+
h1. cap-recipes
|
2
|
+
|
3
|
+
h2. INSTALLATION
|
4
|
+
|
5
|
+
* gem sources -a http://gems.github.com/
|
6
|
+
* sudo gem install nesquena-cap-recipes
|
7
|
+
|
8
|
+
h2. DESCRIPTION
|
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!
|
11
|
+
|
12
|
+
Currently included:
|
13
|
+
|
14
|
+
* Phusion Passenger (Setup and Deployment)
|
15
|
+
* Apache Server
|
16
|
+
* Memcache Process
|
17
|
+
* Juggernaut Daemon
|
18
|
+
* Backgroundrb Server
|
19
|
+
|
20
|
+
h2. SYNOPSIS
|
21
|
+
|
22
|
+
To include any of these into your deploy.rb configuration file for Capistrano:
|
23
|
+
|
24
|
+
require 'cap_recipes/tasks/passenger'
|
25
|
+
require 'cap_recipes/tasks/apache'
|
26
|
+
require 'cap_recipes/tasks/backgroundrb'
|
27
|
+
require 'cap_recipes/tasks/juggernaut'
|
28
|
+
require 'cap_recipes/tasks/memcache'
|
29
|
+
|
30
|
+
Or to include and activate all of them:
|
31
|
+
|
32
|
+
require 'cap_recipes'
|
33
|
+
|
34
|
+
h2. USAGE
|
35
|
+
|
36
|
+
h3. Passenger
|
37
|
+
|
38
|
+
h4. Configuration
|
39
|
+
|
40
|
+
* base_ruby_path - the base path to the ruby installation [default: "/usr"]
|
41
|
+
|
42
|
+
The following files and folders are expected to exist:
|
43
|
+
|
44
|
+
* "#{base_ruby_path}/lib/ruby"
|
45
|
+
* "#{base_ruby_path}/bin/ruby"
|
46
|
+
* "#{base_ruby_path}/bin/gem"
|
47
|
+
|
48
|
+
h4. Tasks
|
49
|
+
|
50
|
+
deploy
|
51
|
+
:start
|
52
|
+
:stop
|
53
|
+
:restart
|
54
|
+
:with_migrations
|
55
|
+
:copy_config
|
56
|
+
:tail
|
57
|
+
install
|
58
|
+
:passenger
|
59
|
+
:gems
|
60
|
+
sweep
|
61
|
+
:cache
|
62
|
+
:log
|
63
|
+
:gems
|
64
|
+
|
65
|
+
h3. Apache
|
66
|
+
|
67
|
+
h4. Configuration
|
68
|
+
|
69
|
+
* apache_init_path - the path to the init.d apache file [default: '/etc/init.d/apache2']
|
70
|
+
|
71
|
+
h4. Tasks
|
72
|
+
|
73
|
+
apache
|
74
|
+
:stop
|
75
|
+
:start
|
76
|
+
:restart
|
77
|
+
:install
|
78
|
+
|
79
|
+
h3. Backgroundrb
|
80
|
+
|
81
|
+
h4. Configuration
|
82
|
+
|
83
|
+
* backgroundrb_log - the path to the backgroundrb log file
|
84
|
+
* backgroundrb_host - the background host machine ip [default: 'localhost']
|
85
|
+
* backgroundrb_env - the rails environment [default: 'production']
|
86
|
+
|
87
|
+
h4. Tasks
|
88
|
+
|
89
|
+
tasks:
|
90
|
+
backgroundrb
|
91
|
+
:stop
|
92
|
+
:start
|
93
|
+
:restart
|
94
|
+
:copy_config
|
95
|
+
:tail
|
96
|
+
|
97
|
+
h3. Juggernaut
|
98
|
+
|
99
|
+
h4. Configuration
|
100
|
+
|
101
|
+
* juggernaut_config - path to juggernaut config file [default: "#{current_path}/config/juggernaut.yml"]
|
102
|
+
* juggernaut_pid - path to juggernaut pid file [default: "#{current_path}/tmp/pids/juggernaut.pid"]
|
103
|
+
* juggernaut_log - path to juggernaut log file [default: "#{current_path}/log/juggernaut.log"]
|
104
|
+
|
105
|
+
h4. Tasks
|
106
|
+
|
107
|
+
tasks:
|
108
|
+
juggernaut
|
109
|
+
:start
|
110
|
+
:stop
|
111
|
+
:restart
|
112
|
+
:copy_config
|
113
|
+
:tail
|
114
|
+
|
115
|
+
h3. Memcache
|
116
|
+
|
117
|
+
h4. Configuration
|
118
|
+
|
119
|
+
* memcache_init_path - path to memcache config file [default: "/etc/init.d/memcache"]
|
120
|
+
|
121
|
+
h4. Tasks
|
122
|
+
|
123
|
+
tasks:
|
124
|
+
memcache
|
125
|
+
:start
|
126
|
+
:stop
|
127
|
+
:restart
|
128
|
+
:install
|
129
|
+
|
130
|
+
h2. LICENSE:
|
131
|
+
|
132
|
+
(The MIT License)
|
133
|
+
|
134
|
+
Copyright (c) 2008 Nathan Esquenazi
|
135
|
+
|
136
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
137
|
+
a copy of this software and associated documentation files (the
|
138
|
+
'Software'), to deal in the Software without restriction, including
|
139
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
140
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
141
|
+
permit persons to whom the Software is furnished to do so, subject to
|
142
|
+
the following conditions:
|
143
|
+
|
144
|
+
The above copyright notice and this permission notice shall be
|
145
|
+
included in all copies or substantial portions of the Software.
|
146
|
+
|
147
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
148
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
149
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
150
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
151
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
152
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
153
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rubygems/specification'
|
3
|
+
require 'rake'
|
4
|
+
require 'rake/gempackagetask'
|
5
|
+
require 'spec/rake/spectask'
|
6
|
+
|
7
|
+
GEM = "cap-recipes"
|
8
|
+
GEM_VERSION = "0.2.8"
|
9
|
+
SUMMARY = "Collection of capistrano recipes for apache, passenger, memcache, juggernaut and backgroundrb"
|
10
|
+
AUTHOR = "Nathan Esquenazi"
|
11
|
+
EMAIL = "nesquena@gmail.com"
|
12
|
+
HOMEPAGE = "http://caprecipes.rubyforge.org"
|
13
|
+
|
14
|
+
spec = Gem::Specification.new do |s|
|
15
|
+
s.name = GEM
|
16
|
+
s.version = GEM_VERSION
|
17
|
+
s.platform = Gem::Platform::RUBY
|
18
|
+
s.summary = SUMMARY
|
19
|
+
s.require_paths = ['lib']
|
20
|
+
s.files = FileList['[A-Z]*', 'lib/**/*.rb', 'spec/**/*'].to_a
|
21
|
+
|
22
|
+
s.author = AUTHOR
|
23
|
+
s.email = EMAIL
|
24
|
+
s.homepage = HOMEPAGE
|
25
|
+
|
26
|
+
s.rubyforge_project = GEM # GitHub bug, gem isn't being build when this miss
|
27
|
+
end
|
28
|
+
|
29
|
+
Spec::Rake::SpecTask.new do |t|
|
30
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
31
|
+
t.spec_opts = %w(-fs --color)
|
32
|
+
end
|
33
|
+
|
34
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
35
|
+
pkg.gem_spec = spec
|
36
|
+
end
|
37
|
+
|
38
|
+
desc "Install the gem locally"
|
39
|
+
task :install => [:package] do
|
40
|
+
sh %{sudo gem install pkg/#{GEM}-#{GEM_VERSION}}
|
41
|
+
end
|
42
|
+
|
43
|
+
desc "Create a gemspec file"
|
44
|
+
task :make_spec do
|
45
|
+
File.open("#{GEM}.gemspec", "w") do |file|
|
46
|
+
file.puts spec.to_ruby
|
47
|
+
end
|
48
|
+
end
|
data/lib/cap_recipes.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Dir[File.join(File.dirname(__FILE__), 'cap_recipes/**/*.rb')].sort.each { |lib| require lib }
|
@@ -0,0 +1,38 @@
|
|
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
|
+
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
|
@@ -0,0 +1,75 @@
|
|
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
|
+
sudo "chown -R #{user}:#{user} #{current_path}"
|
64
|
+
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
|
@@ -0,0 +1,50 @@
|
|
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
|
@@ -0,0 +1,43 @@
|
|
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
|
+
sudo "#{memcache_init_path} stop"
|
14
|
+
end
|
15
|
+
|
16
|
+
desc "Starts the memcache server"
|
17
|
+
task :start, :roles => :app do
|
18
|
+
puts "Starting the memcache server"
|
19
|
+
sudo "#{memcache_init_path} 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
|
+
memcache.start
|
27
|
+
end
|
28
|
+
|
29
|
+
# ===============================================================
|
30
|
+
# INSTALLATION
|
31
|
+
# ===============================================================
|
32
|
+
|
33
|
+
desc 'Installs memcache and the ruby gem'
|
34
|
+
task :install, :roles => :app do
|
35
|
+
puts 'Installing memcache'
|
36
|
+
sudo 'apt-get install memcached'
|
37
|
+
sudo "#{base_ruby_path}/bin/gem install memcache-client --no-ri --no-rdoc"
|
38
|
+
memcache.start
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
after "deploy:update_code", "memcache:restart" # clear cache after updating code
|
43
|
+
end
|
@@ -0,0 +1,152 @@
|
|
1
|
+
require 'cap_recipes/tasks/with_scope.rb'
|
2
|
+
|
3
|
+
Capistrano::Configuration.instance(true).load do
|
4
|
+
set :base_ruby_path, '/usr'
|
5
|
+
|
6
|
+
# ===============================================================
|
7
|
+
# DEPLOYMENT SCRIPTS
|
8
|
+
# ===============================================================
|
9
|
+
|
10
|
+
namespace :deploy do
|
11
|
+
|
12
|
+
desc "Default deploy action"
|
13
|
+
task :default, :roles => :web do
|
14
|
+
with_role(:web) do
|
15
|
+
update
|
16
|
+
restart
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# ===============================================================
|
21
|
+
# SERVER MANAGEMENT
|
22
|
+
# ===============================================================
|
23
|
+
|
24
|
+
desc "Stops the phusion passenger server"
|
25
|
+
task :stop, :roles => :web do
|
26
|
+
puts "Stopping rails web server"
|
27
|
+
apache.stop
|
28
|
+
end
|
29
|
+
|
30
|
+
desc "Starts the phusion passenger server"
|
31
|
+
task :start, :roles => :web do
|
32
|
+
puts "Starting rails web server"
|
33
|
+
apache.start
|
34
|
+
end
|
35
|
+
|
36
|
+
desc "Restarts the phusion passenger server"
|
37
|
+
task :restart, :roles => :web do
|
38
|
+
puts "Restarting the application"
|
39
|
+
run "touch #{current_path}/tmp/restart.txt"
|
40
|
+
end
|
41
|
+
|
42
|
+
desc "Update code on server, apply migrations, and restart passenger server"
|
43
|
+
task :with_migrations, :roles => :web do
|
44
|
+
with_role(:web) do
|
45
|
+
deploy.update
|
46
|
+
deploy.migrate
|
47
|
+
deploy.restart
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# ===============================================================
|
52
|
+
# UTILITY TASKS
|
53
|
+
# ===============================================================
|
54
|
+
|
55
|
+
desc "Copies the shared/config/database yaml to release/config/"
|
56
|
+
task :copy_config, :roles => :web do
|
57
|
+
puts "Copying database configuration to release path"
|
58
|
+
sudo "ln -s #{shared_path}/config/database.yml #{release_path}/config/database.yml"
|
59
|
+
end
|
60
|
+
|
61
|
+
desc "Repair permissions to allow user to perform all actions"
|
62
|
+
task :repair_permissions, :roles => :web do
|
63
|
+
puts "Applying correct permissions to allow for proper command execution"
|
64
|
+
sudo "chmod -R 744 #{current_path}/log #{current_path}/tmp"
|
65
|
+
sudo "chown -R #{user}:#{user} #{current_path}"
|
66
|
+
sudo "chown -R #{user}:#{user} #{current_path}/tmp"
|
67
|
+
end
|
68
|
+
|
69
|
+
desc "Displays the production log from the server locally"
|
70
|
+
task :tail, :roles => :web do
|
71
|
+
stream "tail -f #{shared_path}/log/production.log"
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
# ===============================================================
|
77
|
+
# INSTALLATION
|
78
|
+
# ===============================================================
|
79
|
+
|
80
|
+
namespace :install do
|
81
|
+
|
82
|
+
desc "Updates all installed ruby gems"
|
83
|
+
task :gems, :roles => :web do
|
84
|
+
sudo "gem update"
|
85
|
+
end
|
86
|
+
|
87
|
+
desc "Installs Phusion Passenger"
|
88
|
+
task :passenger, :roles => :web do
|
89
|
+
puts 'Installing passenger module'
|
90
|
+
install.passenger_apache_module
|
91
|
+
install.config_passenger
|
92
|
+
end
|
93
|
+
|
94
|
+
desc "Setup Passenger Module"
|
95
|
+
task :passenger_apache_module, :roles => :web do
|
96
|
+
sudo "#{base_ruby_path}/bin/gem install passenger --no-ri --no-rdoc"
|
97
|
+
input = ''
|
98
|
+
run "sudo #{base_ruby_path}/bin/passenger-install-apache2-module" do |ch, stream, out|
|
99
|
+
next if out.chomp == input.chomp || out.chomp == ''
|
100
|
+
print out
|
101
|
+
ch.send_data(input = $stdin.gets) if out =~ /(Enter|ENTER)/
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
desc "Configure Passenger"
|
106
|
+
task :config_passenger, :roles => :web do
|
107
|
+
version = 'ERROR' # default
|
108
|
+
|
109
|
+
# passenger (2.X.X, 1.X.X)
|
110
|
+
run("gem list | grep passenger") do |ch, stream, data|
|
111
|
+
version = data.sub(/passenger \(([^,]+).*?\)/,"\\1").strip
|
112
|
+
end
|
113
|
+
|
114
|
+
puts " passenger version #{version} configured"
|
115
|
+
|
116
|
+
passenger_config =<<-EOF
|
117
|
+
LoadModule passenger_module #{base_ruby_path}/lib/ruby/gems/1.8/gems/passenger-#{version}/ext/apache2/mod_passenger.so
|
118
|
+
PassengerRoot #{base_ruby_path}/lib/ruby/gems/1.8/gems/passenger-#{version}
|
119
|
+
PassengerRuby #{base_ruby_path}/bin/ruby
|
120
|
+
EOF
|
121
|
+
|
122
|
+
put passenger_config, "/tmp/passenger"
|
123
|
+
sudo "mv /tmp/passenger /etc/apache2/conf.d/passenger"
|
124
|
+
apache.restart
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
128
|
+
|
129
|
+
# ===============================================================
|
130
|
+
# MAINTENANCE TASKS
|
131
|
+
# ===============================================================
|
132
|
+
namespace :sweep do
|
133
|
+
desc "Clear file-based fragment and action caching"
|
134
|
+
task :log, :roles => :web do
|
135
|
+
puts "Sweeping all the log files"
|
136
|
+
run "cd #{current_path} && #{sudo} rake log:clear RAILS_ENV=production"
|
137
|
+
end
|
138
|
+
|
139
|
+
desc "Clear file-based fragment and action caching"
|
140
|
+
task :cache, :roles => :web do
|
141
|
+
puts "Sweeping the fragment and action cache stores"
|
142
|
+
run "cd #{release_path} && #{sudo} rake tmp:cache:clear RAILS_ENV=production"
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
# ===============================================================
|
147
|
+
# TASK CALLBACKS
|
148
|
+
# ===============================================================
|
149
|
+
after "deploy:update_code", "deploy:copy_config" # copy database.yml file to release path
|
150
|
+
after "deploy:update_code", "sweep:cache" # clear cache after updating code
|
151
|
+
after "deploy:restart" , "deploy:repair_permissions" # fix the permissions to work properly
|
152
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
Capistrano::Configuration.instance(true).load do
|
2
|
+
namespace :thinking_sphinx do
|
3
|
+
|
4
|
+
# ===============================================================
|
5
|
+
# PROCESS MANAGEMENT
|
6
|
+
# ===============================================================
|
7
|
+
|
8
|
+
desc "Starts the thinking sphinx searchd server"
|
9
|
+
task :start, :roles => :app do
|
10
|
+
puts "Starting thinking sphinx searchd server"
|
11
|
+
rake = fetch(:rake, "rake")
|
12
|
+
rails_env = fetch(:rails_env, "production")
|
13
|
+
|
14
|
+
run "cd #{current_path}; #{rake} RAILS_ENV=#{rails_env} thinking_sphinx:configure; #{rake} RAILS_ENV=#{rails_env} ts:start"
|
15
|
+
end
|
16
|
+
|
17
|
+
desc "Stops the thinking sphinx searchd server"
|
18
|
+
task :stop, :roles => :app do
|
19
|
+
puts "Stopping thinking sphinx searchd server"
|
20
|
+
rake = fetch(:rake, "rake")
|
21
|
+
rails_env = fetch(:rails_env, "production")
|
22
|
+
|
23
|
+
run "cd #{current_path}; #{rake} RAILS_ENV=#{rails_env} thinking_sphinx:configure; #{rake} RAILS_ENV=#{rails_env} ts:stop"
|
24
|
+
end
|
25
|
+
|
26
|
+
desc "Restarts the thinking sphinx searchd server"
|
27
|
+
task :restart, :roles => :app do
|
28
|
+
thinking_sphinx.stop
|
29
|
+
thinking_sphinx.index
|
30
|
+
thinking_sphinx.start
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
# ===============================================================
|
35
|
+
# FILE MANAGEMENT
|
36
|
+
# ===============================================================
|
37
|
+
|
38
|
+
desc "Copies the shared/config/sphinx yaml to release/config/"
|
39
|
+
task :copy_config, :roles => :app do
|
40
|
+
run "ln -s #{shared_path}/config/sphinx.yml #{release_path}/config/sphinx.yml"
|
41
|
+
end
|
42
|
+
|
43
|
+
desc "Displays the thinking sphinx log from the server"
|
44
|
+
task :tail, :roles => :app do
|
45
|
+
stream "tail -f #{shared_path}/log/searchd.log"
|
46
|
+
end
|
47
|
+
|
48
|
+
desc "Runs Thinking Sphinx indexer"
|
49
|
+
task :index, :roles => :app do
|
50
|
+
rake = fetch(:rake, "rake")
|
51
|
+
rails_env = fetch(:rails_env, "production")
|
52
|
+
puts "Updating search index"
|
53
|
+
|
54
|
+
run "cd #{current_path}; #{rake} RAILS_ENV=#{rails_env} ts:index"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# ===============================================================
|
59
|
+
# TASK CALLBACKS
|
60
|
+
# ===============================================================
|
61
|
+
|
62
|
+
after "deploy:update_code", "thinking_sphinx:copy_config" # copy thinking_sphinx.yml on update code
|
63
|
+
after "deploy:restart" , "thinking_sphinx:restart" # restart thinking_sphinx on app restart
|
64
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# role = :app
|
2
|
+
def with_role(role, &block)
|
3
|
+
original, ENV['HOSTS'] = ENV['HOSTS'], find_servers(:roles => role).map{|d| d.host}.join(",")
|
4
|
+
begin
|
5
|
+
yield
|
6
|
+
ensure
|
7
|
+
ENV['HOSTS'] = original
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
# options = { :user => 'xxxxx', :password => 'xxxxx' }
|
12
|
+
def with_credentials(options={}, &block)
|
13
|
+
original_username, original_password = user, password
|
14
|
+
begin
|
15
|
+
set :user, options[:user] || original_username
|
16
|
+
set :password, options[:password] || original_password
|
17
|
+
yield
|
18
|
+
ensure
|
19
|
+
set :user, original_username
|
20
|
+
set :password, original_password
|
21
|
+
end
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hubertlepicki-cap-recipes
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.8
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nathan Esquenazi
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-01-27 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: nesquena@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- Rakefile
|
26
|
+
- README.textile
|
27
|
+
- lib/cap_recipes/tasks/apache.rb
|
28
|
+
- lib/cap_recipes/tasks/backgroundrb.rb
|
29
|
+
- lib/cap_recipes/tasks/juggernaut.rb
|
30
|
+
- lib/cap_recipes/tasks/memcache.rb
|
31
|
+
- lib/cap_recipes/tasks/passenger.rb
|
32
|
+
- lib/cap_recipes/tasks/thinking_sphinx.rb
|
33
|
+
- lib/cap_recipes/tasks/with_scope.rb
|
34
|
+
- lib/cap_recipes.rb
|
35
|
+
- spec/cap-recipes-spec.rb
|
36
|
+
has_rdoc: false
|
37
|
+
homepage: http://caprecipes.rubyforge.org
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options: []
|
40
|
+
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: "0"
|
48
|
+
version:
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: "0"
|
54
|
+
version:
|
55
|
+
requirements: []
|
56
|
+
|
57
|
+
rubyforge_project: cap-recipes
|
58
|
+
rubygems_version: 1.2.0
|
59
|
+
signing_key:
|
60
|
+
specification_version: 2
|
61
|
+
summary: Collection of capistrano recipes for apache, passenger, memcache, juggernaut and backgroundrb
|
62
|
+
test_files: []
|
63
|
+
|