deprec 2.1.19 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. data/CHANGELOG +11 -1
  2. data/{README → README.md} +33 -68
  3. data/bin/hosts.rb +44 -0
  4. data/docs/nagios.txt +28 -0
  5. data/lib/deprec/capistrano_extensions.rb +21 -32
  6. data/lib/deprec/recipes/apache.rb +54 -73
  7. data/lib/deprec/recipes/deprec.rb +30 -48
  8. data/lib/deprec/recipes/git.rb +2 -85
  9. data/lib/deprec/recipes/haproxy.rb +3 -11
  10. data/lib/deprec/recipes/mri.rb +23 -40
  11. data/lib/deprec/recipes/mysql.rb +6 -23
  12. data/lib/deprec/recipes/nagios.rb +2 -17
  13. data/lib/deprec/recipes/nagios3.rb +180 -0
  14. data/lib/deprec/recipes/network.rb +60 -28
  15. data/lib/deprec/recipes/nrpe.rb +82 -0
  16. data/lib/deprec/recipes/passenger.rb +15 -12
  17. data/lib/deprec/recipes/postgresql.rb +2 -2
  18. data/lib/deprec/recipes/rack.rb +44 -0
  19. data/lib/deprec/recipes/rails.rb +10 -32
  20. data/lib/deprec/recipes/ree.rb +27 -18
  21. data/lib/deprec/recipes/rubygems.rb +29 -0
  22. data/lib/deprec/recipes/sqlite.rb +1 -1
  23. data/lib/deprec/recipes/ssh.rb +1 -0
  24. data/lib/deprec/recipes/svn.rb +1 -160
  25. data/lib/deprec/recipes/users.rb +19 -16
  26. data/lib/deprec/recipes_minus_rails.rb +39 -36
  27. data/lib/deprec/templates/apache/CHANGES.txt +11 -0
  28. data/lib/deprec/templates/mysql/my.cnf.erb +21 -31
  29. data/lib/deprec/templates/{nagios → nagios.old}/README +0 -0
  30. data/lib/deprec/templates/nagios.old/apache_vhost.erb +25 -0
  31. data/lib/deprec/templates/{nagios → nagios.old}/cgi.cfg.erb +0 -0
  32. data/lib/deprec/templates/nagios.old/check_linux_free_memory.pl +118 -0
  33. data/lib/deprec/templates/{nagios → nagios.old}/check_mongrel_cluster.rb +0 -0
  34. data/lib/deprec/templates/nagios.old/htpasswd.users +1 -0
  35. data/lib/deprec/templates/{nagios → nagios.old}/mrtg.cfg +0 -0
  36. data/lib/deprec/templates/{nagios → nagios.old}/nagios.cfg.erb +0 -0
  37. data/lib/deprec/templates/{nagios → nagios.old}/nrpe.cfg.erb +0 -0
  38. data/lib/deprec/templates/{nagios → nagios.old}/nrpe.xinetd.erb +0 -0
  39. data/lib/deprec/templates/{nagios → nagios.old}/objects/commands.cfg.erb +0 -0
  40. data/lib/deprec/templates/{nagios → nagios.old}/objects/contacts.cfg.erb +0 -0
  41. data/lib/deprec/templates/{nagios → nagios.old}/objects/hosts.cfg.erb +0 -0
  42. data/lib/deprec/templates/{nagios → nagios.old}/objects/localhost.cfg.erb +0 -0
  43. data/lib/deprec/templates/{nagios → nagios.old}/objects/services.cfg.erb +0 -0
  44. data/lib/deprec/templates/{nagios → nagios.old}/objects/timeperiods.cfg.erb +0 -0
  45. data/lib/deprec/templates/{nagios → nagios.old}/resource.cfg.erb +0 -0
  46. data/lib/deprec/templates/nagios/apache2.conf +55 -0
  47. data/lib/deprec/templates/nagios/cgi.cfg +25 -0
  48. data/lib/deprec/templates/nagios/commands.cfg +52 -0
  49. data/lib/deprec/templates/nagios/conf.d/contacts_nagios2.cfg +23 -0
  50. data/lib/deprec/templates/nagios/conf.d/extinfo_nagios2.cfg +13 -0
  51. data/lib/deprec/templates/nagios/conf.d/generic-host_nagios2.cfg +19 -0
  52. data/lib/deprec/templates/nagios/conf.d/generic-service_nagios2.cfg +26 -0
  53. data/lib/deprec/templates/nagios/conf.d/hostgroups_nagios2.cfg +48 -0
  54. data/lib/deprec/templates/nagios/conf.d/hosts/localhost_nagios2.cfg +59 -0
  55. data/lib/deprec/templates/nagios/conf.d/services_nagios2.cfg +45 -0
  56. data/lib/deprec/templates/nagios/conf.d/timeperiods_nagios2.cfg +50 -0
  57. data/lib/deprec/templates/nagios/host_template.erb +6 -0
  58. data/lib/deprec/templates/nagios/htpasswd.users +1 -1
  59. data/lib/deprec/templates/nagios/nagios.cfg +1326 -0
  60. data/lib/deprec/templates/nagios/nrpe.cfg +28 -0
  61. data/lib/deprec/templates/nagios/resource.cfg +31 -0
  62. data/lib/deprec/templates/passenger/apache_vhost.erb +2 -2
  63. data/lib/deprec/templates/passenger/logrotate.conf.erb +1 -1
  64. data/lib/deprec/templates/passenger/passenger.conf.erb +12 -11
  65. data/lib/deprec/templates/passenger/passenger.load.erb +1 -1
  66. metadata +43 -42
  67. data/lib/deprec/recipes/wordpress.rb +0 -96
