cap-recipes 0.3.18
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/.gitignore +3 -0
- data/LICENSE +20 -0
- data/README.textile +357 -0
- data/Rakefile +45 -0
- data/VERSION.yml +4 -0
- data/cap-recipes.gemspec +87 -0
- data/examples/advanced/deploy.rb +39 -0
- data/examples/advanced/deploy/experimental.rb +14 -0
- data/examples/advanced/deploy/production.rb +20 -0
- data/examples/simple/deploy.rb +36 -0
- data/lib/cap_recipes.rb +1 -0
- data/lib/cap_recipes/tasks/apache.rb +1 -0
- data/lib/cap_recipes/tasks/apache/install.rb +12 -0
- data/lib/cap_recipes/tasks/apache/manage.rb +26 -0
- data/lib/cap_recipes/tasks/aptitude.rb +1 -0
- data/lib/cap_recipes/tasks/aptitude/manage.rb +34 -0
- data/lib/cap_recipes/tasks/backgroundrb.rb +1 -0
- data/lib/cap_recipes/tasks/backgroundrb/hooks.rb +5 -0
- data/lib/cap_recipes/tasks/backgroundrb/manage.rb +64 -0
- data/lib/cap_recipes/tasks/delayed_job.rb +1 -0
- data/lib/cap_recipes/tasks/delayed_job/hooks.rb +5 -0
- data/lib/cap_recipes/tasks/delayed_job/manage.rb +32 -0
- data/lib/cap_recipes/tasks/juggernaut.rb +1 -0
- data/lib/cap_recipes/tasks/juggernaut/hooks.rb +4 -0
- data/lib/cap_recipes/tasks/juggernaut/manage.rb +54 -0
- data/lib/cap_recipes/tasks/memcache.rb +1 -0
- data/lib/cap_recipes/tasks/memcache/hooks.rb +5 -0
- data/lib/cap_recipes/tasks/memcache/install.rb +13 -0
- data/lib/cap_recipes/tasks/memcache/manage.rb +35 -0
- data/lib/cap_recipes/tasks/passenger.rb +1 -0
- data/lib/cap_recipes/tasks/passenger/install.rb +62 -0
- data/lib/cap_recipes/tasks/passenger/manage.rb +24 -0
- data/lib/cap_recipes/tasks/rails.rb +1 -0
- data/lib/cap_recipes/tasks/rails/hooks.rb +8 -0
- data/lib/cap_recipes/tasks/rails/manage.rb +53 -0
- data/lib/cap_recipes/tasks/rubygems.rb +1 -0
- data/lib/cap_recipes/tasks/rubygems/manage.rb +43 -0
- data/lib/cap_recipes/tasks/utilities.rb +114 -0
- data/lib/cap_recipes/tasks/whenever.rb +1 -0
- data/lib/cap_recipes/tasks/whenever/hooks.rb +5 -0
- data/lib/cap_recipes/tasks/whenever/manage.rb +10 -0
- data/spec/cap/all/Capfile +2 -0
- data/spec/cap/helper.rb +2 -0
- data/spec/cap_recipes_spec.rb +13 -0
- data/spec/spec_helper.rb +16 -0
- metadata +106 -0
@@ -0,0 +1,39 @@
|
|
1
|
+
# =============================================================================
|
2
|
+
# GENERAL SETTINGS
|
3
|
+
# =============================================================================
|
4
|
+
|
5
|
+
set :application, "demo"
|
6
|
+
set :deploy_to, "/var/apps/#{application}"
|
7
|
+
set :deploy_via, :remote_cache
|
8
|
+
set :scm, :git
|
9
|
+
set :repository, "deploy@dev.demo.com:/home/demo.git"
|
10
|
+
set :git_enable_submodules, 1
|
11
|
+
set :keep_releases, 3
|
12
|
+
|
13
|
+
# =============================================================================
|
14
|
+
# STAGE SETTINGS
|
15
|
+
# =============================================================================
|
16
|
+
|
17
|
+
# set :default_stage, "experimental"
|
18
|
+
set :stages, %w(production experimental)
|
19
|
+
set :default_stage, "experimental"
|
20
|
+
require 'capistrano/ext/multistage'
|
21
|
+
|
22
|
+
# =============================================================================
|
23
|
+
# RECIPE INCLUDES
|
24
|
+
# =============================================================================
|
25
|
+
|
26
|
+
require 'rubygems'
|
27
|
+
require 'cap_recipes/tasks/whenever'
|
28
|
+
require 'cap_recipes/tasks/apache'
|
29
|
+
require 'cap_recipes/tasks/passenger'
|
30
|
+
require 'cap_recipes/tasks/memcache'
|
31
|
+
require 'cap_recipes/tasks/juggernaut'
|
32
|
+
require 'cap_recipes/tasks/delayed_job'
|
33
|
+
require 'cap_recipes/tasks/rails'
|
34
|
+
|
35
|
+
ssh_options[:paranoid] = false
|
36
|
+
default_run_options[:pty] = true
|
37
|
+
|
38
|
+
# PASSENGER
|
39
|
+
set :base_ruby_path, '/opt/ruby-enterprise' # not /usr
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# Domain
|
2
|
+
role :web, "stage.app.com"
|
3
|
+
role :app, "stage.app.com"
|
4
|
+
role :db, "stage.app.com", :primary => true
|
5
|
+
|
6
|
+
# GENERAL
|
7
|
+
set :user, "deploy"
|
8
|
+
set :runner, "deploy"
|
9
|
+
set :password, "demo567"
|
10
|
+
set :use_sudo, true
|
11
|
+
ssh_options[:keys] = [File.join(ENV["HOME"], ".ssh", "demo")]
|
12
|
+
|
13
|
+
# Branch
|
14
|
+
set :branch, 'develop'
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# Domain
|
2
|
+
role :web, "demo.app.com"
|
3
|
+
role :app, "demo.app.com"
|
4
|
+
role :db, "demo.app.com", :primary => true
|
5
|
+
role :juggernaut, "juggernaut.app.com", :no_release => true
|
6
|
+
role :delayed_job, "dj.app.com", :no_release => true
|
7
|
+
role :memcache, "memcache.app.com", :no_release => true
|
8
|
+
|
9
|
+
# GENERAL
|
10
|
+
set :user, "deploy"
|
11
|
+
set :runner, "deploy"
|
12
|
+
set :password, "demo567"
|
13
|
+
set :use_sudo, true
|
14
|
+
set :juggernaut_role, :juggernaut
|
15
|
+
set :delayed_job_role, :delayed_job
|
16
|
+
set :memcache_role, :memcache
|
17
|
+
ssh_options[:keys] = [File.join(ENV["HOME"], ".ssh", "demo")]
|
18
|
+
|
19
|
+
# Branch
|
20
|
+
set :branch, 'master'
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# =============================================================================
|
2
|
+
# GENERAL SETTINGS
|
3
|
+
# =============================================================================
|
4
|
+
|
5
|
+
role :web, "demo.app.com"
|
6
|
+
role :app, "demo.app.com"
|
7
|
+
role :db, "demo.app.com", :primary => true
|
8
|
+
|
9
|
+
set :application, "demo"
|
10
|
+
set :deploy_to, "/var/apps/#{application}"
|
11
|
+
set :deploy_via, :remote_cache
|
12
|
+
set :scm, :git
|
13
|
+
set :repository, "deploy@dev.demo.com:/home/demo.git"
|
14
|
+
set :git_enable_submodules, 1
|
15
|
+
set :keep_releases, 3
|
16
|
+
set :user, "deploy"
|
17
|
+
set :runner, "deploy"
|
18
|
+
set :password, "demo567"
|
19
|
+
set :use_sudo, true
|
20
|
+
set :branch, 'production'
|
21
|
+
|
22
|
+
# =============================================================================
|
23
|
+
# RECIPE INCLUDES
|
24
|
+
# =============================================================================
|
25
|
+
|
26
|
+
require 'rubygems'
|
27
|
+
require 'cap_recipes/tasks/whenever'
|
28
|
+
require 'cap_recipes/tasks/apache'
|
29
|
+
require 'cap_recipes/tasks/passenger'
|
30
|
+
require 'cap_recipes/tasks/memcache'
|
31
|
+
require 'cap_recipes/tasks/juggernaut'
|
32
|
+
require 'cap_recipes/tasks/delayed_job'
|
33
|
+
require 'cap_recipes/tasks/rails'
|
34
|
+
|
35
|
+
ssh_options[:paranoid] = false
|
36
|
+
default_run_options[:pty] = true
|
data/lib/cap_recipes.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Dir[File.join(File.dirname(__FILE__), 'cap_recipes/tasks/*.rb')].sort.each { |lib| require lib }
|
@@ -0,0 +1 @@
|
|
1
|
+
Dir[File.join(File.dirname(__FILE__), 'apache/*.rb')].sort.each { |lib| require lib }
|
@@ -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
|
@@ -0,0 +1 @@
|
|
1
|
+
Dir[File.join(File.dirname(__FILE__), 'aptitude/*.rb')].sort.each { |lib| require lib }
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'cap_recipes/tasks/utilities.rb'
|
2
|
+
|
3
|
+
Capistrano::Configuration.instance(true).load do
|
4
|
+
namespace :aptitude do
|
5
|
+
desc "Updates all installed packages on apt-get package system"
|
6
|
+
task :updates do
|
7
|
+
sudo "apt-get -qy update"
|
8
|
+
sudo "apt-get -qy upgrade"
|
9
|
+
sudo "apt-get -qy autoremove"
|
10
|
+
end
|
11
|
+
|
12
|
+
desc "Installs a specified apt-get package"
|
13
|
+
task :install do
|
14
|
+
puts "What is the name of the package(s) you wish to install?"
|
15
|
+
deb_pkg_name = $stdin.gets.chomp
|
16
|
+
raise "Please specify deb_pkg_name" if deb_pkg_name == ''
|
17
|
+
logger.info "Updating packages..."
|
18
|
+
sudo "aptitude update"
|
19
|
+
logger.info "Installing #{deb_pkg_name}..."
|
20
|
+
utilities.sudo_with_input "apt-get install #{deb_pkg_name}", /^Do you want to continue\?/
|
21
|
+
end
|
22
|
+
|
23
|
+
desc "Removes a specified apt-get package"
|
24
|
+
task :remove do
|
25
|
+
puts "What is the name of the package(s) you wish to install?"
|
26
|
+
deb_pkg_name = $stdin.gets.chomp
|
27
|
+
raise "Please specify deb_pkg_name" if deb_pkg_name == ''
|
28
|
+
logger.info "Updating packages..."
|
29
|
+
sudo "aptitude update"
|
30
|
+
logger.info "Removing #{deb_pkg_name}..."
|
31
|
+
utilities.sudo_with_input "apt-get remove --purge #{deb_pkg_name}", /^Do you want to continue\?/
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
Dir[File.join(File.dirname(__FILE__), 'backgroundrb/*.rb')].sort.each { |lib| require lib }
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
Capistrano::Configuration.instance(true).load do
|
4
|
+
set :backgroundrb_host, 'localhost'
|
5
|
+
set :backgroundrb_env , 'production'
|
6
|
+
set :base_ruby_path, '/usr'
|
7
|
+
|
8
|
+
namespace :backgroundrb do
|
9
|
+
# ===============================================================
|
10
|
+
# PROCESS MANAGEMENT
|
11
|
+
# ===============================================================
|
12
|
+
|
13
|
+
desc "Stops the backgroundrb worker processes"
|
14
|
+
task :stop, :roles => :app do
|
15
|
+
run "cd #{current_path} && #{sudo} #{base_ruby_path}/bin/ruby script/backgroundrb stop"
|
16
|
+
end
|
17
|
+
|
18
|
+
desc "Starts the backgroundrb worker processes"
|
19
|
+
task :start, :roles => :app do
|
20
|
+
run "cd #{current_path} && #{sudo} nohup #{base_ruby_path}/bin/ruby script/backgroundrb start"
|
21
|
+
end
|
22
|
+
|
23
|
+
desc "Restarts a running backgroundrb server."
|
24
|
+
task :restart, :roles => :app do
|
25
|
+
backgroundrb.stop
|
26
|
+
sleep(5) # sleep for 5 seconds to make sure the server has mopped up everything
|
27
|
+
backgroundrb.start
|
28
|
+
end
|
29
|
+
|
30
|
+
# ===============================================================
|
31
|
+
# PROCESS CONFIGURATION
|
32
|
+
# ===============================================================
|
33
|
+
|
34
|
+
desc "Creates configuration file for the backgroundrb server"
|
35
|
+
task :configure, :roles => :app do
|
36
|
+
config = { :backgroundrb => {:ip => backgroundrb_host, :port => backgroundrb_port, :environment => backgroundrb_env} }
|
37
|
+
backgroundrb_yml = config.to_yaml
|
38
|
+
|
39
|
+
run "if [ ! -d #{shared_path}/config ]; then mkdir #{shared_path}/config; fi"
|
40
|
+
put(backgroundrb_yml, "#{shared_path}/config/backgroundrb.yml", :mode => 0644)
|
41
|
+
end
|
42
|
+
|
43
|
+
# ===============================================================
|
44
|
+
# FILE MANAGEMENT
|
45
|
+
# ===============================================================
|
46
|
+
|
47
|
+
desc "Symlinks the shared/config/backgroundrb yaml to release/config/"
|
48
|
+
task :symlink_config, :roles => :app do
|
49
|
+
run "ln -s #{shared_path}/config/backgroundrb.yml #{release_path}/config/backgroundrb.yml"
|
50
|
+
end
|
51
|
+
|
52
|
+
desc "Displays the backgroundrb log from the server"
|
53
|
+
task :tail do
|
54
|
+
stream "tail -f #{shared_path}/log/backgroundrb_#{backgroundrb_port}.log"
|
55
|
+
end
|
56
|
+
|
57
|
+
desc "Repair permissions to allow user to perform all actions"
|
58
|
+
task :repair_permissions, :roles => :app do
|
59
|
+
puts "Applying correct permissions to allow for proper command execution"
|
60
|
+
try_sudo "chown -R #{user}:#{user} #{current_path}"
|
61
|
+
try_sudo "chown -R #{user}:#{user} #{current_path}/tmp"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
Dir[File.join(File.dirname(__FILE__), 'delayed_job/*.rb')].sort.each { |lib| require lib }
|
@@ -0,0 +1,32 @@
|
|
1
|
+
Capistrano::Configuration.instance(true).load do
|
2
|
+
set :delayed_script_path, "#{current_path}/script/delayed_job"
|
3
|
+
set :delayed_job_env, 'production'
|
4
|
+
set :delayed_job_role, :app
|
5
|
+
set :base_ruby_path, '/usr'
|
6
|
+
|
7
|
+
namespace :delayed_job do
|
8
|
+
desc "Start delayed_job process"
|
9
|
+
task :start, :roles => delayed_job_role do
|
10
|
+
utilities.with_role(delayed_job_role) do
|
11
|
+
try_sudo "#{base_ruby_path}/bin/ruby #{delayed_script_path} start #{delayed_job_env}"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
desc "Stop delayed_job process"
|
16
|
+
task :stop, :roles => delayed_job_role do
|
17
|
+
utilities.with_role(delayed_job_role) do
|
18
|
+
try_sudo "#{base_ruby_path}/bin/ruby #{delayed_script_path} stop #{delayed_job_env}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
desc "Restart delayed_job process"
|
23
|
+
task :restart, :roles => delayed_job_role do
|
24
|
+
utilities.with_role(delayed_job_role) do
|
25
|
+
delayed_job.stop
|
26
|
+
sleep(4)
|
27
|
+
try_sudo "killall -s TERM delayed_job; true"
|
28
|
+
delayed_job.start
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
Dir[File.join(File.dirname(__FILE__), 'juggernaut/*.rb')].sort.each { |lib| require lib }
|
@@ -0,0 +1,54 @@
|
|
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
|
+
set :juggernaut_role, :app
|
6
|
+
set :base_ruby_path, '/usr'
|
7
|
+
|
8
|
+
namespace :juggernaut do
|
9
|
+
|
10
|
+
# ===============================================================
|
11
|
+
# PROCESS MANAGEMENT
|
12
|
+
# ===============================================================
|
13
|
+
|
14
|
+
desc "Starts the juggernaut push server"
|
15
|
+
task :start, :roles => juggernaut_role do
|
16
|
+
utilities.with_role(juggernaut_role) do
|
17
|
+
puts "Starting juggernaut push server"
|
18
|
+
try_sudo "#{base_ruby_path}/bin/juggernaut -c #{juggernaut_config} -d --pid #{juggernaut_pid} --log #{juggernaut_log}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
desc "Stops the juggernaut push server"
|
23
|
+
task :stop, :roles => juggernaut_role do
|
24
|
+
utilities.with_role(juggernaut_role) do
|
25
|
+
puts "Stopping juggernaut push server"
|
26
|
+
try_sudo "#{base_ruby_path}/bin/juggernaut -c #{juggernaut_config} -k * --pid #{juggernaut_pid} --log #{juggernaut_log}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
desc "Restarts the juggernaut push server"
|
31
|
+
task :restart, :roles => juggernaut_role do
|
32
|
+
utilities.with_role(juggernaut_role) do
|
33
|
+
juggernaut.stop
|
34
|
+
juggernaut.start
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# ===============================================================
|
39
|
+
# FILE MANAGEMENT
|
40
|
+
# ===============================================================
|
41
|
+
|
42
|
+
desc "Symlinks the shared/config/juggernaut yaml to release/config/"
|
43
|
+
task :symlink_config, :roles => :app do
|
44
|
+
try_sudo "ln -s #{shared_path}/config/juggernaut.yml #{release_path}/config/juggernaut.yml"
|
45
|
+
end
|
46
|
+
|
47
|
+
desc "Displays the juggernaut log from the server"
|
48
|
+
task :tail, :roles => :app do
|
49
|
+
stream "tail -f #{shared_path}/log/juggernaut.log"
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
Dir[File.join(File.dirname(__FILE__), 'memcache/*.rb')].sort.each { |lib| require lib }
|
@@ -0,0 +1,13 @@
|
|
1
|
+
Capistrano::Configuration.instance(true).load do
|
2
|
+
namespace :memcache do
|
3
|
+
|
4
|
+
desc 'Installs memcache and the ruby gem'
|
5
|
+
task :install, :roles => :app do
|
6
|
+
puts 'Installing memcache'
|
7
|
+
try_sudo 'apt-get install memcached'
|
8
|
+
try_sudo "#{base_ruby_path}/bin/gem install memcache-client --no-ri --no-rdoc"
|
9
|
+
memcache.start
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
Capistrano::Configuration.instance(true).load do
|
2
|
+
|
3
|
+
set :memcache_init_path, "/etc/init.d/memcached"
|
4
|
+
set :memcache_role, :app
|
5
|
+
|
6
|
+
namespace :memcache do
|
7
|
+
|
8
|
+
desc "Stops the memcache server"
|
9
|
+
task :stop, :roles => memcache_role do
|
10
|
+
utilities.with_role(memcache_role) do
|
11
|
+
puts "Stopping the memcache server"
|
12
|
+
try_sudo "killall -s TERM memcached; true"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
desc "Starts the memcache server"
|
17
|
+
task :start, :roles => memcache_role do
|
18
|
+
utilities.with_role(memcache_role) do
|
19
|
+
puts "Starting the memcache server"
|
20
|
+
try_sudo "nohup /etc/init.d/memcached start"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
desc "Restarts the memcache server"
|
25
|
+
task :restart, :roles => memcache_role do
|
26
|
+
utilities.with_role(memcache_role) do
|
27
|
+
puts "Restarting the memcache server"
|
28
|
+
memcache.stop
|
29
|
+
sleep(3) # sleep for 3 seconds to make sure the server has mopped up everything
|
30
|
+
memcache.start
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|