nesquena-cap-recipes 0.3.16 → 0.3.17
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 +43 -8
- data/Rakefile +1 -1
- data/VERSION.yml +1 -1
- data/cap-recipes.gemspec +8 -4
- data/lib/cap_recipes/tasks/aptitude/manage.rb +34 -0
- data/lib/cap_recipes/tasks/aptitude.rb +1 -0
- data/lib/cap_recipes/tasks/delayed_job/manage.rb +3 -3
- data/lib/cap_recipes/tasks/juggernaut/manage.rb +3 -3
- data/lib/cap_recipes/tasks/memcache/manage.rb +3 -3
- data/lib/cap_recipes/tasks/passenger/install.rb +18 -18
- data/lib/cap_recipes/tasks/passenger/manage.rb +1 -1
- data/lib/cap_recipes/tasks/rails/hooks.rb +1 -1
- data/lib/cap_recipes/tasks/rails/manage.rb +7 -7
- data/lib/cap_recipes/tasks/rubygems/manage.rb +43 -0
- data/lib/cap_recipes/tasks/rubygems.rb +1 -0
- data/lib/cap_recipes/tasks/utilities.rb +113 -0
- data/lib/cap_recipes/tasks/whenever/manage.rb +1 -1
- metadata +8 -4
- data/lib/cap_recipes/tasks/with_scope.rb +0 -22
data/README.textile
CHANGED
@@ -1,19 +1,24 @@
|
|
1
1
|
h1. cap-recipes
|
2
2
|
|
3
|
-
A collection of useful capistrano recipes.
|
4
|
-
Best suited for ruby projects which deploy using Phusion Passenger.
|
3
|
+
A collection of useful capistrano recipes I have been using in production on a number of sites.
|
5
4
|
|
6
|
-
|
5
|
+
This gem is best suited for ruby (and rails) projects which deploy using Apache and Phusion Passenger.
|
6
|
+
Feel free to contribute to this collection and make it even better!
|
7
|
+
|
8
|
+
The overall vision for this project being to collect a number of classic, generic recipes which can
|
9
|
+
be used by the community.
|
7
10
|
|
8
11
|
Currently included:
|
9
12
|
|
10
13
|
* Apache Server
|
14
|
+
* Rubygems Package Management
|
11
15
|
* Phusion Passenger (Setup and Deployment)
|
12
16
|
* Memcache Process (Setup and Deployment)
|
13
17
|
* Juggernaut Daemon
|
14
18
|
* Backgroundrb Server
|
15
19
|
* DelayedJob Worker
|
16
20
|
* Whenever Cron Scheduling
|
21
|
+
* Aptitude Package Management
|
17
22
|
|
18
23
|
h2. INSTALLATION
|
19
24
|
|
@@ -23,15 +28,16 @@ Include into your deploy.rb configuration file for Capistrano:
|
|
23
28
|
|
24
29
|
<pre>
|
25
30
|
<code>
|
26
|
-
# use the complete deployment process
|
31
|
+
# use the complete deployment process (NOT RECOMMENDED)
|
27
32
|
require 'cap_recipes'
|
28
33
|
|
29
|
-
#
|
30
|
-
#
|
34
|
+
# RECOMMENDED
|
35
|
+
# require necessary recipes according to your needs
|
31
36
|
# (use hooks which tie all the recipes into the deployment process,
|
32
37
|
# tasks for managing and tasks for installing):
|
33
|
-
# substitute memcache with: passenger, rails, apache, backgroundrb, delayed_job, juggernaut, whenever
|
34
38
|
require 'cap_recipes/tasks/memcache'
|
39
|
+
require 'cap_recipes/tasks/passenger'
|
40
|
+
# or rails, apache, rubygems, delayed_job, juggernaut, backgroundrb, aptitude, whenever
|
35
41
|
|
36
42
|
# OR
|
37
43
|
# only use managing tasks:
|
@@ -66,6 +72,24 @@ h5. install.rb
|
|
66
72
|
|
67
73
|
apache
|
68
74
|
:install
|
75
|
+
|
76
|
+
h3. Rubygems
|
77
|
+
|
78
|
+
h4. Configuration
|
79
|
+
|
80
|
+
* rubygem_paths - a path or array of paths to your gem binaries [default '/usr/bin/gem' ]
|
81
|
+
|
82
|
+
h4. Tasks
|
83
|
+
|
84
|
+
h5. manage.rb
|
85
|
+
|
86
|
+
rubygems
|
87
|
+
:full_update
|
88
|
+
:upgrade
|
89
|
+
:update
|
90
|
+
:cleanup
|
91
|
+
:install
|
92
|
+
:uninstall
|
69
93
|
|
70
94
|
h3. Passenger
|
71
95
|
|
@@ -73,7 +97,7 @@ These recipes manage the passenger module for apache
|
|
73
97
|
|
74
98
|
h4. Configuration
|
75
99
|
|
76
|
-
* base_ruby_path - the base path to the ruby installation [default:
|
100
|
+
* base_ruby_path - the base path to the ruby installation [default: '/usr']
|
77
101
|
* local_ping_path - the localhost path to ping to start passenger [default: "http://localhost"]
|
78
102
|
|
79
103
|
The following files and folders are expected to exist:
|
@@ -96,6 +120,17 @@ h5. install.rb
|
|
96
120
|
passenger
|
97
121
|
:install
|
98
122
|
|
123
|
+
h3. Aptitude
|
124
|
+
|
125
|
+
h4. Tasks
|
126
|
+
|
127
|
+
h5. manage.rb
|
128
|
+
|
129
|
+
aptitude
|
130
|
+
:install
|
131
|
+
:remove
|
132
|
+
:updates
|
133
|
+
|
99
134
|
h3. Rails
|
100
135
|
|
101
136
|
These recipes support rails-specific functionality
|
data/Rakefile
CHANGED
@@ -10,7 +10,7 @@ begin
|
|
10
10
|
s.summary = %Q{Battle-tested capistrano recipes for passenger, delayed_job, and more}
|
11
11
|
s.email = "nesquena@gmail.com"
|
12
12
|
s.homepage = "http://github.com/nesquena/cap-recipes"
|
13
|
-
s.description = "Battle-tested capistrano recipes for passenger, apache, delayed_job, juggernaut, backgroundrb, rails and more"
|
13
|
+
s.description = "Battle-tested capistrano recipes for debian, passenger, apache, delayed_job, juggernaut, rubygems, backgroundrb, rails and more"
|
14
14
|
s.authors = ["Nathan Esquenazi"]
|
15
15
|
end
|
16
16
|
rescue LoadError
|
data/VERSION.yml
CHANGED
data/cap-recipes.gemspec
CHANGED
@@ -2,12 +2,12 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{cap-recipes}
|
5
|
-
s.version = "0.3.
|
5
|
+
s.version = "0.3.17"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Nathan Esquenazi"]
|
9
|
-
s.date = %q{2009-06-
|
10
|
-
s.description = %q{Battle-tested capistrano recipes for passenger, apache, delayed_job, juggernaut, backgroundrb, rails and more}
|
9
|
+
s.date = %q{2009-06-07}
|
10
|
+
s.description = %q{Battle-tested capistrano recipes for debian, passenger, apache, delayed_job, juggernaut, rubygems, backgroundrb, rails and more}
|
11
11
|
s.email = %q{nesquena@gmail.com}
|
12
12
|
s.extra_rdoc_files = [
|
13
13
|
"LICENSE",
|
@@ -24,6 +24,8 @@ Gem::Specification.new do |s|
|
|
24
24
|
"lib/cap_recipes/tasks/apache.rb",
|
25
25
|
"lib/cap_recipes/tasks/apache/install.rb",
|
26
26
|
"lib/cap_recipes/tasks/apache/manage.rb",
|
27
|
+
"lib/cap_recipes/tasks/aptitude.rb",
|
28
|
+
"lib/cap_recipes/tasks/aptitude/manage.rb",
|
27
29
|
"lib/cap_recipes/tasks/backgroundrb.rb",
|
28
30
|
"lib/cap_recipes/tasks/backgroundrb/hooks.rb",
|
29
31
|
"lib/cap_recipes/tasks/backgroundrb/manage.rb",
|
@@ -43,10 +45,12 @@ Gem::Specification.new do |s|
|
|
43
45
|
"lib/cap_recipes/tasks/rails.rb",
|
44
46
|
"lib/cap_recipes/tasks/rails/hooks.rb",
|
45
47
|
"lib/cap_recipes/tasks/rails/manage.rb",
|
48
|
+
"lib/cap_recipes/tasks/rubygems.rb",
|
49
|
+
"lib/cap_recipes/tasks/rubygems/manage.rb",
|
50
|
+
"lib/cap_recipes/tasks/utilities.rb",
|
46
51
|
"lib/cap_recipes/tasks/whenever.rb",
|
47
52
|
"lib/cap_recipes/tasks/whenever/hooks.rb",
|
48
53
|
"lib/cap_recipes/tasks/whenever/manage.rb",
|
49
|
-
"lib/cap_recipes/tasks/with_scope.rb",
|
50
54
|
"spec/cap/all/Capfile",
|
51
55
|
"spec/cap/helper.rb",
|
52
56
|
"spec/cap_recipes_spec.rb",
|
@@ -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__), 'aptitude/*.rb')].sort.each { |lib| require lib }
|
@@ -7,21 +7,21 @@ Capistrano::Configuration.instance(true).load do
|
|
7
7
|
namespace :delayed_job do
|
8
8
|
desc "Start delayed_job process"
|
9
9
|
task :start, :roles => delayed_job_role do
|
10
|
-
with_role(delayed_job_role) do
|
10
|
+
utilities.with_role(delayed_job_role) do
|
11
11
|
try_sudo "#{base_ruby_path}/bin/ruby #{delayed_script_path} start #{delayed_job_env}"
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
15
|
desc "Stop delayed_job process"
|
16
16
|
task :stop, :roles => delayed_job_role do
|
17
|
-
with_role(delayed_job_role) do
|
17
|
+
utilities.with_role(delayed_job_role) do
|
18
18
|
try_sudo "#{base_ruby_path}/bin/ruby #{delayed_script_path} stop #{delayed_job_env}"
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
22
|
desc "Restart delayed_job process"
|
23
23
|
task :restart, :roles => delayed_job_role do
|
24
|
-
with_role(delayed_job_role) do
|
24
|
+
utilities.with_role(delayed_job_role) do
|
25
25
|
delayed_job.stop
|
26
26
|
sleep(4)
|
27
27
|
try_sudo "killall -s TERM delayed_job; true"
|
@@ -13,7 +13,7 @@ Capistrano::Configuration.instance(true).load do
|
|
13
13
|
|
14
14
|
desc "Starts the juggernaut push server"
|
15
15
|
task :start, :roles => juggernaut_role do
|
16
|
-
with_role(juggernaut_role) do
|
16
|
+
utilities.with_role(juggernaut_role) do
|
17
17
|
puts "Starting juggernaut push server"
|
18
18
|
try_sudo "#{base_ruby_path}/bin/juggernaut -c #{juggernaut_config} -d --pid #{juggernaut_pid} --log #{juggernaut_log}"
|
19
19
|
end
|
@@ -21,7 +21,7 @@ Capistrano::Configuration.instance(true).load do
|
|
21
21
|
|
22
22
|
desc "Stops the juggernaut push server"
|
23
23
|
task :stop, :roles => juggernaut_role do
|
24
|
-
with_role(juggernaut_role) do
|
24
|
+
utilities.with_role(juggernaut_role) do
|
25
25
|
puts "Stopping juggernaut push server"
|
26
26
|
try_sudo "#{base_ruby_path}/bin/juggernaut -c #{juggernaut_config} -k * --pid #{juggernaut_pid} --log #{juggernaut_log}"
|
27
27
|
end
|
@@ -29,7 +29,7 @@ Capistrano::Configuration.instance(true).load do
|
|
29
29
|
|
30
30
|
desc "Restarts the juggernaut push server"
|
31
31
|
task :restart, :roles => juggernaut_role do
|
32
|
-
with_role(juggernaut_role) do
|
32
|
+
utilities.with_role(juggernaut_role) do
|
33
33
|
juggernaut.stop
|
34
34
|
juggernaut.start
|
35
35
|
end
|
@@ -7,7 +7,7 @@ Capistrano::Configuration.instance(true).load do
|
|
7
7
|
|
8
8
|
desc "Stops the memcache server"
|
9
9
|
task :stop, :roles => memcache_role do
|
10
|
-
with_role(memcache_role) do
|
10
|
+
utilities.with_role(memcache_role) do
|
11
11
|
puts "Stopping the memcache server"
|
12
12
|
try_sudo "killall -s TERM memcached; true"
|
13
13
|
end
|
@@ -15,7 +15,7 @@ Capistrano::Configuration.instance(true).load do
|
|
15
15
|
|
16
16
|
desc "Starts the memcache server"
|
17
17
|
task :start, :roles => memcache_role do
|
18
|
-
with_role(memcache_role) do
|
18
|
+
utilities.with_role(memcache_role) do
|
19
19
|
puts "Starting the memcache server"
|
20
20
|
try_sudo "nohup /etc/init.d/memcached start"
|
21
21
|
end
|
@@ -23,7 +23,7 @@ Capistrano::Configuration.instance(true).load do
|
|
23
23
|
|
24
24
|
desc "Restarts the memcache server"
|
25
25
|
task :restart, :roles => memcache_role do
|
26
|
-
with_role(memcache_role) do
|
26
|
+
utilities.with_role(memcache_role) do
|
27
27
|
puts "Restarting the memcache server"
|
28
28
|
memcache.stop
|
29
29
|
sleep(3) # sleep for 3 seconds to make sure the server has mopped up everything
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'cap_recipes/tasks/
|
1
|
+
require 'cap_recipes/tasks/utilities.rb'
|
2
2
|
|
3
3
|
#TODO add something like require that a task named apache:restart exists
|
4
4
|
Capistrano::Configuration.instance(true).load do
|
@@ -41,22 +41,22 @@ Capistrano::Configuration.instance(true).load do
|
|
41
41
|
apache.restart
|
42
42
|
end
|
43
43
|
|
44
|
-
# if you want to add more options, try this, in your own conifg
|
45
|
-
# read this first... http://www.modrails.com/documentation/Users%20guide.html
|
46
|
-
# namespace :passenger do
|
47
|
-
# task :add_custom_configuration, :roles=>:web do
|
48
|
-
# #512 - 100(stack) - 4*100(instance)
|
49
|
-
# passenger_config = <<EOF
|
50
|
-
# PassengerMaxPoolSize 4
|
51
|
-
# PassengerPoolIdleTime 3000
|
52
|
-
# EOF
|
53
|
-
# put passenger_config, "/tmp/passenger"
|
54
|
-
# sudo "cat /tmp/passenger >> /etc/apache2/conf.d/passenger"
|
55
|
-
# apache.restart
|
56
|
-
# end
|
57
|
-
# end
|
58
|
-
# after "passenger:update_config", *%w(
|
59
|
-
# passenger:add_custom_configuration
|
60
|
-
# )
|
44
|
+
# if you want to add more options, try this, in your own conifg
|
45
|
+
# read this first... http://www.modrails.com/documentation/Users%20guide.html
|
46
|
+
# namespace :passenger do
|
47
|
+
# task :add_custom_configuration, :roles=>:web do
|
48
|
+
# #512 - 100(stack) - 4*100(instance)
|
49
|
+
# passenger_config = <<EOF
|
50
|
+
# PassengerMaxPoolSize 4
|
51
|
+
# PassengerPoolIdleTime 3000
|
52
|
+
# EOF
|
53
|
+
# put passenger_config, "/tmp/passenger"
|
54
|
+
# sudo "cat /tmp/passenger >> /etc/apache2/conf.d/passenger"
|
55
|
+
# apache.restart
|
56
|
+
# end
|
57
|
+
# end
|
58
|
+
# after "passenger:update_config", *%w(
|
59
|
+
# passenger:add_custom_configuration
|
60
|
+
# )
|
61
61
|
end
|
62
62
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'cap_recipes/tasks/
|
1
|
+
require 'cap_recipes/tasks/utilities.rb'
|
2
2
|
|
3
3
|
Capistrano::Configuration.instance(true).load do
|
4
4
|
set :local_ping_path, 'http://localhost'
|
@@ -8,14 +8,14 @@ Capistrano::Configuration.instance(true).load do
|
|
8
8
|
# UTILITY TASKS
|
9
9
|
# ===============================================================
|
10
10
|
desc "Symlinks the shared/config/database yaml to release/config/"
|
11
|
-
task :symlink_db_config, :roles => :
|
11
|
+
task :symlink_db_config, :roles => :app do
|
12
12
|
puts "Copying database configuration to release path"
|
13
13
|
try_sudo "rm #{release_path}/config/database.yml -f"
|
14
14
|
try_sudo "ln -s #{shared_path}/config/database.yml #{release_path}/config/database.yml"
|
15
15
|
end
|
16
16
|
|
17
17
|
desc "Repair permissions to allow user to perform all actions"
|
18
|
-
task :repair_permissions, :roles => :
|
18
|
+
task :repair_permissions, :roles => :app do
|
19
19
|
puts "Applying correct permissions to allow for proper command execution"
|
20
20
|
try_sudo "chmod -R 744 #{current_path}/log #{current_path}/tmp"
|
21
21
|
try_sudo "chown -R #{user}:#{user} #{current_path}"
|
@@ -23,12 +23,12 @@ Capistrano::Configuration.instance(true).load do
|
|
23
23
|
end
|
24
24
|
|
25
25
|
desc "Displays the production log from the server locally"
|
26
|
-
task :tail, :roles => :
|
26
|
+
task :tail, :roles => :app do
|
27
27
|
stream "tail -f #{shared_path}/log/production.log"
|
28
28
|
end
|
29
29
|
|
30
30
|
desc "Pings localhost to startup server"
|
31
|
-
task :ping, :roles => :
|
31
|
+
task :ping, :roles => :app do
|
32
32
|
puts "Pinging the web server to start it"
|
33
33
|
run "wget -O /dev/null #{local_ping_path} 2>/dev/null"
|
34
34
|
end
|
@@ -38,13 +38,13 @@ Capistrano::Configuration.instance(true).load do
|
|
38
38
|
# ===============================================================
|
39
39
|
namespace :sweep do
|
40
40
|
desc "Clear file-based fragment and action caching"
|
41
|
-
task :log, :roles => :
|
41
|
+
task :log, :roles => :app do
|
42
42
|
puts "Sweeping all the log files"
|
43
43
|
run "cd #{current_path} && #{sudo} rake log:clear RAILS_ENV=production"
|
44
44
|
end
|
45
45
|
|
46
46
|
desc "Clear file-based fragment and action caching"
|
47
|
-
task :cache, :roles => :
|
47
|
+
task :cache, :roles => :app do
|
48
48
|
puts "Sweeping the fragment and action cache stores"
|
49
49
|
run "cd #{release_path} && #{sudo} rake tmp:cache:clear RAILS_ENV=production"
|
50
50
|
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
Capistrano::Configuration.instance(true).load do
|
2
|
+
set :rubygem_paths, '/usr/bin/gem'
|
3
|
+
|
4
|
+
namespace :rubygems do
|
5
|
+
desc "Performs a rubygems upgrade, updates all gems and cleans up old ones"
|
6
|
+
task :full_update, :roles => :app do
|
7
|
+
rubygems.upgrade
|
8
|
+
rubygems.update
|
9
|
+
rubygems.cleanup
|
10
|
+
end
|
11
|
+
|
12
|
+
desc "Upgrades the rubygem package installation"
|
13
|
+
task :upgrade, :roles => :app do
|
14
|
+
Array(rubygem_paths).each { |path| sudo "#{path} update --system" }
|
15
|
+
end
|
16
|
+
|
17
|
+
desc "Updates all installed gems"
|
18
|
+
task :update, :roles => :app do
|
19
|
+
Array(rubygem_paths).each { |path| sudo "#{path} update" }
|
20
|
+
end
|
21
|
+
|
22
|
+
desc "Removes old gems which are now outdated"
|
23
|
+
task :cleanup, :roles => :app do
|
24
|
+
Array(rubygem_paths).each { |path| sudo "#{path} cleanup" }
|
25
|
+
end
|
26
|
+
|
27
|
+
desc "Install a gem on your servers servers"
|
28
|
+
task :install, :roles => :app do
|
29
|
+
puts "Enter the name of the gem you'd like to install:"
|
30
|
+
gem_name = $stdin.gets.chomp
|
31
|
+
logger.info "trying to install '#{gem_name}'"
|
32
|
+
Array(rubygem_paths).each {|path| sudo "#{path} install #{gem_name} --no-ri --no-rdoc" }
|
33
|
+
end
|
34
|
+
|
35
|
+
desc "Uninstall a gem from the release servers"
|
36
|
+
task :uninstall, :roles => :app do
|
37
|
+
puts "Enter the name of the gem you'd like to remove:"
|
38
|
+
gem_name = $stdin.gets.chomp
|
39
|
+
logger.info "trying to remove '#{gem_name}'"
|
40
|
+
Array(rubygem_paths).each { |path| sudo "#{path} uninstall #{gem_name} -x" }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
Dir[File.join(File.dirname(__FILE__), 'rubygems/*.rb')].sort.each { |lib| require lib }
|
@@ -0,0 +1,113 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
module Utilities
|
4
|
+
def config_gsub(file, find, replace)
|
5
|
+
tmp="/tmp/#{File.basename(file)}"
|
6
|
+
get file, tmp
|
7
|
+
content=File.open(tmp).read
|
8
|
+
content.gsub!(find,replace)
|
9
|
+
put content, tmp
|
10
|
+
sudo "mv #{tmp} #{file}"
|
11
|
+
end
|
12
|
+
|
13
|
+
def sudo_upload(from, to, options={}, &block)
|
14
|
+
top.upload from, "/tmp/#{File.basename(to)}", options, &block
|
15
|
+
sudo "mv /tmp/#{File.basename(to)} #{to}"
|
16
|
+
sudo "chmod #{options[:mode]} #{to}" if options[:mode]
|
17
|
+
sudo "chown #{options[:owner]} #{to}" if options[:owner]
|
18
|
+
end
|
19
|
+
|
20
|
+
def adduser(user, options={})
|
21
|
+
options[:shell] ||= '/bin/bash' # new accounts on ubuntu 6.06.1 have been getting /bin/sh
|
22
|
+
switches = '--disabled-password --gecos ""'
|
23
|
+
switches += " --shell=#{options[:shell]} " if options[:shell]
|
24
|
+
switches += ' --no-create-home ' if options[:nohome]
|
25
|
+
switches += " --ingroup #{options[:group]} " unless options[:group].nil?
|
26
|
+
invoke_command "grep '^#{user}:' /etc/passwd || sudo /usr/sbin/adduser #{user} #{switches}",
|
27
|
+
:via => run_method
|
28
|
+
end
|
29
|
+
|
30
|
+
# role = :app
|
31
|
+
def with_role(role, &block)
|
32
|
+
original, ENV['HOSTS'] = ENV['HOSTS'], find_servers(:roles => role).map{|d| d.host}.join(",")
|
33
|
+
begin
|
34
|
+
yield
|
35
|
+
ensure
|
36
|
+
ENV['HOSTS'] = original
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# options = { :user => 'xxxxx', :password => 'xxxxx' }
|
41
|
+
def with_credentials(options={}, &block)
|
42
|
+
original_username, original_password = user, password
|
43
|
+
begin
|
44
|
+
set :user, options[:user] || original_username
|
45
|
+
set :password, options[:password] || original_password
|
46
|
+
yield
|
47
|
+
ensure
|
48
|
+
set :user, original_username
|
49
|
+
set :password, original_password
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
##
|
54
|
+
# Run a command and ask for input when input_query is seen.
|
55
|
+
# Sends the response back to the server.
|
56
|
+
#
|
57
|
+
# +input_query+ is a regular expression that defaults to /^Password/.
|
58
|
+
#
|
59
|
+
# Can be used where +run+ would otherwise be used.
|
60
|
+
#
|
61
|
+
# run_with_input 'ssh-keygen ...', /^Are you sure you want to overwrite\?/
|
62
|
+
|
63
|
+
def run_with_input(shell_command, input_query=/^Password/, response=nil)
|
64
|
+
handle_command_with_input(:run, shell_command, input_query, response)
|
65
|
+
end
|
66
|
+
|
67
|
+
##
|
68
|
+
# Run a command using sudo and ask for input when a regular expression is seen.
|
69
|
+
# Sends the response back to the server.
|
70
|
+
#
|
71
|
+
# See also +run_with_input+
|
72
|
+
#
|
73
|
+
# +input_query+ is a regular expression
|
74
|
+
|
75
|
+
def sudo_with_input(shell_command, input_query=/^Password/, response=nil)
|
76
|
+
handle_command_with_input(:sudo, shell_command, input_query, response)
|
77
|
+
end
|
78
|
+
|
79
|
+
def invoke_with_input(shell_command, input_query=/^Password/, response=nil)
|
80
|
+
handle_command_with_input(run_method, shell_command, input_query, response)
|
81
|
+
end
|
82
|
+
|
83
|
+
private
|
84
|
+
|
85
|
+
##
|
86
|
+
# Does the actual capturing of the input and streaming of the output.
|
87
|
+
#
|
88
|
+
# local_run_method: run or sudo
|
89
|
+
# shell_command: The command to run
|
90
|
+
# input_query: A regular expression matching a request for input: /^Please enter your password/
|
91
|
+
|
92
|
+
def handle_command_with_input(local_run_method, shell_command, input_query, response=nil)
|
93
|
+
send(local_run_method, shell_command, {:pty => true}) do |channel, stream, data|
|
94
|
+
|
95
|
+
if data =~ input_query
|
96
|
+
if response
|
97
|
+
logger.info "#{data} #{"*"*(rand(10)+5)}", channel[:host]
|
98
|
+
channel.send_data "#{response}\n"
|
99
|
+
else
|
100
|
+
logger.info data, channel[:host]
|
101
|
+
response = ::Capistrano::CLI.password_prompt "#{data}"
|
102
|
+
channel.send_data "#{response}\n"
|
103
|
+
end
|
104
|
+
else
|
105
|
+
logger.info data, channel[:host]
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
|
111
|
+
end
|
112
|
+
|
113
|
+
Capistrano.plugin :utilities, Utilities
|
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.3.
|
4
|
+
version: 0.3.17
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Esquenazi
|
@@ -9,11 +9,11 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-06-
|
12
|
+
date: 2009-06-07 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
16
|
-
description: Battle-tested capistrano recipes for passenger, apache, delayed_job, juggernaut, backgroundrb, rails and more
|
16
|
+
description: Battle-tested capistrano recipes for debian, passenger, apache, delayed_job, juggernaut, rubygems, backgroundrb, rails and more
|
17
17
|
email: nesquena@gmail.com
|
18
18
|
executables: []
|
19
19
|
|
@@ -33,6 +33,8 @@ files:
|
|
33
33
|
- lib/cap_recipes/tasks/apache.rb
|
34
34
|
- lib/cap_recipes/tasks/apache/install.rb
|
35
35
|
- lib/cap_recipes/tasks/apache/manage.rb
|
36
|
+
- lib/cap_recipes/tasks/aptitude.rb
|
37
|
+
- lib/cap_recipes/tasks/aptitude/manage.rb
|
36
38
|
- lib/cap_recipes/tasks/backgroundrb.rb
|
37
39
|
- lib/cap_recipes/tasks/backgroundrb/hooks.rb
|
38
40
|
- lib/cap_recipes/tasks/backgroundrb/manage.rb
|
@@ -52,10 +54,12 @@ files:
|
|
52
54
|
- lib/cap_recipes/tasks/rails.rb
|
53
55
|
- lib/cap_recipes/tasks/rails/hooks.rb
|
54
56
|
- lib/cap_recipes/tasks/rails/manage.rb
|
57
|
+
- lib/cap_recipes/tasks/rubygems.rb
|
58
|
+
- lib/cap_recipes/tasks/rubygems/manage.rb
|
59
|
+
- lib/cap_recipes/tasks/utilities.rb
|
55
60
|
- lib/cap_recipes/tasks/whenever.rb
|
56
61
|
- lib/cap_recipes/tasks/whenever/hooks.rb
|
57
62
|
- lib/cap_recipes/tasks/whenever/manage.rb
|
58
|
-
- lib/cap_recipes/tasks/with_scope.rb
|
59
63
|
- spec/cap/all/Capfile
|
60
64
|
- spec/cap/helper.rb
|
61
65
|
- spec/cap_recipes_spec.rb
|
@@ -1,22 +0,0 @@
|
|
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
|