deprec 0.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. data/bin/deprec +35 -0
  2. data/bin/deprec_dotfiles +6 -0
  3. data/docs/building_edge_capistrano.txt +9 -0
  4. data/lib/deprec/generators/deprec/USAGE +11 -0
  5. data/lib/deprec/generators/deprec/deprec_generator.rb +24 -0
  6. data/lib/deprec/generators/deprec/templates/deploy.rb +71 -0
  7. data/lib/deprec/generators/loader.rb +20 -0
  8. data/lib/deprec/recipes.rb +227 -0
  9. data/lib/deprec/recipes/slicehost.rb +18 -0
  10. data/lib/deprec/recipes/ssh.rb +13 -0
  11. data/lib/deprec/recipes/svn.rb +18 -0
  12. data/lib/deprec/recipes/templates/test_template.rhtml +1 -0
  13. data/lib/deprec/recipes/ubuntu.rb +38 -0
  14. data/lib/deprec/third_party/THIRD_PARTY_README +12 -0
  15. data/lib/deprec/third_party/mongrel_cluster/LICENSE +506 -0
  16. data/lib/deprec/third_party/mongrel_cluster/recipes.rb +95 -0
  17. data/lib/deprec/third_party/mongrel_cluster/resources/mongrel_cluster +41 -0
  18. data/lib/deprec/third_party/railsmachine/LICENSE +506 -0
  19. data/lib/deprec/third_party/railsmachine/recipes/apache.rb +84 -0
  20. data/lib/deprec/third_party/railsmachine/recipes/mysql.rb +58 -0
  21. data/lib/deprec/third_party/railsmachine/recipes/svn.rb +42 -0
  22. data/lib/deprec/third_party/railsmachine/recipes/templates/httpd-ssl.conf +74 -0
  23. data/lib/deprec/third_party/railsmachine/recipes/templates/httpd.conf +63 -0
  24. data/lib/deprec/third_party/vmbuilder/LICENSE +506 -0
  25. data/lib/deprec/third_party/vmbuilder/plugins.rb +8 -0
  26. data/lib/deprec/third_party/vmbuilder/plugins/apt.rb +144 -0
  27. data/lib/deprec/third_party/vmbuilder/plugins/gem.rb +97 -0
  28. data/lib/deprec/third_party/vmbuilder/plugins/std.rb +153 -0
  29. data/resources/capistrano_include_dotfiles.patch +17 -0
  30. metadata +58 -6
  31. data/lib/deprec.rb +0 -9