data/CHANGELOG CHANGED
@@ -1,6 +1,16 @@
1
1
  # deprec changelog
2
2
 
3
- = 2.1.19 (Feb 4, 2011)
3
+ = 2.2.1 (Jul 10, 2011)
4
+
5
+ * First release since rewrite of http://deprec.org
6
+ * Tidy up of various recipes
7
+ * Introduction of deprec:rack namespace
8
+
9
+ = 2.1.20 (Mar 4, 2011)
10
+
11
+ * generate apache vhost to current dir if config/ not present
12
+
13
+ = 2.1.19 (Mar 4, 2011)
4
14
 
5
15
  * replaced mailx with mailutils
6
16
  * cap deprec:apache:vhost # handy vhost generator
@@ -1,41 +1,39 @@
1
- ------------------------------------------
2
1
  deprec - Deployment Recipes for Capistrano
3
- ------------------------------------------
2
+ ==========================================
4
3
 
5
- == Introduction
6
-
7
- The deprec [1] gem is a set of tasks for Capistrano [2]. These tasks provide
4
+ The [deprec][1] gem is a set of tasks for [Capistrano][2]. These tasks provide
8
5
  for the installation, configuration and control of system services on servers
9
6
  running Ubuntu linux. Deprec was created in 2006 by Mike Bailey to setup an
10
7
  environment for running Ruby on Rails web applications on Ubuntu servers. Since
11
- then its uses have grown to installing Xen virtualization, mail, monitoring, high
12
- availability IP failover and other services.
8
+ then its uses have grown to installing Xen virtualization, mail, monitoring,
9
+ high availability IP failover and other services.
13
10
 
14
11
  The tasks are run at the command line on your workstation and connect to
15
12
  remote servers via ssh to run commands and copy out files.
16
13
 
17
14
  Deprec-2.x is a complete rewrite of the project that achieves the following:
18
15
 
19
- - support for Capistrano 2
20
- - generated config files are stored locally to enable editing and version control
21
- - support for more services (heartbeat, nagios, nginx, ntp, postfix, etc)
22
- - multiple Rails deployment options (Passenger+Apache, Mongrel+Apache/Nginx)
23
- - creation of a standard base set of task names
24
- - tasks are cleanly separated into namespaced units (one file per service)
25
- - interactive prompting for missing config values
16
+ * support for Capistrano 2
17
+ * generated config files are stored locally to enable editing and version control
18
+ * support for more services (heartbeat, nagios, nginx, ntp, postfix, etc)
19
+ * multiple Rails deployment options (Passenger+Apache, Mongrel+Apache/Nginx)
20
+ * creation of a standard base set of task names
21
+ * tasks are cleanly separated into namespaced units (one file per service)
22
+ * interactive prompting for missing config values
26
23
 
