Browse Source

FC003: Check before using server-specific features

Andrew Crump 13 years ago
parent
commit
7d8d1a3103
5 changed files with 47 additions and 27 deletions
  1. 11 7
      recipes/default.rb
  2. 9 5
      recipes/django.rb
  3. 9 5
      recipes/java_webapp.rb
  4. 9 5
      recipes/php.rb
  5. 9 5
      recipes/rails.rb

+ 11 - 7
recipes/default.rb

@@ -17,14 +17,18 @@
 # limitations under the License.
 #
 
-search(:apps) do |app|
-  (app["server_roles"] & node.run_list.roles).each do |app_role|
-    app["type"][app_role].each do |thing|
-      node.run_state['current_app'] = app
-      include_recipe "application::#{thing}"
+if Chef::Config[:solo]
+  Chef::Log.warn("This recipe uses search. Chef Solo does not support search.")
+else
+  search(:apps) do |app|
+    (app["server_roles"] & node.run_list.roles).each do |app_role|
+      app["type"][app_role].each do |thing|
+        node.run_state['current_app'] = app
+        include_recipe "application::#{thing}"
+      end
     end
   end
-end
 
-node.run_state.delete(:current_app)
+  node.run_state.delete(:current_app)
+end
 

+ 9 - 5
recipes/django.rb

@@ -106,11 +106,15 @@ if app["database_master_role"]
   if node.run_list.roles.include?(app["database_master_role"][0])
     dbm = node
   else
-  # Find the database master
-    results = search(:node, "role:#{app["database_master_role"][0]} AND chef_environment:#{node.chef_environment}", nil, 0, 1)
-    rows = results[0]
-    if rows.length == 1
-      dbm = rows[0]
+    if Chef::Config[:solo]
+      Chef::Log.warn("This recipe uses search. Chef Solo does not support search.")
+    else
+      # Find the database master
+      results = search(:node, "role:#{app["database_master_role"][0]} AND chef_environment:#{node.chef_environment}", nil, 0, 1)
+      rows = results[0]
+      if rows.length == 1
+        dbm = rows[0]
+      end
     end
   end
   

+ 9 - 5
recipes/java_webapp.rb

@@ -74,11 +74,15 @@ if app["database_master_role"]
   if node.run_list.roles.include?(app["database_master_role"][0])
     dbm = node
   else
-  # Find the database master
-    results = search(:node, "role:#{app["database_master_role"][0]} AND chef_environment:#{node.chef_environment}", nil, 0, 1)
-    rows = results[0]
-    if rows.length == 1
-      dbm = rows[0]
+    if Chef::Config[:solo]
+      Chef::Log.warn("This recipe uses search. Chef Solo does not support search.")
+    else
+      # Find the database master
+      results = search(:node, "role:#{app["database_master_role"][0]} AND chef_environment:#{node.chef_environment}", nil, 0, 1)
+      rows = results[0]
+      if rows.length == 1
+        dbm = rows[0]
+      end
     end
   end
 

+ 9 - 5
recipes/php.rb

@@ -97,11 +97,15 @@ if app["database_master_role"]
   if node.run_list.roles.include?(app["database_master_role"][0])
     dbm = node
   else
-  # Find the database master
-    results = search(:node, "role:#{app["database_master_role"][0]} AND chef_environment:#{node.chef_environment}", nil, 0, 1)
-    rows = results[0]
-    if rows.length == 1
-      dbm = rows[0]
+    if Chef::Config[:solo]
+      Chef::Log.warn("This recipe uses search. Chef Solo does not support search.")
+    else
+      # Find the database master
+      results = search(:node, "role:#{app["database_master_role"][0]} AND chef_environment:#{node.chef_environment}", nil, 0, 1)
+      rows = results[0]
+      if rows.length == 1
+        dbm = rows[0]
+      end
     end
   end
 

+ 9 - 5
recipes/rails.rb

@@ -106,11 +106,15 @@ if app["database_master_role"]
   if node.run_list.roles.include?(app["database_master_role"][0])
     dbm = node
   else
-  # Find the database master
-    results = search(:node, "role:#{app["database_master_role"][0]} AND chef_environment:#{node.chef_environment}", nil, 0, 1)
-    rows = results[0]
-    if rows.length == 1
-      dbm = rows[0]
+    if Chef::Config[:solo]
+      Chef::Log.warn("This recipe uses search. Chef Solo does not support search.")
+    else
+      # Find the database master
+      results = search(:node, "role:#{app["database_master_role"][0]} AND chef_environment:#{node.chef_environment}", nil, 0, 1)
+      rows = results[0]
+      if rows.length == 1
+        dbm = rows[0]
+      end
     end
   end