]> git.openstreetmap.org Git - chef.git/commitdiff
Use inline compile mode for apache LWRPs
authorTom Hughes <tom@compton.nu>
Tue, 10 Feb 2015 19:17:00 +0000 (19:17 +0000)
committerTom Hughes <tom@compton.nu>
Tue, 10 Feb 2015 19:17:00 +0000 (19:17 +0000)
cookbooks/apache/providers/conf.rb
cookbooks/apache/providers/module.rb
cookbooks/apache/providers/site.rb
cookbooks/apache/resources/conf.rb
cookbooks/apache/resources/module.rb
cookbooks/apache/resources/site.rb

index 489be8b84f4dee7ef5c3790b03b37f67dbaa9cd9..d7eddc6368a03abf20d11ba5f3fbdfbd6ba504e1 100644 (file)
@@ -21,6 +21,8 @@ def whyrun_supported?
   true
 end
 
+use_inline_resources
+
 action :create do # ~FC017
   if node[:lsb][:release].to_f >= 14.04
     create_conf
@@ -50,45 +52,34 @@ action :delete do # ~FC017
 end
 
 def create_conf
-  t = template available_name do
+  template available_name do
     cookbook new_resource.cookbook
     source new_resource.template
     owner "root"
     group "root"
     mode 0644
     variables new_resource.variables
-    notifies :reload, "service[apache2]" if enabled? || available_name == enabled_name
   end
-
-  new_resource.updated_by_last_action(t.updated_by_last_action?)
 end
 
 def enable_conf
-  l = link enabled_name do
+  link enabled_name do
     to available_name
     owner "root"
     group "root"
-    notifies :reload, "service[apache2]"
   end
-
-  new_resource.updated_by_last_action(l.updated_by_last_action?)
 end
 
 def disable_conf
-  l = link enabled_name do
+  link enabled_name do
     action :delete
-    notifies :reload, "service[apache2]"
   end
-
-  new_resource.updated_by_last_action(l.updated_by_last_action?)
 end
 
 def delete_conf
-  f = file available_name do
+  file available_name do
     action :delete
   end
-
-  new_resource.updated_by_last_action(f.updated_by_last_action?)
 end
 
 def available_name
@@ -106,7 +97,3 @@ def enabled_name
     "/etc/apache2/conf.d/#{new_resource.name}"
   end
 end
-
-def enabled?
-  ::File.exist?(enabled_name)
-end
index 0a85f7ee4ce1c004642a0d7837dae00f7043ce85..e824a03433e5d0e986d5be4fc82b3119165b31d9 100644 (file)
@@ -21,75 +21,52 @@ def whyrun_supported?
   true
 end
 
+use_inline_resources
+
 action :install do
-  if !installed?
+  unless installed?
     package package_name
-
-    updated = true
-  else
-    updated = false
   end
 
-  if new_resource.conf
-    t = template available_name("conf") do
+  if new_resource.conf # ~FC023
+    template available_name("conf") do
       source new_resource.conf
       owner "root"
       group "root"
       mode 0644
       variables new_resource.variables
-      notifies :reload, "service[apache2]" if enabled?
     end
-
-    updated ||= t.updated_by_last_action?
   end
-
-  new_resource.updated_by_last_action(updated)
 end
 
 action :enable do
-  unless enabled?
-    link enabled_name("load") do
-      to available_name("load")
-      owner "root"
-      group "root"
-      notifies :restart, "service[apache2]"
-    end
-
-    link enabled_name("conf") do
-      to available_name("conf")
-      owner "root"
-      group "root"
-      notifies :reload, "service[apache2]"
-      only_if { ::File.exist?(available_name("conf")) }
-    end
+  link enabled_name("load") do
+    to available_name("load")
+    owner "root"
+    group "root"
+  end
 
-    new_resource.updated_by_last_action(true)
+  link enabled_name("conf") do
+    to available_name("conf")
+    owner "root"
+    group "root"
+    only_if { ::File.exist?(available_name("conf")) }
   end
 end
 
 action :disable do
-  if enabled?
-    link enabled_name("load") do
-      action :delete
-      notifies :restart, "service[apache2]"
-    end
-
-    link enabled_name("conf") do
-      action :delete
-      notifies :reload, "service[apache2]"
-    end
+  link enabled_name("load") do
+    action :delete
+  end
 
-    new_resource.updated_by_last_action(true)
+  link enabled_name("conf") do
+    action :delete
   end
 end
 
 action :delete do
-  if installed?
-    package package_name do
-      action :remove
-    end
-
-    new_resource.updated_by_last_action(true)
+  package package_name do
+    action :remove
   end
 end
 
@@ -108,7 +85,3 @@ end
 def installed?
   ::File.exist?(available_name("load"))
 end
-
-def enabled?
-  ::File.exist?(enabled_name("load"))
-end
index 9c33032514f64ac553c0d00144d19ac4c73b07de..a8c90344927f818a25146df51470580db980c20b 100644 (file)
@@ -21,46 +21,37 @@ def whyrun_supported?
   true
 end
 
+use_inline_resources
+
 action :create do
-  t = template available_name do
+  template available_name do
     cookbook new_resource.cookbook
     source new_resource.template
     owner "root"
     group "root"
     mode 0644
     variables new_resource.variables.merge(:name => new_resource.name, :directory => site_directory)
-    notifies :reload, "service[apache2]" if enabled?
   end
-
-  new_resource.updated_by_last_action(t.updated_by_last_action?)
 end
 
 action :enable do
-  l = link enabled_name do
+  link enabled_name do
     to available_name
     owner "root"
     group "root"
-    notifies :reload, "service[apache2]"
   end
-
-  new_resource.updated_by_last_action(l.updated_by_last_action?)
 end
 
 action :disable do
-  l = link enabled_name do
+  link enabled_name do
     action :delete
-    notifies :reload, "service[apache2]"
   end
-
-  new_resource.updated_by_last_action(l.updated_by_last_action?)
 end
 
 action :delete do
-  f = file available_name do
+  file available_name do
     action :delete
   end
-
-  new_resource.updated_by_last_action(f.updated_by_last_action?)
 end
 
 def site_directory
@@ -92,7 +83,3 @@ def enabled_name
     end
   end
 end
-
-def enabled?
-  ::File.exist?(enabled_name)
-end
index e17d25bbba4e767d37039d49c80de64b2aa3dab1..a6487c98c4b2b8a02e0d9aed28e416c65eabb1be 100644 (file)
@@ -24,3 +24,8 @@ attribute :name, :kind_of => String, :name_attribute => true
 attribute :cookbook, :kind_of => String
 attribute :template, :kind_of => String, :required => true
 attribute :variables, :kind_of => Hash, :default => {}
+attribute :reload_apache, :kind_of => [TrueClass, FalseClass], :default => true
+
+def after_created
+  notifies :reload, "service[apache2]" if reload_apache
+end
index f2d95551ec486a42d7709d2cbf3aa4f4b95a5f93..cded39a47881394c141212fe36861af07d8be03a 100644 (file)
@@ -24,3 +24,8 @@ attribute :name, :kind_of => String, :name_attribute => true
 attribute :package, :kind_of => String
 attribute :conf, :kind_of => String
 attribute :variables, :kind_of => Hash, :default => {}
+attribute :restart_apache, :kind_of => [TrueClass, FalseClass], :default => true
+
+def after_created
+  notifies :restart, "service[apache2]" if restart_apache
+end
index d6735ba8fa7dca06a4eb12e2ab80d01590fba06c..0e6a2fedffdc7ef31588a5f4623d8f3514e8a697 100644 (file)
@@ -25,3 +25,8 @@ attribute :directory, :kind_of => String
 attribute :cookbook, :kind_of => String
 attribute :template, :kind_of => String, :required => true
 attribute :variables, :kind_of => Hash, :default => {}
+attribute :reload_apache, :kind_of => [TrueClass, FalseClass], :default => true
+
+def after_created
+  notifies :reload, "service[apache2]" if reload_apache
+end