27
- Deprec and Capistrano are written in the Ruby programming language [3] however
24
+ Deprec and Capistrano are written in the [Ruby programming language][3] however
28
25
  no knowledge of Ruby is required to use it. Users should be able to write
29
26
  new tasks and modify existing options without prior knowledge of Ruby.
30
27
 
31
28
 
32
- == Installation
29
+ Installation
30
+ ------------
33
31
 
34
- Deprec can be obtained from rubyforge[4] and installed using rubygems[5].
32
+ Deprec can using rubygems[5].
35
33
 
36
34
  sudo gem install deprec # installs deprec and dependancies
37
- cap depify . # creates ~/.caprc which you may edit
38
- cap -T # should list lots of deprec tasks
35
+ depify -c # creates ~/.caprc which you may edit
36
+ cap -T # should list lots of deprec tasks
39
37
 
40
38
  The .caprc file is loaded every time you use Capistrano. It in turn loads
41
39
  the deprec tasks so you always have them available. Editing the .caprc file
@@ -45,56 +43,23 @@ also put tasks here that you want access to, regardless of the current working
45
43
  directory.
46
44
 
47
45
 
48
- == Getting a Ruby on Rails app running on a fresh Ubuntu server
49
-
50
- This is still what brings people to deprec. You can install a full Rails stack
51
- and get multiple apps running on it in much less time than it would take to
52
- do it manually (e.g. an hour vs. a weekend).
53
-
54
- Get your app running on a fresh Ubuntu (7.10, 8.04) server with these commands:
55
-
56
- cd your_rails_app
57
- depify .
58
- # Edit config/deploy.rb
59
- cap deprec:rails:install_stack
60
-
61
- # WARNING! Don't run the following command if you are using a shared
62
- # database server that has already been installed.
63
- cap deprec:db:install
64
-
65
- cap deploy:setup
66
- cap deploy
67
- cap deploy:migrate
68
-
69
- Recorded times for complete install on Ubuntu hardy server (7.10 amd64)
70
-
71
- * Passenger+REE+Apache : 14m29s
72
- * Passenger+ruby-1.8.7+Apache : 17m51s
73
- * nginx+mongrel : 16m25s
74
-
75
- Note you can choose combinations of:
76
-
77
- * Ruby Enterprise Edition or ruby-1.8.7
78
- * Passenger or mongrel (passenger requires you choose to the apache option)
79
- * Apache or nginx
80
-
81
- You can find documentation on the deprec site. http://www.deprec.org/
82
-
83
-
84
- == Installing other things
46
+ Installing other things
47
+ -----------------------
85
48
 
86
49
  I plan to document other things I use deprec for on http://www.deprec.org/.
87
50
  Feel free to poke around and see what's there. I use deprec to provision and
88
51
  manage servers so you might find some things in there I haven't documented. Lucky you.
89
52
 
90
53
 
91
- == Disclaimer
54
+ Disclaimer
55
+ ----------
92
56
 
93
57
  The tasks run commands that may make changes to your workstation and remote server.
94
58
  You are advised to read the source and use at your own risk.
95
59
 
96
60
 
97
- == Credits
61
+ Credits
62
+ -------
98
63
 
99
64
  Deprec is written and maintained by Mike Bailey <mike@bailey.net.au>.