@@ -0,0 +1,8 @@
1
+ # plugins.rb: Load all the Capistrano Plugins in the plugins directory.
2
+
3
+ require 'rubygems'
4
+
5
+ # Load plugins from the plugins directory
6
+ Dir["#{File.dirname(__FILE__)}/plugins/*.rb"].sort.each do |plugin|
7
+ load plugin
8
+ end
@@ -0,0 +1,144 @@
1
+ # =apt.rb: Debian 'apt' Installer library
2
+ # Capistrano task library to install and manage apt packages
3
+ #
4
+ # ----
5
+ # Copyright (c) 2006 Neil Wilson, Aldur Systems Ltd
6
+ #
7
+ # Licensed under the GNU Public License v2. No warranty is provided.
8
+
9
+ require 'capistrano'
10
+
11
+ # = Purpose
12
+ # Apt is a Capistrano plugin module providing a set of methods
13
+ # that invoke the *apt* package manager (as used in Debian and Ubuntu)
14
+ #
15
+ # Installs within Capistrano as the plugin _apt_.
16
+ #
17
+ # =Usage
18
+ #
19
+ # require 'vmbuilder/plugins/apt'
20
+ #
21
+ # Prefix all calls to the library with <tt>apt.</tt>
22
+ #
23
+ module Apt
24
+
25
+ # Default apt-get command - reduces any interactivity to the minimum.
26
+ APT_GET="DEBCONF_TERSE='yes' DEBIAN_PRIORITY='critical' DEBIAN_FRONTEND=noninteractive apt-get"
27
+
28
+ # Default list of packages required to extract source packages.
29
+ BACKPORT_REQUIRED={:base => %w(dpkg-dev debhelper devscripts fakeroot)}
30
+
31
+ # Directory where any package compilation takes place.
32
+ BUILD_DIR="/var/cache/backport/build"
33
+
34
+ # Run the apt install program across the package list in 'packages'.
35
+ # Select those packages referenced by <tt>:base</tt> and the +version+
36
+ # of the distribution you want to use.
37
+ def install(packages, version, options={})
38
+ special_options="--allow-unauthenticated" if version != :stable
39
+ cmd = <<-CMD
40
+ sh -c "#{APT_GET} -qyu #{special_options.to_s} install #{package_list(packages, version)}"
41
+ CMD
42
+ sudo(cmd, options)
43
+ end
44
+
45
+ # Run an apt autoclean
46
+ def autoclean(options={})
47
+ cmd = <<-CMD
48
+ sh -c "#{APT_GET} -qy autoclean"
49
+ CMD
50
+ sudo(cmd, options)
51
+ end
52
+
53
+ # Run an apt distribution upgrade
54
+ def dist_upgrade(options={})
55
+ cmd = <<-CMD
56
+ sh -c "#{APT_GET} -qy dist-upgrade"
57
+ CMD
58
+ sudo(cmd, options)
59
+ end
60
+
61
+ # Run an apt upgrade. Use dist_upgrade instead if you want to upgrade
62
+ # the critical base packages.
63
+ def upgrade(options={})
64
+ cmd = <<-CMD
65
+ sh -c "#{APT_GET} -qy upgrade"
66
+ CMD
67
+ sudo(cmd, options)
68
+ end
69
+
70
+ # Run an apt update.
71
+ def update(options={})
72
+ cmd = <<-CMD
73
+ sh -c "#{APT_GET} -qy update"
74
+ CMD
75
+ sudo(cmd, options)
76
+ end
77
+
78
+ # Update the apt control files using the files from the machine
79
+ # which is running Capistrano. Set the default version to +version+
80
+ def update_apt(version, myopts={})
81
+ apt_fname="/etc/apt/apt.conf"
82
+ sources_fname="/etc/apt/sources.list"
83
+ pref_fname="/etc/apt/preferences"
84
+ std.su_put("APT::Default-Release \"#{version.to_s}\";\n"+apt_conf, apt_fname, "/tmp", myopts)
85
+ std.su_put(sources, sources_fname, "/tmp", myopts)
86
+ std.su_put(preferences, pref_fname, '/tmp', myopts)
87
+ end
88
+
89
+ # Downloads the specified source module and the quoted dependencies
90
+ # Compiles the module and installs it.
91
+ #
92
+ # If no dependencies are specified, runs an apt build-dep on the stable
93
+ # package list in an attempt to locate them automatically.
94
+ #
95
+ # Alter the <tt>deb-src</tt> line in <tt>sources.list</tt> file to
96
+ # determine which distribution source files are retrieved from.
97
+ def backport_to_stable(packages, dependencies={})
98
+ install(BACKPORT_REQUIRED, :stable)
99
+ if dependencies.empty?
100
+ sudo <<-CMD
101
+ sh -c "#{APT_GET} -qyu build-dep #{package_list(packages, :stable)}"
102
+ CMD
103
+ else
104
+ install(dependencies, :stable)
105
+ end
106
+ patch_gcc
107
+ sudo <<-SUDO
108
+ sh -c "[ -d #{BUILD_DIR} ] || { mkdir -p #{BUILD_DIR} && chown #{user || ENV['USER']} #{BUILD_DIR}; }"
109
+ SUDO
110
+ sudo <<-CMD
111
+ sh -c "cd #{BUILD_DIR} &&
112
+ if [ ! -f `apt-get --print-uris source #{package_list(packages, :stable)}| tail -n1 | cut -d' ' -f2` ]; then
113
+ #{APT_GET} -qyub source #{package_list(packages, :stable)};
114
+ fi;"
115
+ CMD
116
+ sudo "dpkg -i #{BUILD_DIR}/*.deb"
117
+ end
118
+
119
+ # Boot script manipulation command
120
+ def rc_conf(packages, setting)
121
+ packages.each do |service|
122
+ sudo "sysv-rc-conf --level 2 #{service} #{setting}"
123
+ end
124
+ end
125
+
126
+ private
127
+
128
+ # Provides a string containing all the package names in the base
129
+ #list plus those in +version+.
130
+ def package_list(packages, version)
131
+ packages[:base].to_a.join(' ') + ' ' + packages[version].to_a.join(' ')
132
+ end
133
+
134
+ # Stable likes to use gcc3.3. Force it to use 3.4 if it is installed.
135
+ def patch_gcc
136
+ sudo <<-CMD
137
+ sh -c "[ ! -f /usr/bin/gcc-3.4 ] || ln -sf /usr/bin/gcc-3.4 /usr/local/bin/gcc"
138
+ CMD
139
+ end
140
+
141
+ end
142
+
143
+ Capistrano.plugin :apt, Apt
144
+ # vim: nowrap sw=2 sts=2 ts=8 ff=unix ft=ruby:
@@ -0,0 +1,97 @@
1
+ # =gem.rb: Gem Installer library
2
+ # Capistrano library to install and manage Ruby Gems.
3
+ #
4
+ # ----
5
+ # Copyright (c) 2006 Neil Wilson, Aldur Systems Ltd
6
+ #
7
+ # Licensed under the GNU Public License v2. No warranty is provided.
8
+
9
+ require 'capistrano'
10
+
11
+ # = Purpose
12
+ # Gem is a Capistrano plugin module providing a set of methods
13
+ # that invoke the *gem* package manager.
14
+ #
15
+ # Installs within Capistrano as the plugin _gem_.
16
+ #
17
+ # =Usage
18
+ #
19
+ # require 'vmbuilder/plugins/gem'
20
+ #
21
+ # Prefix all calls to the library with <tt>gem.</tt>
22
+ #
23
+ module Gem
24
+
25
+ # Default install command
26
+ #
27
+ # * doesn't install documentation
28
+ # * installs all required dependencies automatically.
29
+ #
30
+ GEM_INSTALL="gem install -y --no-rdoc --no-ri"
31
+
32
+ # Upgrade the *gem* system to the latest version. Runs via *sudo*
33
+ def update_system
34
+ sudo "gem update --system"
35
+ end
36
+
37
+ # Updates all the installed gems to the latest version. Runs via *sudo*.
38
+ # Don't use this command if any of the gems require a version selection.
39
+ def upgrade
40
+ sudo "gem update --no-rdoc"
41
+ end
42
+
43
+ # Removes old versions of gems from installation area.
44
+ def cleanup
45
+ sudo "gem cleanup"
46
+ end
47
+
48
+ # Installs the gems detailed in +packages+, selecting version +version+ if
49
+ # specified.
50
+ #
51
+ # +packages+ can be a single string or an array of strings.
52
+ #
53
+ def install(packages, version=nil)
54
+ sudo "#{GEM_INSTALL} #{if version then '-v '+version.to_s end} #{packages.to_a.join(' ')}"
55
+ end
56
+
57
+ # Auto selects a gem from a list and installs it.
58
+ #
59
+ # *gem* has no mechanism on the command line of disambiguating builds for
60
+ # different platforms, and instead asks the user. This method has the necessary
61
+ # conversation to select the +version+ relevant to +platform+ (or the one nearest
62
+ # the top of the list if you don't specify +version+).
63
+ def select(package, version=nil, platform='ruby')
64
+ selections={}
65
+ cmd="#{GEM_INSTALL} #{if version then '-v '+version.to_s end} #{package}"
66
+ sudo cmd do |channel, stream, data|
67
+ data.each_line do | line |
68
+ case line
69
+ when /\s(\d+).*\(#{platform}\)/
70
+ if selections[channel[:host]].nil?
71
+ selections[channel[:host]]=$1.dup+"\n"
72
+ logger.info "Selecting #$&", "#{stream} :: #{channel[:host]}"
73
+ end
74
+ when /\s\d+\./
75
+ # Discard other selections from data stream
76
+ when /^>/
77
+ channel.send_data selections[channel[:host]]
78
+ logger.debug line, "#{stream} :: #{channel[:host]}"
79
+ else
80
+ logger.info line, "#{stream} :: #{channel[:host]}"
81
+ end
82
+ end
83
+ end
84
+ end
85
+
86
+ #def gem_select(package, version, platform='ruby')
87
+ # sudo <<-CMD
88
+ # sh -c "#{GEM_INSTALL} -v #{version} #{package} </dev/null 2>&1|
89
+ # sed -ne '/(#{platform})/s/ \\([0-9][0-9]*\\).*/\\1/p' |
90
+ # #{GEM_INSTALL} -v #{version} #{package}"
91
+ # CMD
92
+ # end
93
+
94
+ end
95
+
96
+ Capistrano.plugin :gem, Gem
97
+ # vim: nowrap sw=2 sts=2 ts=8 ff=unix ft=ruby:
@@ -0,0 +1,153 @@
1
+ # =std.rb: Capistrano Standard Methods
2
+ # Standard library of procedures and functions that you can use with Capistrano.
3
+ #
4
+ # ----
5
+ # Copyright (c) 2006 Neil Wilson, Aldur Systems Ltd
6
+ #
7
+ # Licensed under the GNU Public License v2. No warranty is provided.
8
+
9
+ require 'capistrano'
10
+
11
+ # = Purpose
12
+ # Std is a Capistrano plugin that provides a set of standard methods refactored
13
+ # out of several Capistrano task libraries.
14
+ #
15
+ # Installs within Capistrano as the plugin _std_
16
+ #
17
+ # = Usage
18
+ #
19
+ # require 'vmbuilder/plugins/std'
20
+ #
21
+ # Prefix all calls to the library with <tt>std.</tt>
22
+ module Std
23
+
24
+ begin
25
+ # Use the Mmap class if it is available
26
+ # http://moulon.inra.fr/ruby/mmap.html
27
+ require 'mmap'
28
+ MMAP=true #:nodoc:
29
+ rescue LoadError
30
+ # no MMAP class, use normal reads instead
31
+ MMAP=false #:nodoc:
32
+ end
33
+
34
+ # Copies the files specified by +file_pattern+ to +destination+
35
+ #
36
+ # Error checking is minimal - a pattern onto a single file will result in +destination+
37
+ # containing the data from the last file only.
38
+ #
39
+ # Installs via *sudo*, +options+ are as for *put*.
40
+ def fput(file_pattern, destination, options={})
41
+ logger.info file_pattern
42
+ Dir.glob(file_pattern) do |fname|
43
+ logger.info fname
44
+ if File.readable?(fname) then
45
+ if MMAP
46
+ logger.debug "Using Memory Mapped File Upload"
47
+ fdata=Mmap.new(fname,"r", Mmap::MAP_SHARED, :advice => Mmap::MADV_SEQUENTIAL)
48
+ else
49
+ fdata=File.open(fname).read
50
+ end
51
+ su_put(fdata, destination, File.join('/tmp',File.basename(fname)), options)
52
+ end
53
+ end
54
+ end
55
+
56
+ # Upload +data+ to +temporary_area+ before installing it in
57
+ # +destination+ using sudo.
58
+ #
59
+ # +options+ are as for *put*
60
+ #
61
+ def su_put(data, destination, temporary_area='/tmp', options={})
62
+ temporary_area = File.join(temporary_area,File.basename(destination)) if File.directory?(temporary_area)
63
+ put(data, temporary_area, options)
64
+ sudo <<-CMD
65
+ sh -c "install -m#{sprintf("%3o",options[:mode]||0755)} #{temporary_area} #{destination} &&
66
+ rm -f #{temporary_area}"
67
+ CMD
68
+ end
69
+
70
+ # Copies the +file_pattern+, which is assumed to be a tar
71
+ # file of some description (gzipped or plain), and unpacks it into
72
+ # +destination+.
73
+ def unzip(file_pattern, destination, options={})
74
+ Dir.glob(file_pattern) do |fname|
75
+ if File.readable?(fname) then
76
+ target="/tmp/#{File.basename(fname)}"
77
+ if MMAP
78
+ logger.debug "Using Memory Mapped File Upload"
79
+ fdata=Mmap.new(fname,"r", Mmap::MAP_SHARED, :advice => Mmap::MADV_SEQUENTIAL)
80
+ else
81
+ fdata=File.open(fname).read
82
+ end
83
+ put(fdata, target, options)
84
+ sudo <<-CMD
85
+ sh -c "cd #{destination} &&
86
+ zcat -f #{target} | tar xvf - &&
87
+ rm -f #{target}"
88
+ CMD
89
+ end
90
+ end
91
+ end
92
+
93
+ # Creates the directory +web_root_dir+ using sudo is +use_sudo+ is true.
94
+ #
95
+ # Makes the root directory manageble by the +control_group+ group and sets the
96
+ # permissions so that the directory is writeable by +control_group+ and the group
97
+ # remains _sticky_
98
+ #
99
+ def create_web_root(web_root_dir, control_group)
100
+ send run_method, <<-CMD
101
+ sh -c "[ -d #{web_root_dir} ] || mkdir -m2770 -p #{web_root_dir}"
102
+ CMD
103
+ send(run_method, "chgrp -c #{control_group} #{web_root_dir}")
104
+ end
105
+
106
+ # Wrap this around your task calls to catch the no servers error and
107
+ # ignore it
108
+ #
109
+ # std.ignore_no_servers_error do
110
+ # activate_mysql
111
+ # end
112
+ #
113
+ def ignore_no_servers_error (&block)
114
+ begin
115
+ yield
116
+ rescue RuntimeError => failure
117
+ if failure.message =~ /no servers matched/
118
+ logger.debug "Ignoring 'no servers matched' error in task #{current_task.name}"
119
+ else
120
+ raise
121
+ end
122
+ end
123
+ end
124
+
125
+ # Wrap this around your task to force a connection as root.
126
+ #
127
+ # std.connect_as_root do
128
+ # install_sudo
129
+ # end
130
+ #
131
+ def connect_as_root (&block)
132
+ begin
133
+ tempuser = user
134
+ set :user, "root"
135
+ yield tempuser
136
+ ensure
137
+ set :user, tempuser if tempuser
138
+ end
139
+ end
140
+
141
+ #Returns a random string of alphanumeric characters of size +size+
142
+ #Useful for passwords, usernames and the like.
143
+ def random_string(size=10)
144
+ s = ""
145
+ size.times { s << (i = rand(62); i += ((i < 10) ? 48 : ((i < 36) ? 55 : 61 ))).chr }
146
+ s
147
+ end
148
+
149
+ end
150
+
151
+ Capistrano.plugin :std, Std
152
+ #
153
+ # vim: nowrap sw=2 sts=2 ts=8 ff=unix ft=ruby:
@@ -0,0 +1,17 @@
1
+ Index: lib/capistrano/cli.rb
2
+ ===================================================================
3
+ --- lib/capistrano/cli.rb (revision 5636)
4
+ +++ lib/capistrano/cli.rb (working copy)
5
+ @@ -289,6 +289,12 @@
6
+ end
7
+
8
+ def look_for_default_recipe_file!
9
+ + if File.exist?(system_defaults = '/etc/capistrano.conf')
10
+ + @options[:recipes] << system_defaults
11
+ + end
12
+ + if File.exist?(user_defaults = File.join(ENV['HOME'],'.caprc'))
13
+ + @options[:recipes] << user_defaults
14
+ + end
15
+ DEFAULT_RECIPES.each do |file|
16
+ if File.exist?(file)
17
+ @options[:recipes] << file
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: deprec
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.0.1
7
- date: 2006-11-16 00:00:00 +11:00
6
+ version: 1.1.0
7
+ date: 2006-11-30 00:00:00 +11:00
8
8
  summary: deployment recipes for capistrano
9
9
  require_paths:
10
10
  - lib
@@ -13,7 +13,7 @@ homepage:
13
13
  rubyforge_project:
14
14
  description: This project provides libraries of Capistrano tasks and extensions to remove the repetative manual work associated with installing services on linux servers.
15
15
  autorequire:
16
- default_executable:
16
+ default_executable: deprec
17
17
  bindir: bin
18
18
  has_rdoc: false
19
19
  required_ruby_version: !ruby/object:Gem::Version::Requirement
@@ -28,15 +28,58 @@ cert_chain:
28
28
  authors: []
29
29
 
30
30
  files:
31
- - lib/deprec.rb
31
+ - bin/deprec
32
+ - bin/deprec_dotfiles
33
+ - docs/building_edge_capistrano.txt
34
+ - lib/deprec
35
+ - lib/deprec/generators
36
+ - lib/deprec/recipes
37
+ - lib/deprec/recipes.rb
38
+ - lib/deprec/third_party
39
+ - lib/deprec/generators/deprec
40
+ - lib/deprec/generators/loader.rb
41
+ - lib/deprec/generators/deprec/deprec_generator.rb
42
+ - lib/deprec/generators/deprec/templates
43
+ - lib/deprec/generators/deprec/USAGE
44
+ - lib/deprec/generators/deprec/templates/deploy.rb
45
+ - lib/deprec/recipes/slicehost.rb
46
+ - lib/deprec/recipes/ssh.rb
47
+ - lib/deprec/recipes/svn.rb
48
+ - lib/deprec/recipes/templates
49
+ - lib/deprec/recipes/ubuntu.rb
50
+ - lib/deprec/recipes/templates/test_template.rhtml
51
+ - lib/deprec/third_party/mongrel_cluster
52
+ - lib/deprec/third_party/railsmachine
53
+ - lib/deprec/third_party/THIRD_PARTY_README
54
+ - lib/deprec/third_party/vmbuilder
55
+ - lib/deprec/third_party/mongrel_cluster/LICENSE
56
+ - lib/deprec/third_party/mongrel_cluster/recipes.rb
57
+ - lib/deprec/third_party/mongrel_cluster/resources
58
+ - lib/deprec/third_party/mongrel_cluster/resources/mongrel_cluster
59
+ - lib/deprec/third_party/railsmachine/LICENSE
60
+ - lib/deprec/third_party/railsmachine/recipes
61
+ - lib/deprec/third_party/railsmachine/recipes/apache.rb
62
+ - lib/deprec/third_party/railsmachine/recipes/mysql.rb
63
+ - lib/deprec/third_party/railsmachine/recipes/svn.rb
64
+ - lib/deprec/third_party/railsmachine/recipes/templates
65
+ - lib/deprec/third_party/railsmachine/recipes/templates/httpd-ssl.conf
66
+ - lib/deprec/third_party/railsmachine/recipes/templates/httpd.conf
67
+ - lib/deprec/third_party/vmbuilder/LICENSE
68
+ - lib/deprec/third_party/vmbuilder/plugins
69
+ - lib/deprec/third_party/vmbuilder/plugins.rb
70
+ - lib/deprec/third_party/vmbuilder/plugins/apt.rb
71
+ - lib/deprec/third_party/vmbuilder/plugins/gem.rb
72
+ - lib/deprec/third_party/vmbuilder/plugins/std.rb
73
+ - resources/capistrano_include_dotfiles.patch
32
74
  test_files: []
33
75
 
34
76
  rdoc_options: []
35
77
 
36
78
  extra_rdoc_files: []
37
79
 
38
- executables: []
39
-
80
+ executables:
81
+ - deprec
82
+ - deprec_dotfiles
40
83
  extensions: []
41
84
 
42
85
  requirements: []
@@ -51,3 +94,12 @@ dependencies:
51
94
  - !ruby/object:Gem::Version
52
95
  version: 1.2.0
53
96
  version:
97
+ - !ruby/object:Gem::Dependency
98
+ name: termios
99
+ version_requirement:
100
+ version_requirements: !ruby/object:Gem::Version::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: 0.9.4
105
+ version: