capitate 0.1.7
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/Capfile +24 -0
- data/History.txt +22 -0
- data/License.txt +20 -0
- data/Manifest.txt +100 -0
- data/README.txt +1 -0
- data/Rakefile +4 -0
- data/bin/capitate +46 -0
- data/config/hoe.rb +70 -0
- data/config/requirements.rb +17 -0
- data/lib/capitate/cap_ext/connections.rb +95 -0
- data/lib/capitate/cap_ext/extension_proxy.rb +15 -0
- data/lib/capitate/cap_ext/variables.rb +59 -0
- data/lib/capitate/config.rb +106 -0
- data/lib/capitate/plugins/base.rb +85 -0
- data/lib/capitate/plugins/gem.rb +25 -0
- data/lib/capitate/plugins/package.rb +30 -0
- data/lib/capitate/plugins/profiles.rb +33 -0
- data/lib/capitate/plugins/script.rb +118 -0
- data/lib/capitate/plugins/templates.rb +98 -0
- data/lib/capitate/plugins/wget.rb +23 -0
- data/lib/capitate/plugins/yum.rb +87 -0
- data/lib/capitate/recipes.rb +9 -0
- data/lib/capitate/version.rb +9 -0
- data/lib/capitate.rb +32 -0
- data/lib/doc/centos/memcached.yml +18 -0
- data/lib/doc/centos/mongrel_cluster.yml +11 -0
- data/lib/doc/centos/monit.yml +12 -0
- data/lib/doc/centos/mysql.yml +6 -0
- data/lib/doc/centos/nginx.yml +25 -0
- data/lib/doc/centos/sphinx.yml +14 -0
- data/lib/doc/gems.yml +7 -0
- data/lib/doc/install.yml +11 -0
- data/lib/doc/memcached.yml +13 -0
- data/lib/doc/mongrel_cluster.yml +12 -0
- data/lib/doc/mysql.yml +46 -0
- data/lib/doc/nginx.yml +23 -0
- data/lib/doc/packages.yml +17 -0
- data/lib/doc/rails.yml +15 -0
- data/lib/profiles/centos-sick.rb +114 -0
- data/lib/recipes/README +5 -0
- data/lib/recipes/centos/README +3 -0
- data/lib/recipes/centos/centos.rb +44 -0
- data/lib/recipes/centos/imagemagick.rb +19 -0
- data/lib/recipes/centos/memcached.rb +31 -0
- data/lib/recipes/centos/mongrel_cluster.rb +34 -0
- data/lib/recipes/centos/monit.rb +42 -0
- data/lib/recipes/centos/mysql.rb +25 -0
- data/lib/recipes/centos/nginx.rb +45 -0
- data/lib/recipes/centos/ruby.rb +37 -0
- data/lib/recipes/centos/sphinx.rb +49 -0
- data/lib/recipes/deploy.rb +18 -0
- data/lib/recipes/gems.rb +11 -0
- data/lib/recipes/install.rb +18 -0
- data/lib/recipes/memcached.rb +14 -0
- data/lib/recipes/mongrel_cluster.rb +33 -0
- data/lib/recipes/mysql.rb +33 -0
- data/lib/recipes/nginx.rb +40 -0
- data/lib/recipes/packages.rb +24 -0
- data/lib/recipes/rails.rb +20 -0
- data/lib/recipes/sphinx.rb +38 -0
- data/lib/templates/capistrano/Capfile +26 -0
- data/lib/templates/centos/setup_for_web.sh +17 -0
- data/lib/templates/centos/sudoers +95 -0
- data/lib/templates/memcached/memcached.initd.centos.erb +70 -0
- data/lib/templates/memcached/memcached.monitrc.erb +4 -0
- data/lib/templates/mongrel/mongrel_cluster.initd.erb +61 -0
- data/lib/templates/mongrel/mongrel_cluster.monitrc.erb +15 -0
- data/lib/templates/mongrel/mongrel_cluster.yml.erb +10 -0
- data/lib/templates/monit/cert.sh +14 -0
- data/lib/templates/monit/monit.cnf +34 -0
- data/lib/templates/monit/monit.initd.centos.erb +68 -0
- data/lib/templates/monit/monitrc.erb +28 -0
- data/lib/templates/monit/patch_inittab.sh +15 -0
- data/lib/templates/mysql/install_db.sql.erb +7 -0
- data/lib/templates/mysql/mysql.monitrc.erb +6 -0
- data/lib/templates/nginx/nginx.conf.erb +88 -0
- data/lib/templates/nginx/nginx.initd.erb +62 -0
- data/lib/templates/nginx/nginx.monitrc.erb +4 -0
- data/lib/templates/nginx/nginx_vhost.conf.erb +95 -0
- data/lib/templates/rails/database.yml.erb +42 -0
- data/lib/templates/ruby/fix_openssl.sh +12 -0
- data/lib/templates/sphinx/sphinx.conf.erb +498 -0
- data/lib/templates/sphinx/sphinx.monitrc.erb +4 -0
- data/lib/templates/sphinx/sphinx_app.initd.centos.erb +67 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/script/txt2html +74 -0
- data/setup.rb +1585 -0
- data/tasks/capitate.rake +10 -0
- data/tasks/deployment.rake +34 -0
- data/tasks/environment.rake +7 -0
- data/tasks/website.rake +17 -0
- data/test/test_helper.rb +2 -0
- data/test/test_recipes.rb +11 -0
- data/test/test_templates.rb +29 -0
- data/website/index.html +161 -0
- data/website/index.txt +86 -0
- data/website/javascripts/rounded_corners_lite.inc.js +285 -0
- data/website/stylesheets/screen.css +138 -0
- data/website/template.rhtml +48 -0
- metadata +160 -0
data/Capfile
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Capfile for running base install recipe
|
|
3
|
+
#
|
|
4
|
+
|
|
5
|
+
load 'deploy' if respond_to?(:namespace) # cap2 differentiator
|
|
6
|
+
|
|
7
|
+
require 'lib/capitate'
|
|
8
|
+
|
|
9
|
+
# Load recipes
|
|
10
|
+
Dir["lib/recipes/**/*.rb"].each { |recipe| load recipe }
|
|
11
|
+
|
|
12
|
+
require 'erb'
|
|
13
|
+
|
|
14
|
+
# This should be overriden by project specific Capfile
|
|
15
|
+
set :user, Proc.new { Capistrano::CLI.ui.ask('Bootstrap user: ') }
|
|
16
|
+
|
|
17
|
+
# Roles
|
|
18
|
+
role :base, Capistrano::CLI.ui.ask('Server: ')
|
|
19
|
+
|
|
20
|
+
# Choose a profile
|
|
21
|
+
set :profile, Proc.new { load profile.choose }
|
|
22
|
+
|
|
23
|
+
# Reset the password var
|
|
24
|
+
reset_password
|
data/History.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
== 0.1.5 ?
|
|
2
|
+
|
|
3
|
+
* Renamed to 'capitate'
|
|
4
|
+
* Moving centos specific recipes into separate namespace
|
|
5
|
+
* Plugin: script.make_install
|
|
6
|
+
* Documentation and explicitly fetching vars (for install tasks), showing useful error messages
|
|
7
|
+
|
|
8
|
+
== 0.1.4 2008-02-07
|
|
9
|
+
|
|
10
|
+
* Using capistrano's plugin architecture instead of hacking around
|
|
11
|
+
|
|
12
|
+
== 0.1.3 2008-02-06
|
|
13
|
+
|
|
14
|
+
* Fixing local recipes
|
|
15
|
+
|
|
16
|
+
== 0.1.2 2008-02-06
|
|
17
|
+
|
|
18
|
+
* Loading recipes from gem
|
|
19
|
+
|
|
20
|
+
== 0.1.1 2008-02-06
|
|
21
|
+
|
|
22
|
+
* Initial import
|
data/License.txt
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright (c) 2008 Gabriel Handford
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Manifest.txt
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
Capfile
|
|
2
|
+
History.txt
|
|
3
|
+
License.txt
|
|
4
|
+
Manifest.txt
|
|
5
|
+
README.txt
|
|
6
|
+
Rakefile
|
|
7
|
+
bin/capitate
|
|
8
|
+
config/hoe.rb
|
|
9
|
+
config/requirements.rb
|
|
10
|
+
lib/capitate.rb
|
|
11
|
+
lib/capitate/cap_ext/connections.rb
|
|
12
|
+
lib/capitate/cap_ext/extension_proxy.rb
|
|
13
|
+
lib/capitate/cap_ext/variables.rb
|
|
14
|
+
lib/capitate/config.rb
|
|
15
|
+
lib/capitate/plugins/base.rb
|
|
16
|
+
lib/capitate/plugins/gem.rb
|
|
17
|
+
lib/capitate/plugins/package.rb
|
|
18
|
+
lib/capitate/plugins/profiles.rb
|
|
19
|
+
lib/capitate/plugins/script.rb
|
|
20
|
+
lib/capitate/plugins/templates.rb
|
|
21
|
+
lib/capitate/plugins/wget.rb
|
|
22
|
+
lib/capitate/plugins/yum.rb
|
|
23
|
+
lib/capitate/recipes.rb
|
|
24
|
+
lib/capitate/version.rb
|
|
25
|
+
lib/doc/centos/memcached.yml
|
|
26
|
+
lib/doc/centos/mongrel_cluster.yml
|
|
27
|
+
lib/doc/centos/monit.yml
|
|
28
|
+
lib/doc/centos/mysql.yml
|
|
29
|
+
lib/doc/centos/nginx.yml
|
|
30
|
+
lib/doc/centos/sphinx.yml
|
|
31
|
+
lib/doc/gems.yml
|
|
32
|
+
lib/doc/install.yml
|
|
33
|
+
lib/doc/memcached.yml
|
|
34
|
+
lib/doc/mongrel_cluster.yml
|
|
35
|
+
lib/doc/mysql.yml
|
|
36
|
+
lib/doc/nginx.yml
|
|
37
|
+
lib/doc/packages.yml
|
|
38
|
+
lib/doc/rails.yml
|
|
39
|
+
lib/profiles/centos-sick.rb
|
|
40
|
+
lib/recipes/README
|
|
41
|
+
lib/recipes/centos/README
|
|
42
|
+
lib/recipes/centos/centos.rb
|
|
43
|
+
lib/recipes/centos/imagemagick.rb
|
|
44
|
+
lib/recipes/centos/memcached.rb
|
|
45
|
+
lib/recipes/centos/mongrel_cluster.rb
|
|
46
|
+
lib/recipes/centos/monit.rb
|
|
47
|
+
lib/recipes/centos/mysql.rb
|
|
48
|
+
lib/recipes/centos/nginx.rb
|
|
49
|
+
lib/recipes/centos/ruby.rb
|
|
50
|
+
lib/recipes/centos/sphinx.rb
|
|
51
|
+
lib/recipes/deploy.rb
|
|
52
|
+
lib/recipes/gems.rb
|
|
53
|
+
lib/recipes/install.rb
|
|
54
|
+
lib/recipes/memcached.rb
|
|
55
|
+
lib/recipes/mongrel_cluster.rb
|
|
56
|
+
lib/recipes/mysql.rb
|
|
57
|
+
lib/recipes/nginx.rb
|
|
58
|
+
lib/recipes/packages.rb
|
|
59
|
+
lib/recipes/rails.rb
|
|
60
|
+
lib/recipes/sphinx.rb
|
|
61
|
+
lib/templates/capistrano/Capfile
|
|
62
|
+
lib/templates/centos/setup_for_web.sh
|
|
63
|
+
lib/templates/centos/sudoers
|
|
64
|
+
lib/templates/memcached/memcached.initd.centos.erb
|
|
65
|
+
lib/templates/memcached/memcached.monitrc.erb
|
|
66
|
+
lib/templates/mongrel/mongrel_cluster.initd.erb
|
|
67
|
+
lib/templates/mongrel/mongrel_cluster.monitrc.erb
|
|
68
|
+
lib/templates/mongrel/mongrel_cluster.yml.erb
|
|
69
|
+
lib/templates/monit/cert.sh
|
|
70
|
+
lib/templates/monit/monit.cnf
|
|
71
|
+
lib/templates/monit/monit.initd.centos.erb
|
|
72
|
+
lib/templates/monit/monitrc.erb
|
|
73
|
+
lib/templates/monit/patch_inittab.sh
|
|
74
|
+
lib/templates/mysql/install_db.sql.erb
|
|
75
|
+
lib/templates/mysql/mysql.monitrc.erb
|
|
76
|
+
lib/templates/nginx/nginx.conf.erb
|
|
77
|
+
lib/templates/nginx/nginx.initd.erb
|
|
78
|
+
lib/templates/nginx/nginx.monitrc.erb
|
|
79
|
+
lib/templates/nginx/nginx_vhost.conf.erb
|
|
80
|
+
lib/templates/rails/database.yml.erb
|
|
81
|
+
lib/templates/ruby/fix_openssl.sh
|
|
82
|
+
lib/templates/sphinx/sphinx.conf.erb
|
|
83
|
+
lib/templates/sphinx/sphinx.monitrc.erb
|
|
84
|
+
lib/templates/sphinx/sphinx_app.initd.centos.erb
|
|
85
|
+
script/destroy
|
|
86
|
+
script/generate
|
|
87
|
+
script/txt2html
|
|
88
|
+
setup.rb
|
|
89
|
+
tasks/capitate.rake
|
|
90
|
+
tasks/deployment.rake
|
|
91
|
+
tasks/environment.rake
|
|
92
|
+
tasks/website.rake
|
|
93
|
+
test/test_helper.rb
|
|
94
|
+
test/test_recipes.rb
|
|
95
|
+
test/test_templates.rb
|
|
96
|
+
website/index.html
|
|
97
|
+
website/index.txt
|
|
98
|
+
website/javascripts/rounded_corners_lite.inc.js
|
|
99
|
+
website/stylesheets/screen.css
|
|
100
|
+
website/template.rhtml
|
data/README.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
See website/index.txt
|
data/Rakefile
ADDED
data/bin/capitate
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
APP_ROOT = File.join(File.dirname(__FILE__), '..')
|
|
3
|
+
|
|
4
|
+
begin
|
|
5
|
+
require 'capitate'
|
|
6
|
+
rescue LoadError
|
|
7
|
+
require 'rubygems'
|
|
8
|
+
require 'capitate'
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def usage
|
|
12
|
+
puts <<-EOS
|
|
13
|
+
|
|
14
|
+
Capitate your project.
|
|
15
|
+
|
|
16
|
+
Usage:
|
|
17
|
+
|
|
18
|
+
#{$0} bootstrap
|
|
19
|
+
|
|
20
|
+
EOS
|
|
21
|
+
|
|
22
|
+
exit 1
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
class CapitateBin
|
|
26
|
+
class << self
|
|
27
|
+
include Capitate::Plugins::Templates
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
puts <<-EOS
|
|
32
|
+
|
|
33
|
+
Generating capistrano configuration...
|
|
34
|
+
|
|
35
|
+
EOS
|
|
36
|
+
|
|
37
|
+
# Write Capfile
|
|
38
|
+
CapitateBin.write("capistrano/Capfile", "Capfile")
|
|
39
|
+
|
|
40
|
+
puts <<-EOS
|
|
41
|
+
|
|
42
|
+
You now need to create and set you deployment "profile" in the Capfile.
|
|
43
|
+
This is currently a manual process, see the documentation on profiles
|
|
44
|
+
for more information.
|
|
45
|
+
|
|
46
|
+
EOS
|
data/config/hoe.rb
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
require 'capitate/version'
|
|
2
|
+
|
|
3
|
+
AUTHOR = 'Gabriel Handford' # can also be an array of Authors
|
|
4
|
+
EMAIL = "gabrielh@gmail.com"
|
|
5
|
+
DESCRIPTION = "Capistrano recipe library for all types of remote tasks."
|
|
6
|
+
GEM_NAME = 'capitate' # what ppl will type to install your gem
|
|
7
|
+
RUBYFORGE_PROJECT = 'capitate' # The unix name for your project
|
|
8
|
+
HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
|
|
9
|
+
DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
|
|
10
|
+
|
|
11
|
+
@config_file = "~/.rubyforge/user-config.yml"
|
|
12
|
+
@config = nil
|
|
13
|
+
RUBYFORGE_USERNAME = "gabe"
|
|
14
|
+
def rubyforge_username
|
|
15
|
+
unless @config
|
|
16
|
+
begin
|
|
17
|
+
@config = YAML.load(File.read(File.expand_path(@config_file)))
|
|
18
|
+
rescue
|
|
19
|
+
puts <<-EOS
|
|
20
|
+
ERROR: No rubyforge config file found: #{@config_file}
|
|
21
|
+
Run 'rubyforge setup' to prepare your env for access to Rubyforge
|
|
22
|
+
- See http://newgem.rubyforge.org/rubyforge.html for more details
|
|
23
|
+
EOS
|
|
24
|
+
exit
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
RUBYFORGE_USERNAME.replace @config["username"]
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
REV = nil
|
|
32
|
+
# UNCOMMENT IF REQUIRED:
|
|
33
|
+
# REV = `svn info`.each {|line| if line =~ /^Revision:/ then k,v = line.split(': '); break v.chomp; else next; end} rescue nil
|
|
34
|
+
VERS = Capitate::VERSION::STRING + (REV ? ".#{REV}" : "")
|
|
35
|
+
RDOC_OPTS = ['--quiet', '--title', 'capitate documentation',
|
|
36
|
+
"--opname", "index.html",
|
|
37
|
+
"--line-numbers",
|
|
38
|
+
"--main", "README",
|
|
39
|
+
"--inline-source"]
|
|
40
|
+
|
|
41
|
+
class Hoe
|
|
42
|
+
def extra_deps
|
|
43
|
+
@extra_deps.reject! { |x| Array(x).first == 'hoe' }
|
|
44
|
+
@extra_deps
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# Generate all the Rake tasks
|
|
49
|
+
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
|
50
|
+
hoe = Hoe.new(GEM_NAME, VERS) do |p|
|
|
51
|
+
p.developer(AUTHOR, EMAIL)
|
|
52
|
+
p.description = DESCRIPTION
|
|
53
|
+
p.summary = DESCRIPTION
|
|
54
|
+
p.url = HOMEPATH
|
|
55
|
+
p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
|
|
56
|
+
p.test_globs = ["test/**/test_*.rb"]
|
|
57
|
+
p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
|
|
58
|
+
|
|
59
|
+
# == Optional
|
|
60
|
+
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
|
|
61
|
+
#p.extra_deps = [] # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]
|
|
62
|
+
|
|
63
|
+
#p.spec_extras = {} # A hash of extra values to set in the gemspec.
|
|
64
|
+
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
CHANGES = hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
|
|
68
|
+
PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
|
|
69
|
+
hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
|
|
70
|
+
hoe.rsync_args = '-av --delete --ignore-errors'
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require 'fileutils'
|
|
2
|
+
include FileUtils
|
|
3
|
+
|
|
4
|
+
require 'rubygems'
|
|
5
|
+
%w[rake hoe newgem rubigen].each do |req_gem|
|
|
6
|
+
begin
|
|
7
|
+
require req_gem
|
|
8
|
+
rescue LoadError
|
|
9
|
+
puts "This Rakefile requires the '#{req_gem}' RubyGem."
|
|
10
|
+
puts "Installation: gem install #{req_gem} -y"
|
|
11
|
+
exit
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
$:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
|
|
16
|
+
|
|
17
|
+
require 'capitate'
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# Patch to add ability to clear sessions/connections.
|
|
2
|
+
module Capistrano::Configuration::Connections
|
|
3
|
+
|
|
4
|
+
# Set the user to something new (but save the old user; reset_user will set it back).
|
|
5
|
+
# Takes care of invalidating current connections. Will force a re-login.
|
|
6
|
+
#
|
|
7
|
+
# ==== Options
|
|
8
|
+
# +new_user+:: User to become
|
|
9
|
+
#
|
|
10
|
+
# ==== Examples
|
|
11
|
+
# set_user("nginx")
|
|
12
|
+
# # Do something as user nginx
|
|
13
|
+
#
|
|
14
|
+
def set_user(new_user)
|
|
15
|
+
backup_user = fetch(:user)
|
|
16
|
+
|
|
17
|
+
return if backup_user == new_user
|
|
18
|
+
@backup_user = backup_user
|
|
19
|
+
|
|
20
|
+
set :user, new_user
|
|
21
|
+
clear_sessions
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Reset to the old user.
|
|
25
|
+
# Takes care of invalidating current connections. Will force a re-login.
|
|
26
|
+
#
|
|
27
|
+
# ==== Examples
|
|
28
|
+
# # User is "root"
|
|
29
|
+
# set_user("nginx")
|
|
30
|
+
# # Do something as user nginx
|
|
31
|
+
# reset_user
|
|
32
|
+
# # User is now root
|
|
33
|
+
#
|
|
34
|
+
def reset_user
|
|
35
|
+
set :user, @backup_user
|
|
36
|
+
@backup_user = nil
|
|
37
|
+
clear_sessions
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# Yields the previous user.
|
|
41
|
+
#
|
|
42
|
+
# ==== Options
|
|
43
|
+
# +new_user+:: User to become
|
|
44
|
+
#
|
|
45
|
+
# ==== Examples
|
|
46
|
+
# new_user("nginx") do |old_user|
|
|
47
|
+
# # Do something as user nginx
|
|
48
|
+
# end
|
|
49
|
+
# # Now as user old_user
|
|
50
|
+
#
|
|
51
|
+
def with_user(new_user, &block)
|
|
52
|
+
begin
|
|
53
|
+
set_user(new_user)
|
|
54
|
+
yield @backup_user
|
|
55
|
+
ensure
|
|
56
|
+
reset_user
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
clear_sessions
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# Close all open sessions.
|
|
63
|
+
# Will force user to re-login.
|
|
64
|
+
def clear_sessions
|
|
65
|
+
sessions.each do |key, session|
|
|
66
|
+
logger.info "Closing: #{key}"
|
|
67
|
+
session.close
|
|
68
|
+
end
|
|
69
|
+
sessions.clear
|
|
70
|
+
reset_password
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# Reset the password.
|
|
74
|
+
# Display the current user that is asking for the password.
|
|
75
|
+
def reset_password
|
|
76
|
+
set :password, Proc.new {
|
|
77
|
+
Capistrano::CLI.password_prompt("Password (for user: #{user}): ")
|
|
78
|
+
}
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
# Debug connections
|
|
84
|
+
# class Capistrano::SSH
|
|
85
|
+
#
|
|
86
|
+
# class << self
|
|
87
|
+
#
|
|
88
|
+
# def connect_with_logging(server, options={}, &block)
|
|
89
|
+
# connect_without_logging(server, options, &block)
|
|
90
|
+
# end
|
|
91
|
+
#
|
|
92
|
+
# alias_method_chain :connect, :logging
|
|
93
|
+
#
|
|
94
|
+
# end
|
|
95
|
+
# end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
class Capistrano::ExtensionProxy
|
|
2
|
+
|
|
3
|
+
# Allow ability to include modules in plugins.
|
|
4
|
+
#
|
|
5
|
+
# ==== Options
|
|
6
|
+
# +mod+:: Module
|
|
7
|
+
#
|
|
8
|
+
# ==== Examples
|
|
9
|
+
# include Capitate::Plugins::Yum
|
|
10
|
+
#
|
|
11
|
+
def include(mod)
|
|
12
|
+
self.class.send(:include, mod)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
end
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
module Capitate
|
|
2
|
+
module CapExt
|
|
3
|
+
module Variables
|
|
4
|
+
|
|
5
|
+
def self.included(base) #:nodoc:
|
|
6
|
+
base.send :alias_method, :fetch_without_capitate, :fetch
|
|
7
|
+
base.send :alias_method, :fetch, :fetch_with_capitate
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
# Fetch (alias method chained) variable.
|
|
11
|
+
# Displays usage message from recipe docs if variable not found.
|
|
12
|
+
#
|
|
13
|
+
# See capistrano fetch for usage info.
|
|
14
|
+
#
|
|
15
|
+
# Recipe docs are in lib/doc/the_namespace.yml
|
|
16
|
+
#
|
|
17
|
+
def fetch_with_capitate(variable, *args)
|
|
18
|
+
begin
|
|
19
|
+
fetch_without_capitate(variable, *args)
|
|
20
|
+
rescue IndexError
|
|
21
|
+
message = capitate.usage(variable)
|
|
22
|
+
|
|
23
|
+
if message.blank?
|
|
24
|
+
message = <<-EOS
|
|
25
|
+
|
|
26
|
+
Please set :#{variable} variable in your Capfile or profile.
|
|
27
|
+
|
|
28
|
+
EOS
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
raise IndexError, "\n#{message}"
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Fetch or set and return default.
|
|
36
|
+
#
|
|
37
|
+
# ==== Options
|
|
38
|
+
# +variable+:: Variable to fetch
|
|
39
|
+
# +default+:: Default value if not set
|
|
40
|
+
# +args+:: ?
|
|
41
|
+
#
|
|
42
|
+
# ==== Examples
|
|
43
|
+
# fetch_or_default(:memcached_port, 11211) => 11211
|
|
44
|
+
# # Any calls to fetch(memcached_port) in the future will return this value 11211 (unless overriden)
|
|
45
|
+
#
|
|
46
|
+
def fetch_or_default(variable, default, *args)
|
|
47
|
+
begin
|
|
48
|
+
return fetch(variable, *args)
|
|
49
|
+
rescue IndexError
|
|
50
|
+
set variable, default
|
|
51
|
+
end
|
|
52
|
+
default
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
end
|
|
59
|
+
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
require 'yaml'
|
|
2
|
+
require 'highline'
|
|
3
|
+
|
|
4
|
+
# DEPRECATED, not in use.
|
|
5
|
+
#
|
|
6
|
+
# Application configuration for helping generate Capfile and deploy.rb.
|
|
7
|
+
#
|
|
8
|
+
class Capitate::Config
|
|
9
|
+
|
|
10
|
+
attr_accessor :application, :user, :deploy_to, :web_host
|
|
11
|
+
attr_accessor :db_host, :db_user, :db_pass, :db_name, :db_port
|
|
12
|
+
attr_accessor :sphinx_port, :sphinx_host
|
|
13
|
+
attr_accessor :repository, :recipes
|
|
14
|
+
attr_accessor :mongrel_port, :mongrel_size
|
|
15
|
+
attr_accessor :domain_name
|
|
16
|
+
|
|
17
|
+
def initialize
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# Expose the binding.
|
|
21
|
+
def get_binding
|
|
22
|
+
binding
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# Ask for property.
|
|
26
|
+
#
|
|
27
|
+
# ==== Options
|
|
28
|
+
# +message+:: Prompt
|
|
29
|
+
# +property+:: Property
|
|
30
|
+
# +options+:: Options
|
|
31
|
+
# - :default, Default value, defaults to nil
|
|
32
|
+
# - :answer_type, Highline answer type, defaults to String
|
|
33
|
+
# - :auto_apply, If true and property is set don't ask for it
|
|
34
|
+
#
|
|
35
|
+
# ==== Examples
|
|
36
|
+
# ask("Database port: ", "db_port", { :default => 3306, :answer_type => Integer })
|
|
37
|
+
#
|
|
38
|
+
def ask(message, property, options = {}, &block)
|
|
39
|
+
# Options
|
|
40
|
+
default = options[:default] || nil
|
|
41
|
+
answer_type = options[:answer_type] || String
|
|
42
|
+
auto_apply = options[:auto_apply]
|
|
43
|
+
|
|
44
|
+
# Default to existing or default if set
|
|
45
|
+
existing = send(property.to_sym)
|
|
46
|
+
default = existing || default
|
|
47
|
+
|
|
48
|
+
unless auto_apply and !existing.blank?
|
|
49
|
+
result = HighLine.new.ask(message, answer_type) { |q|
|
|
50
|
+
q.default = default unless default.blank?
|
|
51
|
+
yield q if block_given?
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
send("#{property}=", result)
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# For property, set to value if blank.
|
|
59
|
+
def set_default(property, value)
|
|
60
|
+
v = send(property.to_sym)
|
|
61
|
+
send("#{property}=", value) if v.blank?
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# Save to yaml.
|
|
65
|
+
def save(path)
|
|
66
|
+
File.open(path, "w") { |f| f.puts self.to_yaml }
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# Build config from asking.
|
|
70
|
+
#
|
|
71
|
+
# ==== Options
|
|
72
|
+
# +auto_apply+:: For values, if set, then don't ask for it
|
|
73
|
+
#
|
|
74
|
+
def ask_all(auto_apply = false)
|
|
75
|
+
|
|
76
|
+
options = { :auto_apply => auto_apply }
|
|
77
|
+
|
|
78
|
+
ask("Application name: ", "application", options)
|
|
79
|
+
ask("User (to run application as): ", "user", options.merge({ :default => application }))
|
|
80
|
+
|
|
81
|
+
ask("Deploy to: ", "deploy_to", options.merge({ :default => "/var/www/apps/#{application}" }))
|
|
82
|
+
ask("Web host: ", "web_host", options)
|
|
83
|
+
|
|
84
|
+
ask("Database host: ", "db_host", options.merge({ :default => web_host }))
|
|
85
|
+
ask("Database user: ", "db_user", options.merge({ :default => user }))
|
|
86
|
+
ask("Database password: ", "db_pass", options)
|
|
87
|
+
ask("Database name: ", "db_name", options.merge({ :default => application }))
|
|
88
|
+
|
|
89
|
+
ask("Database port: ", "db_port", options.merge({ :default => 3306, :answer_type => Integer }))
|
|
90
|
+
|
|
91
|
+
ask("Sphinx host: ", "sphinx_host", options.merge({ :default => "127.0.0.1" }))
|
|
92
|
+
ask("Sphinx port: ", "sphinx_port", options.merge({ :default => 3312, :answer_type => Integer }))
|
|
93
|
+
|
|
94
|
+
default_repos = YAML.load(`svn info`)["URL"] rescue nil
|
|
95
|
+
ask("Repository uri: ", "repository", options.merge({ :default => default_repos }))
|
|
96
|
+
|
|
97
|
+
ask("Mongrel starting port: ", "mongrel_port", options.merge({ :answer_type => Integer }))
|
|
98
|
+
ask("Number of mongrels: ", "mongrel_size", options.merge({ :answer_type => Integer }))
|
|
99
|
+
|
|
100
|
+
ask("Domain name (for nginx vhost; no www prefix): ", "domain_name", options)
|
|
101
|
+
|
|
102
|
+
# Load default recipes if not set
|
|
103
|
+
set_default("recipes", YAML.load_file(File.dirname(__FILE__) + "/recipes.yml"))
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
end
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
require 'erb'
|
|
2
|
+
require 'yaml'
|
|
3
|
+
|
|
4
|
+
# Capitate base capistrano plugin
|
|
5
|
+
module Capitate::Plugins::Base
|
|
6
|
+
|
|
7
|
+
# Project root
|
|
8
|
+
def root
|
|
9
|
+
if respond_to?(:fetch)
|
|
10
|
+
return fetch(:project_root)
|
|
11
|
+
else
|
|
12
|
+
RAILS_ROOT
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# Path relative to project root
|
|
17
|
+
def relative_to_root(path = nil, check_exist = false)
|
|
18
|
+
if path
|
|
19
|
+
root_path = File.join(root, path)
|
|
20
|
+
else
|
|
21
|
+
root_path = root
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Check for file existance
|
|
25
|
+
if check_exist and !File.exist?(root_path)
|
|
26
|
+
raise <<-EOS
|
|
27
|
+
|
|
28
|
+
File not found: #{File.expand_path(root_path)}
|
|
29
|
+
|
|
30
|
+
This is loaded for the capitate plugin. View the README in:
|
|
31
|
+
#{File.expand_path(File.dirname(__FILE__) + "/../doc/README")}
|
|
32
|
+
EOS
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
root_path
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Documentation (yaml) for current task (namespace).
|
|
39
|
+
#
|
|
40
|
+
# ==== Examples
|
|
41
|
+
# capitate.current_task_docs => { "task_name" => { "variable" => "The usage docs" } }
|
|
42
|
+
#
|
|
43
|
+
def current_task_doc
|
|
44
|
+
path = File.dirname(__FILE__) + "/../../doc/" + current_task.namespace.fully_qualified_name.to_s.gsub(":", "/") + ".yml"
|
|
45
|
+
puts "Current task doc: #{path}"
|
|
46
|
+
return YAML.load_file(path) if File.exist?(path)
|
|
47
|
+
nil
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Usage for variable from current task documentation.
|
|
51
|
+
#
|
|
52
|
+
# ==== Options
|
|
53
|
+
# +var+:: Variable
|
|
54
|
+
#
|
|
55
|
+
# ==== Examples
|
|
56
|
+
# usage(:gem_list) => "The usage for gem_list variable from the doc/the_namespace.yml file."
|
|
57
|
+
#
|
|
58
|
+
def usage(var)
|
|
59
|
+
task_doc = current_task_doc
|
|
60
|
+
task_name = current_task.name.to_s
|
|
61
|
+
var_name = var.to_s
|
|
62
|
+
if task_doc and task_doc.has_key?(task_name)
|
|
63
|
+
var_usage = task_doc[task_name][var_name]
|
|
64
|
+
return <<-EOS
|
|
65
|
+
|
|
66
|
+
Please set :#{var_name} variable in your Capfile, deploy.rb or profile.
|
|
67
|
+
|
|
68
|
+
Usage:
|
|
69
|
+
|
|
70
|
+
#{indent_doc(var_usage)}
|
|
71
|
+
|
|
72
|
+
EOS
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def indent_doc(s, amount = 8)
|
|
78
|
+
return nil if s.blank?
|
|
79
|
+
indentation = (0..amount).collect { |n| " " }.join
|
|
80
|
+
s.split("\n").collect { |sp| "#{indentation}#{sp}"}.join("\n")
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
Capistrano.plugin :capitate, Capitate::Plugins::Base
|