100
65
  More about me here: [http://mike.bailey.net.au/]
@@ -103,7 +68,8 @@ Deprec was inspired and uses the brilliantly executed Capistrano. Thanks Jamis!
103
68
  This gem includes a modified copy of Neil Wilson's very useful vmbuilder_plugins gem.
104
69
 
105
70
 
106
- == Thanks
71
+ Thanks
72
+ ------
107
73
 
108
74
  Deprec wouldn't be what it is without the contributions of many people, a few of whom are listed here:
109
75
 
@@ -120,7 +86,8 @@ Deprec wouldn't be what it is without the contributions of many people, a few of
120
86
  zippy
121
87
 
122
88
 
123
- == License
89
+ License
90
+ -------
124
91
 
125
92
  Deprec is licenced under the GPL. This means that you can use it in commercial
126
93
  or open source applications. More details found here:
@@ -144,11 +111,9 @@ along with this program; if not, write to the Free Software
144
111
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
145
112
 
146
113
 
147
- [1] http://www.deprec.org/
148
- [2] http://www.capify.org/
149
- [3] http://www.ruby-lang.org/en/
150
- [4] http://rubyforge.org/
151
- [5] http://rubygems.org/
152
- [6] http://www.sct.com.au/
153
-
154
- foo
114
+ [1]: http://www.deprec.org/
115
+ [2]: http://www.capify.org/
116
+ [3]: http://www.ruby-lang.org/en/
117
+ [4]: http://rubyforge.org/
118
+ [5]: http://rubygems.org/
119
+ [6]: http://www.sct.com.au/
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Generate Nagios hosts files from unix hosts file
4
+ #
5
+ # e.g.
6
+ # 10.1.1.1 gw.failmode.com
7
+ # 10.1.1.5 mail.failmode.com
8
+
9
+ require 'erb'
10
+
11
+ hosts_file = ARGV[0] || '/etc/hosts'
12
+
13
+ template = ERB.new <<-EOF
14
+ define host{
15
+ use generic-host
16
+ hostgroups linux-servers
17
+ host_name <%= host_name %>
18
+ address <%= ip %>
19
+ }
20
+ EOF
21
+
22
+ ValidIpAddressRegex = /^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/;
23
+
24
+ ValidHostnameRegex = /^(([a-zA-Z]|[a-zA-Z][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z]|[A-Za-z][A-Za-z0-9\-]*[A-Za-z0-9])$/;
25
+
26
+ # XXX Add hostgroups to hosts
27
+ # HOSTGROUPS = 'linux-servers', 'windows-servers', 'debian-servers', 'vmware-hosts'
28
+
29
+ open(hosts_file).each do |line|
30
+ ip, host_name = line.sub(/#.*/,'').split[0,2]
31
+ hostgroups = []
32
+
33
+
34
+ if ip =~ ValidIpAddressRegex and host_name =~ ValidHostnameRegex
35
+ filename = host_name + '.cfg'
36
+ File.open(filename, 'w') do |file|
37
+ file.write template.result(binding)
38
+ puts "writing #{filename}"
39
+ end
40
+ else
41
+ puts "not writing anything for '#{line}'"
42
+ end
43
+
44
+ end
@@ -0,0 +1,28 @@
1
+ Nagios with deprec
2
+ ==================
3
+
4
+ For each command, append HOSTS=target.host.name
5
+
6
+ # Nagios server
7
+ cap deprec:nagios:install
8
+ cap deprec:nagios:gen_host # One way to add hosts to monitor
9
+ cap deprec:nagios:config
10
+
11
+ # servers to be monitored
12
+ cap deprec:nrpe:install
13
+ cap deprec:nrpe:test_local # does nrpe query from local host
14
+ cap deprec:nrpe:test_remote # does nrpe query from nagios server
15
+
16
+
17
+ # TODO
18
+ By maintaining a simple hosts file you can generate the nagios
19
+ hosts files. The following hosts file is valid:
20
+
21
+ # This hosts file is used to generate Nagios hosts configs
22
+ # The first two tokens are used only if they consist of a
23
+ # valid IP address and hostname.
24
+ #
25
+ # hostgroups can follow but must be preceded by a '#'
26
+ #
27
+ 10.1.1.10 xen01 # linux-servers dom0
28
+ 10.1.1.11 web01 # linux-servers domU
@@ -12,6 +12,7 @@ module Deprec2
12
12
  yield
13
13
  ENV['ROLES'] = old_roles.to_s unless ENV['HOSTS']
14
14
  end
15
+
15
16
 
16
17
  # Temporarily ignore ROLES and HOSTS
17
18
  def ignoring_roles_and_hosts
@@ -77,10 +78,10 @@ module Deprec2
77
78
  elsif path
78
79
  # render to local file
79
80
  full_path = File.join('config', stage, app.to_s, path)
80
- path_dir = File.dirname(full_path)
81
+ path_dir = File.dirname(File.expand_path(full_path))
81
82
  if File.exists?(full_path)
82
83
  if IO.read(full_path) == rendered_template
83
- puts "[skip] File exists and is identical (#{full_path})."
84
+ puts "[skip] Identical file exists (#{full_path})."
84
85
  return false
85
86
  elsif overwrite?(full_path, rendered_template)
86
87
  File.delete(full_path)
@@ -92,7 +93,7 @@ module Deprec2
92
93
  FileUtils.mkdir_p "#{path_dir}" if ! File.directory?(path_dir)
93
94
  # added line above to make windows compatible
94
95
  # system "mkdir -p #{path_dir}" if ! File.directory?(path_dir)
95
- File.open(full_path, 'w'){|f| f.write rendered_template }
96
+ File.open(File.expand_path(full_path), 'w'){|f| f.write rendered_template }
96
97
  puts "[done] #{full_path} written"
97
98
  else
98
99
  # render to string
@@ -241,7 +242,7 @@ module Deprec2
241
242
  end
242
243
 
243
244
  # download source pkg if we don't already have it
244
- def download_src(src_pkg, src_dir)
245
+ def download_src(src_pkg, src_dir=src_dir)
245
246
  set_pkg_defaults(src_pkg)
246
247
  create_src_dir
247
248
  # check if file exists and if we have an MD5 hash or bytecount to compare
@@ -278,7 +279,7 @@ module Deprec2
278
279
  end
279
280
 
280
281
  # unpack src and make it writable by the group
281
- def unpack_src(src_pkg, src_dir)
282
+ def unpack_src(src_pkg, src_dir=src_dir)
282
283
  set_pkg_defaults(src_pkg)
283
284
  pkg_dir = File.join([src_dir, src_pkg[:dir]].compact)
284
285
  case src_pkg[:download_method]
@@ -319,7 +320,8 @@ module Deprec2
319
320
  end
320
321
 
321
322
  # install pkg from source
322
- def install_from_src(src_pkg, src_dir)
323
+ def install_from_src(src_pkg, src_dir=src_dir)
324
+ install_deps(src_pkg[:deps])
323
325
  set_pkg_defaults(src_pkg)
324
326
  pkg_dir = File.join([src_dir, src_pkg[:dir]].compact)
325
327
  unpack_src(src_pkg, src_dir)
@@ -329,6 +331,10 @@ module Deprec2
329
331
  run "cd #{pkg_dir} && #{sudo} #{src_pkg[:install]}" if src_pkg[:install] != ''
330
332
  run "cd #{pkg_dir} && #{sudo} #{src_pkg[:post_install]}" if src_pkg[:post_install] != ''
331
333
  end
334
+
335
+ def install_deps(packages=[])
336
+ apt.install({:base => Array(packages)}, :stable)
337
+ end
332
338
 
333
339
  def read_database_yml
334
340
  stage = exists?(:stage) ? fetch(:stage).to_s : ''
@@ -384,32 +390,15 @@ module Deprec2
384
390
  end
385
391
  end
386
392
 
387
- # We don't need this. Put 'USER=root' on the command line instead.
388
- #
389
- # XXX Not working in deprec2
390
- # ##
391
- # # Run a command using the root account.
392
- # #
393
- # # Some linux distros/VPS providers only give you a root login when you install.
394
- #
395
- # def run_as_root(shell_command)
396
- # std.connect_as_root do |tempuser|
397
- # run shell_command
398
- # end
399
- # end
400
- #
401
- # ##
402
- # # Run a task using root account.
403
- # #
404
- # # Some linux distros/VPS providers only give you a root login when you install.
405
- # #
406
- # # tempuser: contains the value replaced by 'root' for the duration of this call
407
- #
408
- # def as_root()
409
- # std.connect_as_root do |tempuser|
410
- # yield tempuser
411
- # end
412
- # end
393
+ # deprecated...I don't see any need for this
394
+ # Set the value if not already set
395
+ # This method is accessible to all recipe files
396
+ def self.default(name, *args, &block)
397
+ puts "********** deprecation warning **********"
398
+ puts "Could you use set() instead of default()?"
399
+ puts "*****************************************"
400
+ set(name, *args, &block) unless exists?(name)
401
+ end
413
402
 
414
403
  private
415
404
 
@@ -13,41 +13,12 @@ Capistrano::Configuration.instance(:must_exist).load do
13
13
  set :apache_modules_enabled,
14
14
  %w(rewrite ssl proxy_balancer proxy_http deflate expires headers)
15
15
 
16
- # Start apache vhost extras
17
- # These are only used for generating vhost files with:
18
- #
19
- # cap deprec:apache:vhost
20
- #
21
- set(:apache_vhost_domain) { Capistrano::CLI.ui.ask 'Primary domain' }
22
- set(:apache_vhost_server_alii) {
23
- Capistrano::CLI.ui.ask('ServerAlii (space separated)' ).split(' ')
24
- }
25
- set :apache_vhost_access_log_type, 'combined'
26
- set :apache_vhost_canonicalize_hostname, true
27
- set(:apache_vhost_access_log) {
28
- File.join(apache_log_dir, "#{apache_vhost_domain}-access.log")
29
- }
30
- set(:apache_vhost_error_log) {
31
- File.join(apache_log_dir, "#{apache_vhost_domain}-error.log")
32
- }
33
- set(:apache_vhost_document_root) {
34
- File.join('/var/apps', "#{apache_vhost_domain}", 'public')
35
- }
36
- set :apache_vhost_rack_env, false
37
- # End apache vhost extras
38
-
39
-
40
- desc "Install apache"
16
+ desc "Install Apache"
41
17
  task :install do
42
- install_deps
43
- config
44
- end
45
-
46
- # install dependencies for apache
47
- task :install_deps do
48
18
  apt.install(
49
19
  {:base => %w(apache2-mpm-prefork apache2-prefork-dev rsync ssl-cert)},
50
20
  :stable )
21
+ config
51
22
  end
52
23
 
53
24
  SYSTEM_CONFIG_FILES[:apache] = [
@@ -83,43 +54,30 @@ Capistrano::Configuration.instance(:must_exist).load do
83
54
  # Not required
84
55
  ]
85
56
 
86
- desc "Generate configuration file(s) for apache from template(s)"
57
+ desc "Generate Apache config files"
87
58
  task :config_gen do
88
59
  config_gen_system
89
60
  end
90
61
 
62
+ # Generate system level apache configs
91
63
  task :config_gen_system do
92
64
  SYSTEM_CONFIG_FILES[:apache].each do |file|
93
65
  deprec2.render_template(:apache, file)
94
66
  end
95
67
  end
96
68
 
69
+ # Not used here
97
70
  task :config_gen_project do
98
- PROJECT_CONFIG_FILES[:apache].each do |file|
99
- deprec2.render_template(:apache, file)
100
- end
101
- # XXX Need to flesh out generation of custom certs
102
- # In the meantime we'll just use the snakeoil cert
103
- #
104
- # top.deprec.ssl.config_gen if apache_ssl_enabled
105
- top.deprec.ssl.config_gen if apache_ssl_enabled
106
71
  end
107
72
 
108
- desc "Push apache config files to server"
73
+ desc "Push Apache config files to server"
109
74
  task :config, :roles => :web do
110
75
  config_system
111
76
  enable_modules
112
77
  reload
113
78
  end
114
79
 
115
- desc "Generate initial configs and copy direct to server."
116
- task :initial_config, :roles => :web do
117
- SYSTEM_CONFIG_FILES[:apache].each do |file|
118
- deprec2.render_template(:apache, file.merge(:remote => true))
119
- end
120
- end
121
-
122
- desc "Push apache config files to server"
80
+ desc "Push Apache config files to server"
123
81
  task :config_system, :roles => :web do
124
82
  deprec2.push_configs(:apache, SYSTEM_CONFIG_FILES[:apache])
125
83
  run "#{sudo} touch /var/www/check.txt" # Used to test webserver up
@@ -133,58 +91,81 @@ Capistrano::Configuration.instance(:must_exist).load do
133
91
  top.deprec.ssl.config if apache_ssl_enabled
134
92
  end
135
93
 
136
- task :vhost do
137
- file = {
138
- :template => 'vhost.erb',
139
- :path => "/etc/apache2/sites-available/#{apache_vhost_domain}",
140
- :mode => 0644,
141
- :owner => 'root:root'
142
- }
143
- deprec2.render_template(:apache, file)
144
- end
145
-
146
94
  task :enable_modules, :roles => :web do
147
95
  apache_modules_enabled.each { |mod| sudo "a2enmod #{mod}" }
148
96
  end
97
+
98
+ #
99
+ # Control
100
+ #
149
101
 
150
102
  desc "Start Apache"
151
103
  task :start, :roles => :web do
152
- send(run_method, "/etc/init.d/apache2 start")
104
+ run "#{sudo} /etc/init.d/apache2 start"
153
105
  end
154
106
 
155
107
  desc "Stop Apache"
156
108
  task :stop, :roles => :web do
157
- send(run_method, "/etc/init.d/apache2 stop")
109
+ run "#{sudo} /etc/init.d/apache2 stop"
158
110
  end
159
111
 
160
112
  desc "Restart Apache"
161
113
  task :restart, :roles => :web do
162
- send(run_method, "/etc/init.d/apache2 restart")
114
+ run "#{sudo} /etc/init.d/apache2 restart"
163
115
  end
164
116
 
165
117
  desc "Reload Apache"
166
118
  task :reload, :roles => :web do
167
- send(run_method, "/etc/init.d/apache2 force-reload")
119
+ run "#{sudo} /etc/init.d/apache2 force-reload"
168
120
  end
169
121
 
170
- desc "Set apache to start on boot"
122
+ desc "Set Apache to start on boot"
171
123
  task :activate, :roles => :web do
172
- send(run_method, "update-rc.d apache2 defaults")
124
+ run "#{sudo} update-rc.d apache2 defaults"
173
125
  end
174
126
 
175
- desc "Set apache to not start on boot"
127
+ desc "Set Apache to not start on boot"
176
128
  task :deactivate, :roles => :web do
177
- send(run_method, "update-rc.d -f apache2 remove")
129
+ run "#{sudo} update-rc.d -f apache2 remove"
178
130
  end
179
131
 
180
- task :backup, :roles => :web do
181
- # not yet implemented
132
+ # Apache vhost extras
133
+ #
134
+ # These are only used for generating vhost files with:
135
+ #
136
+ # cap deprec:apache:vhost
137
+ #
138
+ set(:apache_vhost_domain) { Capistrano::CLI.ui.ask 'Primary domain' }
139
+ set(:apache_vhost_server_alii) {
140
+ Capistrano::CLI.ui.ask('ServerAlii (space separated)' ).split(' ')
141
+ }
142
+ set :apache_vhost_access_log_type, 'combined'
143
+ set :apache_vhost_canonicalize_hostname, true
144
+ set(:apache_vhost_access_log) {
145
+ File.join(apache_log_dir, "#{apache_vhost_domain}-access.log")
146
+ }
147
+ set(:apache_vhost_error_log) {
148
+ File.join(apache_log_dir, "#{apache_vhost_domain}-error.log")
149
+ }
150
+ set(:apache_vhost_document_root) {
151
+ File.join('/var/apps', "#{apache_vhost_domain}", 'public')
152
+ }
153
+ set :apache_vhost_rack_env, false
154
+ #
155
+ task :vhost do
156
+ file = {
157
+ :template => 'vhost.erb',
158
+ :path => "/etc/apache2/sites-available/#{apache_vhost_domain}",
159
+ :mode => 0644,
160
+ :owner => 'root:root'
161
+ }
162
+ if ! File.exists? 'config'
163
+ file[:path] = "../../#{apache_vhost_domain}"
164
+ end
165
+ deprec2.render_template(:apache, file)
182
166
  end
183
167
 
184
- task :restore, :roles => :web do
185
- # not yet implemented
186
- end
187
-
168
+ # End apache vhost extras
188
169
  end
189
170
  end
190
171
  end