deprec 2.2.3 → 3.1.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (209) hide show
  1. data/CHANGELOG +1 -1
  2. data/bin/depify +3 -8
  3. data/{lib → docs}/deprec_cmd_completion.sh +0 -0
  4. data/lib/deprec.rb +5 -7
  5. data/lib/deprec/cap.rb +51 -0
  6. data/lib/deprec/{callbacks → cap/callbacks}/asset_pipeline.rb +0 -0
  7. data/lib/deprec/{recipes → cap/recipes}/aoe.rb +0 -0
  8. data/lib/deprec/{recipes → cap/recipes}/apache.rb +0 -0
  9. data/lib/deprec/{recipes → cap/recipes}/bash.rb +0 -0
  10. data/lib/deprec/{recipes → cap/recipes}/canonical.rb +0 -0
  11. data/lib/deprec/{recipes → cap/recipes}/collectd.rb +0 -0
  12. data/lib/deprec/{recipes → cap/recipes}/deprec.rb +1 -2
  13. data/lib/deprec/{recipes → cap/recipes}/deprecated.rb +0 -0
  14. data/lib/deprec/{recipes → cap/recipes}/ec2.rb +0 -0
  15. data/lib/deprec/{recipes → cap/recipes}/example.rb +0 -0
  16. data/lib/deprec/{recipes → cap/recipes}/git.rb +0 -0
  17. data/lib/deprec/{recipes → cap/recipes}/haproxy.rb +0 -0
  18. data/lib/deprec/{recipes → cap/recipes}/heartbeat.rb +0 -0
  19. data/lib/deprec/{recipes → cap/recipes}/logrotate.rb +0 -0
  20. data/lib/deprec/{recipes → cap/recipes}/lvm.rb +0 -0
  21. data/lib/deprec/{recipes → cap/recipes}/mongrel.rb +0 -0
  22. data/lib/deprec/{recipes → cap/recipes}/monit.rb +0 -0
  23. data/lib/deprec/{recipes → cap/recipes}/mri.rb +0 -0
  24. data/lib/deprec/{recipes → cap/recipes}/mysql.rb +0 -0
  25. data/lib/deprec/{recipes → cap/recipes}/nagios.rb +0 -0
  26. data/lib/deprec/{recipes → cap/recipes}/nagios3.rb +0 -0
  27. data/lib/deprec/{recipes → cap/recipes}/network.rb +0 -0
  28. data/lib/deprec/{recipes → cap/recipes}/nginx.rb +0 -0
  29. data/lib/deprec/{recipes → cap/recipes}/nrpe.rb +0 -0
  30. data/lib/deprec/{recipes → cap/recipes}/ntp.rb +0 -0
  31. data/lib/deprec/{recipes → cap/recipes}/passenger.rb +0 -0
  32. data/lib/deprec/{recipes → cap/recipes}/php.rb +0 -0
  33. data/lib/deprec/{recipes → cap/recipes}/postfix.rb +0 -0
  34. data/lib/deprec/{recipes → cap/recipes}/postgresql.rb +0 -0
  35. data/lib/deprec/{recipes → cap/recipes}/rack.rb +0 -0
  36. data/lib/deprec/{recipes → cap/recipes}/rails.rb +4 -4
  37. data/lib/deprec/{recipes → cap/recipes}/ree.rb +0 -0
  38. data/lib/deprec/{recipes → cap/recipes}/rubygems.rb +0 -0
  39. data/lib/deprec/{recipes → cap/recipes}/sqlite.rb +0 -0
  40. data/lib/deprec/{recipes → cap/recipes}/ssh.rb +0 -0
  41. data/lib/deprec/{recipes → cap/recipes}/ssl.rb +0 -0
  42. data/lib/deprec/{recipes → cap/recipes}/stunnel.rb +0 -0
  43. data/lib/deprec/{recipes → cap/recipes}/syslog.rb +0 -0
  44. data/lib/deprec/{recipes → cap/recipes}/syslog_ng.rb +0 -0
  45. data/lib/deprec/{recipes → cap/recipes}/ubuntu.rb +0 -0
  46. data/lib/deprec/{recipes → cap/recipes}/users.rb +0 -0
  47. data/lib/deprec/{recipes → cap/recipes}/utils.rb +0 -0
  48. data/lib/deprec/{recipes → cap/recipes}/xen.rb +0 -0
  49. data/lib/deprec/{recipes → cap/recipes}/xentools.rb +0 -0
  50. data/lib/deprec/{templates → cap/templates}/aoe/aoe-init +0 -0
  51. data/lib/deprec/{templates → cap/templates}/aoe/fence_aoemask +0 -0
  52. data/lib/deprec/{templates → cap/templates}/apache/CHANGES.txt +0 -0
  53. data/lib/deprec/{templates → cap/templates}/apache/apache2.conf.erb +0 -0
  54. data/lib/deprec/{templates → cap/templates}/apache/default.erb +0 -0
  55. data/lib/deprec/{templates → cap/templates}/apache/namevirtualhosts.conf +0 -0
  56. data/lib/deprec/{templates → cap/templates}/apache/ports.conf.erb +0 -0
  57. data/lib/deprec/{templates → cap/templates}/apache/status.conf.erb +0 -0
  58. data/lib/deprec/{templates → cap/templates}/apache/vhost.erb +0 -0
  59. data/lib/deprec/{templates → cap/templates}/bash/bash_global +0 -0
  60. data/lib/deprec/{templates → cap/templates}/collectd/collectd-init.d +0 -0
  61. data/lib/deprec/{templates → cap/templates}/collectd/collectd.conf.erb +0 -0
  62. data/lib/deprec/{templates → cap/templates}/deprec/caprc.erb +0 -0
  63. data/lib/deprec/{templates → cap/templates}/haproxy/haproxy-init.d +0 -0
  64. data/lib/deprec/{templates → cap/templates}/haproxy/haproxy.cfg.erb +0 -0
  65. data/lib/deprec/{templates → cap/templates}/heartbeat/authkeys.erb +0 -0
  66. data/lib/deprec/{templates → cap/templates}/heartbeat/ha.cf.erb +0 -0
  67. data/lib/deprec/{templates → cap/templates}/heartbeat/haresources.erb +0 -0
  68. data/lib/deprec/{templates → cap/templates}/logrotate/logrotate.conf.erb +0 -0
  69. data/lib/deprec/{templates → cap/templates}/mongrel/apache_vhost.conf.erb +0 -0
  70. data/lib/deprec/{templates → cap/templates}/mongrel/logrotate.conf.erb +0 -0
  71. data/lib/deprec/{templates → cap/templates}/mongrel/mongrel_cluster-init-script +0 -0
  72. data/lib/deprec/{templates → cap/templates}/mongrel/mongrel_cluster.yml.erb +0 -0
  73. data/lib/deprec/{templates → cap/templates}/mongrel/monit.conf.erb +0 -0
  74. data/lib/deprec/{templates → cap/templates}/mongrel/nginx_vhost.conf.erb +0 -0
  75. data/lib/deprec/{templates → cap/templates}/monit/monit-init-script +0 -0
  76. data/lib/deprec/{templates → cap/templates}/monit/monitrc.erb +0 -0
  77. data/lib/deprec/{templates → cap/templates}/monit/nothing.monitrc +0 -0
  78. data/lib/deprec/{templates → cap/templates}/mysql/create_databases.sql +0 -0
  79. data/lib/deprec/{templates → cap/templates}/mysql/database.yml.prod +0 -0
  80. data/lib/deprec/{templates → cap/templates}/mysql/database.yml.stage +0 -0
  81. data/lib/deprec/{templates → cap/templates}/mysql/my.cnf.erb +0 -0
  82. data/lib/deprec/{templates → cap/templates}/mysql/sphinx.conf.prod +0 -0
  83. data/lib/deprec/{templates → cap/templates}/mysql/sphinx.conf.stage +0 -0
  84. data/lib/deprec/{templates → cap/templates}/nagios.old/README +0 -0
  85. data/lib/deprec/{templates → cap/templates}/nagios.old/apache_vhost.erb +0 -0
  86. data/lib/deprec/{templates → cap/templates}/nagios.old/cgi.cfg.erb +0 -0
  87. data/lib/deprec/{templates → cap/templates}/nagios.old/check_linux_free_memory.pl +0 -0
  88. data/lib/deprec/{templates → cap/templates}/nagios.old/check_mongrel_cluster.rb +0 -0
  89. data/lib/deprec/{templates → cap/templates}/nagios.old/htpasswd.users +0 -0
  90. data/lib/deprec/{templates → cap/templates}/nagios.old/mrtg.cfg +0 -0
  91. data/lib/deprec/{templates → cap/templates}/nagios.old/nagios.cfg.erb +0 -0
  92. data/lib/deprec/{templates → cap/templates}/nagios.old/nrpe.cfg.erb +0 -0
  93. data/lib/deprec/{templates → cap/templates}/nagios.old/nrpe.xinetd.erb +0 -0
  94. data/lib/deprec/{templates → cap/templates}/nagios.old/objects/commands.cfg.erb +0 -0
  95. data/lib/deprec/{templates → cap/templates}/nagios.old/objects/contacts.cfg.erb +0 -0
  96. data/lib/deprec/{templates → cap/templates}/nagios.old/objects/hosts.cfg.erb +0 -0
  97. data/lib/deprec/{templates → cap/templates}/nagios.old/objects/localhost.cfg.erb +0 -0
  98. data/lib/deprec/{templates → cap/templates}/nagios.old/objects/services.cfg.erb +0 -0
  99. data/lib/deprec/{templates → cap/templates}/nagios.old/objects/timeperiods.cfg.erb +0 -0
  100. data/lib/deprec/{templates → cap/templates}/nagios.old/resource.cfg.erb +0 -0
  101. data/lib/deprec/{templates → cap/templates}/nagios/apache2.conf +0 -0
  102. data/lib/deprec/{templates → cap/templates}/nagios/cgi.cfg +0 -0
  103. data/lib/deprec/{templates → cap/templates}/nagios/check_linux_free_memory.pl +0 -0
  104. data/lib/deprec/{templates → cap/templates}/nagios/commands.cfg +0 -0
  105. data/lib/deprec/{templates → cap/templates}/nagios/conf.d/contacts_nagios2.cfg +0 -0
  106. data/lib/deprec/{templates → cap/templates}/nagios/conf.d/extinfo_nagios2.cfg +0 -0
  107. data/lib/deprec/{templates → cap/templates}/nagios/conf.d/generic-host_nagios2.cfg +0 -0
  108. data/lib/deprec/{templates → cap/templates}/nagios/conf.d/generic-service_nagios2.cfg +0 -0
  109. data/lib/deprec/{templates → cap/templates}/nagios/conf.d/hostgroups_nagios2.cfg +0 -0
  110. data/lib/deprec/{templates → cap/templates}/nagios/conf.d/hosts/localhost_nagios2.cfg +0 -0
  111. data/lib/deprec/{templates → cap/templates}/nagios/conf.d/services_nagios2.cfg +0 -0
  112. data/lib/deprec/{templates → cap/templates}/nagios/conf.d/timeperiods_nagios2.cfg +0 -0
  113. data/lib/deprec/{templates → cap/templates}/nagios/host_template.erb +0 -0
  114. data/lib/deprec/{templates → cap/templates}/nagios/htpasswd.users +0 -0
  115. data/lib/deprec/{templates → cap/templates}/nagios/nagios.cfg +0 -0
  116. data/lib/deprec/{templates → cap/templates}/nagios/nrpe.cfg +0 -0
  117. data/lib/deprec/{templates → cap/templates}/nagios/resource.cfg +0 -0
  118. data/lib/deprec/{templates → cap/templates}/network/hostname.erb +0 -0
  119. data/lib/deprec/{templates → cap/templates}/network/hosts.erb +0 -0
  120. data/lib/deprec/{templates → cap/templates}/network/interfaces.erb +0 -0
  121. data/lib/deprec/{templates → cap/templates}/network/resolv.conf.erb +0 -0
  122. data/lib/deprec/{templates → cap/templates}/nginx/logrotate.conf.erb +0 -0
  123. data/lib/deprec/{templates → cap/templates}/nginx/mime.types.erb +0 -0
  124. data/lib/deprec/{templates → cap/templates}/nginx/nginx-init-script +0 -0
  125. data/lib/deprec/{templates → cap/templates}/nginx/nginx.conf.erb +0 -0
  126. data/lib/deprec/{templates → cap/templates}/nginx/nginx.logrotate.d +0 -0
  127. data/lib/deprec/{templates → cap/templates}/nginx/nothing.conf +0 -0
  128. data/lib/deprec/{templates → cap/templates}/nginx/rails_nginx_vhost.conf.erb +0 -0
  129. data/lib/deprec/{templates → cap/templates}/ntp/ntp.conf.erb +0 -0
  130. data/lib/deprec/{templates → cap/templates}/passenger/apache_vhost.erb +0 -0
  131. data/lib/deprec/{templates → cap/templates}/passenger/logrotate.conf.erb +0 -0
  132. data/lib/deprec/{templates → cap/templates}/passenger/passenger.conf.erb +0 -0
  133. data/lib/deprec/{templates → cap/templates}/passenger/passenger.load.erb +0 -0
  134. data/lib/deprec/{templates → cap/templates}/postfix/aliases.erb +0 -0
  135. data/lib/deprec/{templates → cap/templates}/postfix/dynamicmaps.cf.erb +0 -0
  136. data/lib/deprec/{templates → cap/templates}/postfix/main.cf.erb +0 -0
  137. data/lib/deprec/{templates → cap/templates}/postfix/master.cf.erb +0 -0
  138. data/lib/deprec/{templates → cap/templates}/ssh/ssh_config.erb +0 -0
  139. data/lib/deprec/{templates → cap/templates}/ssh/sshd_config.erb +0 -0
  140. data/lib/deprec/{templates → cap/templates}/ssl/make-ssl-cert +0 -0
  141. data/lib/deprec/{templates → cap/templates}/ssl/ssl-cert-snakeoil.key +0 -0
  142. data/lib/deprec/{templates → cap/templates}/ssl/ssl-cert-snakeoil.pem +0 -0
  143. data/lib/deprec/{templates → cap/templates}/stunnel/stunnel.conf-client +0 -0
  144. data/lib/deprec/{templates → cap/templates}/stunnel/stunnel.conf-orig +0 -0
  145. data/lib/deprec/{templates → cap/templates}/stunnel/stunnel.conf-server +0 -0
  146. data/lib/deprec/{templates → cap/templates}/stunnel/stunnel4 +0 -0
  147. data/lib/deprec/{templates → cap/templates}/stunnel/syslog-server.pem +0 -0
  148. data/lib/deprec/{templates → cap/templates}/syslog/syslog.conf.erb +0 -0
  149. data/lib/deprec/{templates → cap/templates}/syslog/syslogd.erb +0 -0
  150. data/lib/deprec/{templates → cap/templates}/syslog_ng/apache_syslog +0 -0
  151. data/lib/deprec/{templates → cap/templates}/syslog_ng/syslog-ng.conf-client +0 -0
  152. data/lib/deprec/{templates → cap/templates}/syslog_ng/syslog-ng.conf-orig +0 -0
  153. data/lib/deprec/{templates → cap/templates}/syslog_ng/syslog-ng.conf-server +0 -0
  154. data/lib/deprec/{templates → cap/templates}/xen/network-bridge-wrapper +0 -0
  155. data/lib/deprec/{templates → cap/templates}/xen/xend-config.sxp.erb +0 -0
  156. data/lib/deprec/{templates → cap/templates}/xen/xend-init.erb +0 -0
  157. data/lib/deprec/{templates → cap/templates}/xen/xendomains.erb +0 -0
  158. data/lib/deprec/{templates → cap/templates}/xentools/15-disable-hwclock +0 -0
  159. data/lib/deprec/{templates → cap/templates}/xentools/40-setup-networking +0 -0
  160. data/lib/deprec/{templates → cap/templates}/xentools/xen-tools.conf.erb +0 -0
  161. data/lib/deprec/{templates → cap/templates}/xentools/xm.tmpl.erb +0 -0
  162. data/lib/deprec_minus_rails.rb +22 -12
  163. metadata +178 -212
  164. data/lib/deprec/TODO.txt +0 -6
  165. data/lib/deprec/capistrano_extensions.rb +0 -418
  166. data/lib/deprec/recipes.rb +0 -7
  167. data/lib/deprec/recipes/ar_sendmail.rb +0 -67
  168. data/lib/deprec/recipes/chef.rb +0 -68
  169. data/lib/deprec/recipes/couchdb.rb +0 -107
  170. data/lib/deprec/recipes/ddclient.rb +0 -51
  171. data/lib/deprec/recipes/gitosis.rb +0 -55
  172. data/lib/deprec/recipes/integrity.rb +0 -108
  173. data/lib/deprec/recipes/memcache.rb +0 -49
  174. data/lib/deprec/recipes/sphinx.rb +0 -86
  175. data/lib/deprec/recipes/starling.rb +0 -119
  176. data/lib/deprec/recipes/svn.rb +0 -12
  177. data/lib/deprec/recipes/trac.rb +0 -277
  178. data/lib/deprec/recipes/vmware_tools.rb +0 -15
  179. data/lib/deprec/recipes/vnstat.rb +0 -85
  180. data/lib/deprec/recipes/wpmu.rb +0 -103
  181. data/lib/deprec/recipes_minus_rails.rb +0 -69
  182. data/lib/deprec/templates/ar_sendmail/logrotate.conf.erb +0 -9
  183. data/lib/deprec/templates/ar_sendmail/monit.conf.erb +0 -5
  184. data/lib/deprec/templates/chef/chef.json.erb +0 -1
  185. data/lib/deprec/templates/chef/solo.rb +0 -2
  186. data/lib/deprec/templates/ddclient/ddclient.conf.erb +0 -11
  187. data/lib/deprec/templates/ddclient/ddclient.erb +0 -15
  188. data/lib/deprec/templates/integrity/apache_vhost.erb +0 -4
  189. data/lib/deprec/templates/integrity/config.ru.erb +0 -21
  190. data/lib/deprec/templates/integrity/config.yml.erb +0 -43
  191. data/lib/deprec/templates/sphinx/monit.conf.erb +0 -5
  192. data/lib/deprec/templates/starling/monit.conf.erb +0 -14
  193. data/lib/deprec/templates/starling/starling-init-script.erb +0 -71
  194. data/lib/deprec/templates/subversion/svn.apache.vhost.erb +0 -43
  195. data/lib/deprec/templates/trac/apache_vhost.conf.erb +0 -24
  196. data/lib/deprec/templates/trac/nginx_vhost.conf.erb +0 -26
  197. data/lib/deprec/templates/trac/trac.ini.erb +0 -169
  198. data/lib/deprec/templates/trac/trac_deprec.png +0 -0
  199. data/lib/deprec/templates/trac/tracd-init.erb +0 -43
  200. data/lib/deprec/templates/trac/users.htdigest.erb +0 -0
  201. data/lib/deprec/templates/vnstat/config.php +0 -57
  202. data/lib/deprec/templates/wordpress/apache2_wordpress_vhost.conf.erb +0 -31
  203. data/lib/deprec/templates/wordpress/wp-config.php.erb +0 -31
  204. data/lib/deprec/templates/wpmu/apache_vhost.conf.erb +0 -13
  205. data/lib/vmbuilder_plugins/all.rb +0 -20
  206. data/lib/vmbuilder_plugins/apt.rb +0 -93
  207. data/lib/vmbuilder_plugins/emerge.rb +0 -76
  208. data/lib/vmbuilder_plugins/gem.rb +0 -90
  209. data/lib/vmbuilder_plugins/std.rb +0 -203
data/lib/deprec/TODO.txt DELETED
@@ -1,6 +0,0 @@
1
-
2
- # Add option to symlink apache vhosts
3
- #
4
- # This will make updating with deploys easier
5
- #
6
- ln -sf /srv/brandish/current/config/uat/passenger/apache_vhost brandish
@@ -1,418 +0,0 @@
1
- # Copyright 2006-2008 by Mike Bailey. All rights reserved.
2
- require 'capistrano'
3
- require 'fileutils'
4
-
5
- module Deprec2
6
-
7
- # Temporarily modify ROLES if HOSTS not set
8
- # Capistrano's default behaviour is for HOSTS to override ROLES
9
- def for_roles(roles)
10
- old_roles = ENV['ROLES']
11
- ENV['ROLES'] = roles.to_s unless ENV['HOSTS']
12
- yield
13
- ENV['ROLES'] = old_roles.to_s unless ENV['HOSTS']
14
- end
15
-
16
-
17
- # Temporarily ignore ROLES and HOSTS
18
- def ignoring_roles_and_hosts
19
- old_roles = ENV['ROLES']
20
- old_hosts = ENV['HOSTS']
21
- ENV['ROLES'] = nil
22
- ENV['HOSTS'] = nil
23
- yield
24
- ENV['ROLES'] = old_roles
25
- ENV['HOSTS'] = old_hosts
26
- end
27
-
28
- DEPREC_TEMPLATES_BASE = File.join(File.dirname(__FILE__), 'templates')
29
-
30
- # Render template (usually a config file)
31
- #
32
- # Usually we render it to a file on the local filesystem.
33
- # This way, we keep a copy of the config file under source control.
34
- # We can make manual changes if required and push to new hosts.
35
- #
36
- # If the options hash contains :path then it's written to that path.
37
- # If it contains :remote => true, the file will instead be written to remote targets
38
- # If options[:path] and options[:remote] are missing, it just returns the rendered
39
- # template as a string (good for debugging).
40
- #
41
- # XXX I would like to get rid of :render_template_to_file
42
- # XXX Perhaps pass an option to this function to write to remote
43
- #
44
- def render_template(app, options={})
45
- template = options[:template]
46
- path = options[:path] || nil
47
- remote = options[:remote] || false
48
- mode = options[:mode] || 0755
49
- owner = options[:owner] || nil
50
- stage = exists?(:stage) ? fetch(:stage).to_s : ''
51
- # replace this with a check for the file
52
- if ! template
53
- puts "render_template() requires a value for the template!"
54
- return false
55
- end
56
-
57
- # If local copies of deprec templates exist they will be used
58
- # If you don't specify the location with the local_template_dir option
59
- # it defaults to config/templates.
60
- # e.g. config/templates/nginx/nginx.conf.erb
61
- local_template = File.join(local_template_dir, app.to_s, template)
62
- if File.exists?(local_template)
63
- puts
64
- puts "Using local template (#{local_template})"
65
- template = ERB.new(IO.read(local_template), nil, '-')
66
- else
67
- template = ERB.new(IO.read(File.join(DEPREC_TEMPLATES_BASE, app.to_s, template)), nil, '-')
68
- end
69
- rendered_template = template.result(binding)
70
-
71
- if remote
72
- # render to remote machine
73
- puts 'You need to specify a path to render the template to!' unless path
74
- exit unless path
75
- sudo "test -d #{File.dirname(path)} || #{sudo} mkdir -p #{File.dirname(path)}"
76
- std.su_put rendered_template, path, '/tmp/', :mode => mode
77
- sudo "chown #{owner} #{path}" if defined?(owner)
78
- elsif path
79
- # render to local file
80
- full_path = File.join('config', stage, app.to_s, path)
81
- path_dir = File.dirname(File.expand_path(full_path))
82
- if File.exists?(full_path)
83
- if IO.read(full_path) == rendered_template
84
- puts "[skip] Identical file exists (#{full_path})."
85
- return false
86
- elsif overwrite?(full_path, rendered_template)
87
- File.delete(full_path)
88
- else
89
- puts "[skip] Not overwriting #{full_path}"
90
- return false
91
- end
92
- end
93
- FileUtils.mkdir_p "#{path_dir}" if ! File.directory?(path_dir)
94
- # added line above to make windows compatible
95
- # system "mkdir -p #{path_dir}" if ! File.directory?(path_dir)
96
- File.open(File.expand_path(full_path), 'w'){|f| f.write rendered_template }
97
- puts "[done] #{full_path} written"
98
- else
99
- # render to string
100
- return rendered_template
101
- end
102
- end
103
-
104
- def overwrite?(full_path, rendered_template)
105
- if defined?(overwrite_all)
106
- if overwrite_all == true
107
- return true
108
- else
109
- return false
110
- end
111
- end
112
-
113
- # XXX add :always and :never later - not sure how to set persistent value from here
114
- # response = Capistrano::CLI.ui.ask "File exists. Overwrite? ([y]es, [n]o, [a]lways, n[e]ver)" do |q|
115
- puts
116
- response = Capistrano::CLI.ui.ask "File exists (#{full_path}).
117
- Overwrite? ([y]es, [n]o, [d]iff)" do |q|
118
- q.default = 'n'
119
- end
120
-
121
- case response
122
- when 'y'
123
- return true
124
- when 'n'
125
- return false
126
- when 'd'
127
- require 'tempfile'
128
- tf = Tempfile.new("deprec_diff")
129
- tf.puts(rendered_template)
130
- tf.close
131
- puts
132
- puts "Running diff -u current_file new_file_if_you_overwrite"
133
- puts
134
- system "diff -u #{full_path} #{tf.path} | less"
135
- puts
136
- overwrite?(full_path, rendered_template)
137
- # XXX add :always and :never later - not sure how to set persistent value from here
138
- # when 'a'
139
- # set :overwrite_all, true
140
- # when 'e'
141
- # set :overwrite_all, false
142
- end
143
-
144
- end
145
-
146
- def render_template_to_file(template_name, destination_file_name, templates_dir = DEPREC_TEMPLATES_BASE)
147
- template_name += '.conf' if File.extname(template_name) == '' # XXX this to be removed
148
-
149
- file = File.join(templates_dir, template_name)
150
- buffer = render :template => File.read(file)
151
-
152
- temporary_location = "/tmp/#{template_name}"
153
- put buffer, temporary_location
154
- sudo "cp #{temporary_location} #{destination_file_name}"
155
- delete temporary_location
156
- end
157
-
158
- # Copy configs to server(s). Note there is no :pull task. No changes should
159
- # be made to configs on the servers so why would you need to pull them back?
160
- def push_configs(app, files)
161
- app = app.to_s
162
- stage = exists?(:stage) ? fetch(:stage).to_s : ''
163
-
164
- files.each do |file|
165
- full_local_path = File.join('config', stage, app, file[:path])
166
- if File.exists?(full_local_path)
167
- # If the file path is relative we will prepend a path to this projects
168
- # own config directory for this service.
169
- if file[:path][0,1] != '/'
170
- full_remote_path = File.join(deploy_to, app, file[:path])
171
- else
172
- full_remote_path = file[:path]
173
- end
174
- sudo "test -d #{File.dirname(full_remote_path)} || #{sudo} mkdir -p #{File.dirname(full_remote_path)}"
175
- std.su_put File.read(full_local_path), full_remote_path, '/tmp/', :mode=>file[:mode]
176
- sudo "chown #{file[:owner]} #{full_remote_path}"
177
- else
178
- # Render directly to remote host.
179
- render_template(app, file.merge(:remote => true))
180
- end
181
- end
182
- end
183
-
184
- def teardown_connections
185
- sessions.keys.each do |server|
186
- sessions[server].close
187
- sessions.delete(server)
188
- end
189
- end
190
-
191
- def append_to_file_if_missing(filename, value, options={})
192
- # XXX sort out single quotes in 'value' - they'l break command!
193
- # XXX if options[:requires_sudo] and :use_sudo then use sudo
194
- sudo <<-END
195
- sh -c '
196
- grep -F "#{value}" #{filename} > /dev/null 2>&1 ||
197
- echo "#{value}" >> #{filename}
198
- '
199
- END
200
- end
201
-
202
- # create new user account on target system
203
- def useradd(user, options={})
204
- options[:shell] ||= '/bin/bash' # new accounts on ubuntu 6.06.1 have been getting /bin/sh
205
- switches = ''
206
- switches += " --shell=#{options[:shell]} " if options[:shell]
207
- switches += ' --create-home ' unless options[:homedir] == false
208
- switches += " --gid #{options[:group]} " unless options[:group].nil?
209
- invoke_command "grep '^#{user}:' /etc/passwd || #{sudo} /usr/sbin/useradd #{switches} #{user}",
210
- :via => run_method
211
- end
212
-
213
- # create a new group on target system
214
- def groupadd(group, options={})
215
- via = options.delete(:via) || run_method
216
- # XXX I don't like specifying the path to groupadd - need to sort out paths before long
217
- invoke_command "grep '#{group}:' /etc/group || #{sudo} /usr/sbin/groupadd #{group}", :via => via
218
- end
219
-
220
- # add group to the list of groups this user belongs to
221
- def add_user_to_group(user, group)
222
- invoke_command "groups #{user} | grep ' #{group} ' || #{sudo} /usr/sbin/usermod -G #{group} -a #{user}",
223
- :via => run_method
224
- end
225
-
226
- # create directory if it doesn't already exist
227
- # set permissions and ownership
228
- # XXX move mode, path and
229
- def mkdir(path, options={})
230
- via = options.delete(:via) || :run
231
- # XXX need to make sudo commands wrap the whole command (sh -c ?)
232
- # XXX removed the extra 'sudo' from after the '||' - need something else
233
- invoke_command "test -d #{path} || #{sudo if via == :sudo} mkdir -p #{path}"
234
- invoke_command "chmod #{sprintf("%3o",options[:mode]||0755)} #{path}", :via => via if options[:mode]
235
- invoke_command "chown -R #{options[:owner]} #{path}", :via => via if options[:owner]
236
- groupadd(options[:group], :via => via) if options[:group]
237
- invoke_command "chgrp -R #{options[:group]} #{path}", :via => via if options[:group]
238
- end
239
-
240
- def create_src_dir
241
- mkdir(src_dir, :mode => 0775, :group => group_src, :via => :sudo)
242
- end
243
-
244
- # download source pkg if we don't already have it
245
- def download_src(src_pkg, src_dir=src_dir)
246
- set_pkg_defaults(src_pkg)
247
- create_src_dir
248
- # check if file exists and if we have an MD5 hash or bytecount to compare
249
- # against if so, compare and decide if we need to download again
250
- if defined?(src_pkg[:md5sum])
251
- md5_clause = " && echo '#{src_pkg[:md5sum]}' | md5sum -c - "
252
- end
253
- case src_pkg[:download_method]
254
- # when getting source with git
255
- when :git
256
- # ensure git is installed
257
- apt.install( {:base => %w(git-core)}, :stable) #TODO fix this to test ubuntu version <hardy might need specific git version for full git submodules support
258
- pkg_dir = File.join(src_dir, src_pkg[:dir])
259
- run "if [ -d #{pkg_dir} ]; then cd #{pkg_dir} && #{sudo} git checkout master && #{sudo} git pull && #{sudo} git submodule init && #{sudo} git submodule update; else #{sudo} git clone #{src_pkg[:url]} #{pkg_dir} && cd #{pkg_dir} && #{sudo} git submodule init && #{sudo} git submodule update ; fi"
260
- # Checkout the revision wanted if defined
261
- if src_pkg[:version]
262
- run "cd #{pkg_dir} && git branch | grep '#{src_pkg[:version]}$' && #{sudo} git branch -D '#{src_pkg[:version]}'; exit 0"
263
- run "cd #{pkg_dir} && #{sudo} git checkout -b #{src_pkg[:version]} #{src_pkg[:version]}"
264
- end
265
-
266
- # when getting source with wget
267
- when :http
268
- # ensure wget is installed
269
- apt.install( {:base => %w(wget)}, :stable )
270
- # XXX replace with invoke_command
271
- run "cd #{src_dir} && test -f #{src_pkg[:filename]} #{md5_clause} || #{sudo} wget --quiet --timestamping #{src_pkg[:url]}"
272
-
273
- when :deb
274
- run "cd #{src_dir} && test -f #{src_pkg[:filename]} #{md5_clause} || #{sudo} wget --quiet --timestamping #{src_pkg[:url]}"
275
-
276
- else
277
- puts "DOWNLOAD SRC: Download method not recognised. src_pkg[:download_method]: #{src_pkg[:download_method]}"
278
- end
279
- end
280
-
281
- # unpack src and make it writable by the group
282
- def unpack_src(src_pkg, src_dir=src_dir)
283
- set_pkg_defaults(src_pkg)
284
- pkg_dir = File.join([src_dir, src_pkg[:dir]].compact)
285
- case src_pkg[:download_method]
286
- # when unpacking git sources - nothing to do
287
- when :deb
288
- puts "UNPACK SRC: nothing to do for deb installs"
289
- when :git
290
- puts "UNPACK SRC: nothing to do for git installs"
291
- when :http
292
- run "test -d #{pkg_dir}.old && #{sudo} rm -fr #{pkg_dir}.old; exit 0"
293
- run "test -d #{pkg_dir} && #{sudo} mv #{pkg_dir} #{pkg_dir}.old; exit 0"
294
- run "cd #{src_dir} && #{sudo} #{src_pkg[:unpack]}" if src_pkg[:unpack] != ''
295
- run "#{sudo} chgrp -R #{group} #{pkg_dir}"
296
- run "#{sudo} chmod -R g+w #{pkg_dir}"
297
- else
298
- puts "UNPACK SRC: Download method not recognised. src_pkg[:download_method]: #{src_pkg[:download_method]} "
299
- end
300
- end
301
-
302
- def set_pkg_defaults(pkg)
303
- pkg[:filename] ||= File.basename(pkg[:url])
304
- pkg[:download_method] ||= :http
305
- pkg[:post_install] ||= ''
306
- case pkg[:download_method]
307
- when :http
308
- pkg[:dir] ||= pkg[:filename].sub(/(\.tgz|\.tar\.gz)/,'')
309
- pkg[:unpack] ||= "tar zxf #{pkg[:filename]};"
310
- pkg[:configure] ||= './configure ;'
311
- pkg[:make] ||= 'make;'
312
- pkg[:install] ||= 'make install;'
313
- when :deb
314
- pkg[:dir] ||= ''
315
- pkg[:unpack] ||= ''
316
- pkg[:configure] ||= ''
317
- pkg[:make] ||= ''
318
- pkg[:install] ||= "dpkg -i #{pkg[:filename]}"
319
- end
320
- end
321
-
322
- # install pkg from source
323
- def install_from_src(src_pkg, src_dir=src_dir)
324
- install_deps(src_pkg[:deps])
325
- set_pkg_defaults(src_pkg)
326
- pkg_dir = File.join([src_dir, src_pkg[:dir]].compact)
327
- unpack_src(src_pkg, src_dir)
328
- apt.install( {:base => %w(build-essential)}, :stable )
329
- run "cd #{pkg_dir} && #{sudo} #{src_pkg[:configure]}" if src_pkg[:configure] != ''
330
- run "cd #{pkg_dir} && #{sudo} #{src_pkg[:make]}" if src_pkg[:make] != ''
331
- run "cd #{pkg_dir} && #{sudo} #{src_pkg[:install]}" if src_pkg[:install] != ''
332
- run "cd #{pkg_dir} && #{sudo} #{src_pkg[:post_install]}" if src_pkg[:post_install] != ''
333
- end
334
-
335
- def install_deps(packages=[])
336
- apt.install({:base => Array(packages)}, :stable)
337
- end
338
-
339
- def read_database_yml
340
- stage = exists?(:stage) ? fetch(:stage).to_s : ''
341
- db_config = YAML.load_file(File.join('config', stage, 'database.yml'))
342
- set :db_user, db_config[rails_env]["username"]
343
- set :db_password, db_config[rails_env]["password"]
344
- set :db_name, db_config[rails_env]["database"]
345
- end
346
-
347
-
348
- ##
349
- # Run a command and ask for input when input_query is seen.
350
- # Sends the response back to the server.
351
- #
352
- # +input_query+ is a regular expression that defaults to /^Password/.
353
- #
354
- # Can be used where +run+ would otherwise be used.
355
- #
356
- # run_with_input 'ssh-keygen ...', /^Are you sure you want to overwrite\?/
357
-
358
- def run_with_input(shell_command, input_query=/^Password/, response=nil)
359
- handle_command_with_input(:run, shell_command, input_query, response)
360
- end
361
-
362
- ##
363
- # Run a command using sudo and ask for input when a regular expression is seen.
364
- # Sends the response back to the server.
365
- #
366
- # See also +run_with_input+
367
- #
368
- # +input_query+ is a regular expression
369
-
370
- def sudo_with_input(shell_command, input_query=/^Password/, response=nil)
371
- handle_command_with_input(:sudo, shell_command, input_query, response)
372
- end
373
-
374
- def invoke_with_input(shell_command, input_query=/^Password/, response=nil)
375
- handle_command_with_input(run_method, shell_command, input_query, response)
376
- end
377
-
378
- ##
379
- # Run a command using sudo and continuously pipe the results back to the console.
380
- #
381
- # Similar to the built-in +stream+, but for privileged users.
382
-
383
- def sudo_stream(command)
384
- sudo(command) do |ch, stream, out|
385
- puts out if stream == :out
386
- if stream == :err
387
- puts "[err : #{ch[:host]}] #{out}"
388
- break
389
- end
390
- end
391
- end
392
-
393
- private
394
-
395
- ##
396
- # Does the actual capturing of the input and streaming of the output.
397
- #
398
- # local_run_method: run or sudo
399
- # shell_command: The command to run
400
- # input_query: A regular expression matching a request for input: /^Please enter your password/
401
-
402
- def handle_command_with_input(local_run_method, shell_command, input_query, response=nil)
403
- send(local_run_method, shell_command) do |channel, stream, data|
404
- logger.info data, channel[:host]
405
- if data =~ input_query
406
- if response
407
- channel.send_data "#{response}\n"
408
- else
409
- response = ::Capistrano::CLI.password_prompt "#{data}"
410
- channel.send_data "#{response}\n"
411
- end
412
- end
413
- end
414
- end
415
-
416
- end
417
-
418
- Capistrano.plugin :deprec2, Deprec2
@@ -1,7 +0,0 @@
1
- # Copyright 2006-2008 by Mike Bailey. All rights reserved.
2
- unless Capistrano::Configuration.respond_to?(:instance)
3
- abort "deprec2 requires Capistrano 2"
4
- end
5
-
6
- require "#{File.dirname(__FILE__)}/recipes_minus_rails"
7
- require "#{File.dirname(__FILE__)}/recipes/rails"
@@ -1,67 +0,0 @@
1
- # Copyright 2006-2008 by Mike Bailey. All rights reserved.
2
- Capistrano::Configuration.instance(:must_exist).load do
3
- namespace :deprec do
4
- namespace :ar_sendmail do
5
-
6
- desc "Install ar_mailer"
7
- task :install, :roles => :app do
8
- gem2.install 'ar_mailer'
9
- end
10
-
11
- # install dependencies for ar_sendmail
12
- task :install_deps, :roles => :app do
13
- #pass
14
- end
15
-
16
- PROJECT_CONFIG_FILES[:ar_sendmail] = [
17
-
18
- {:template => 'monit.conf.erb',
19
- :path => "monit.conf",
20
- :mode => 0600,
21
- :owner => 'root:root'},
22
-
23
- {:template => 'logrotate.conf.erb',
24
- :path => "logrotate.conf",
25
- :mode => 0644,
26
- :owner => 'root:root'}
27
- ]
28
-
29
- task :config_gen do
30
- config_gen_project
31
- end
32
-
33
- desc "Generate configuration file(s) for ar_sendmail from template(s)"
34
- task :config_gen_project do
35
- PROJECT_CONFIG_FILES[:ar_sendmail].each do |file|
36
- deprec2.render_template(:ar_sendmail, file)
37
- end
38
- end
39
-
40
- desc "Push ar_sendmail config files to server"
41
- task :config, :roles => :app do
42
- config_project
43
- end
44
-
45
- task :config_project, :roles => :app do
46
- deprec2.push_configs(:ar_sendmail, PROJECT_CONFIG_FILES[:ar_sendmail])
47
- symlink_monit_config
48
- symlink_logrotate_config
49
- end
50
-
51
- task :symlink_monit_config, :roles => :app do
52
- deprec2.mkdir(monit_confd_dir, :via => :sudo)
53
- sudo "ln -sf #{deploy_to}/ar_sendmail/monit.conf #{monit_confd_dir}/ar_sendmail_#{application}.conf"
54
- end
55
-
56
- task :unlink_monit_config, :roles => :app do
57
- link = "#{monit_confd_dir}/ar_sendmail_#{application}.conf"
58
- sudo "test -L #{link} && unlink #{link}"
59
- end
60
-
61
- task :symlink_logrotate_config, :roles => :app do
62
- sudo "ln -sf #{deploy_to}/ar_sendmail/logrotate.conf /etc/logrotate.d/ar_sendmail-#{application}"
63
- end
64
-
65
- end
66
- end
67
- end