diff --git a/Batali b/Batali index 2e532a8..e282b54 100644 --- a/Batali +++ b/Batali @@ -6,9 +6,6 @@ Batali.define do cookbook 'mediawiki', git: 'https://github.com/67P/mediawiki-cookbook.git', ref: 'nginx' - cookbook 'php-fpm', - git: 'https://github.com/67P/cookbook-php-fpm.git', - ref: 'ubuntu_systemd' cookbook 'wordpress', git: 'https://github.com/67P/wordpress-cookbook.git', ref: 'relax_dependencies' @@ -17,7 +14,9 @@ Batali.define do cookbook 'application_nodejs', git: 'https://github.com/67p/application_nodejs.git', ref: 'master' + cookbook 'php-fpm', '0.7.8' cookbook 'application', '4.1.6' + cookbook 'php', '~> 3.0.0' cookbook 'users' cookbook 'sudo' cookbook 'hostname' @@ -28,13 +27,16 @@ Batali.define do cookbook 'firewall' cookbook 'nginx' cookbook 'build-essential' - cookbook 'mysql' + cookbook 'mysql', '~> 8.3.0' cookbook 'database' - cookbook 'mysql2_chef_gem' + cookbook 'mysql2_chef_gem', '~> 2.0.1' cookbook 'omnibus_updater' cookbook 'timezone-ii' cookbook 'nodejs', '~> 3.0.0' cookbook 'ark' cookbook 'logrotate' + + # Unused + cookbook "yum-epel", '0.3.6' end diff --git a/batali.manifest b/batali.manifest index 47b4f56..46b106a 100644 --- a/batali.manifest +++ b/batali.manifest @@ -36,7 +36,7 @@ "version": "0.2.0", "source": { "url": "https://github.com/67P/mediawiki-cookbook.git", - "ref": "b76104ab975ed95e238c10ae49722f0dacd7c0b2", + "ref": "41d3c5129b5a6cd9c473e99339885bc1feac5d57", "type": "Batali::Source::Git", "subdirectory": null } @@ -73,19 +73,19 @@ ">= 0.0.0" ], [ - "windows", + "iis", ">= 0.0.0" ], [ - "iis", + "windows", ">= 0.0.0" ] ], - "version": "1.7.2", + "version": "3.0.0", "source": { "type": "Batali::Source::Site", - "url": "https://supermarket.chef.io:443/api/v1/cookbooks/php/versions/1.7.2/download", - "version": "1.7.2" + "url": "https://supermarket.chef.io:443/api/v1/cookbooks/php/versions/3.0.0/download", + "version": "3.0.0" } }, { @@ -198,35 +198,28 @@ { "name": "mysql", "dependencies": [ - [ - "yum-mysql-community", - ">= 0.0.0" - ], - [ - "smf", - ">= 0.0.0" - ] + ], - "version": "6.1.3", + "version": "8.3.0", "source": { "type": "Batali::Source::Site", - "url": "https://supermarket.chef.io:443/api/v1/cookbooks/mysql/versions/6.1.3/download", - "version": "6.1.3" + "url": "https://supermarket.chef.io:443/api/v1/cookbooks/mysql/versions/8.3.0/download", + "version": "8.3.0" } }, { - "name": "yum-mysql-community", + "name": "yum-epel", "dependencies": [ [ "yum", - ">= 3.2" + "~> 3.0" ] ], - "version": "0.1.21", + "version": "0.3.6", "source": { "type": "Batali::Source::Site", - "url": "https://supermarket.chef.io:443/api/v1/cookbooks/yum-mysql-community/versions/0.1.21/download", - "version": "0.1.21" + "url": "https://supermarket.chef.io:443/api/v1/cookbooks/yum-epel/versions/0.3.6/download", + "version": "0.3.6" } }, { @@ -234,65 +227,11 @@ "dependencies": [ ], - "version": "5.0.0", + "version": "3.13.0", "source": { "type": "Batali::Source::Site", - "url": "https://supermarket.chef.io:443/api/v1/cookbooks/yum/versions/5.0.0/download", - "version": "5.0.0" - } - }, - { - "name": "smf", - "dependencies": [ - [ - "rbac", - ">= 1.0.1" - ] - ], - "version": "2.2.8", - "source": { - "type": "Batali::Source::Site", - "url": "https://supermarket.chef.io:443/api/v1/cookbooks/smf/versions/2.2.8/download", - "version": "2.2.8" - } - }, - { - "name": "rbac", - "dependencies": [ - - ], - "version": "1.0.3", - "source": { - "type": "Batali::Source::Site", - "url": "https://supermarket.chef.io:443/api/v1/cookbooks/rbac/versions/1.0.3/download", - "version": "1.0.3" - } - }, - { - "name": "yum-epel", - "dependencies": [ - [ - "compat_resource", - ">= 12.16.3" - ] - ], - "version": "2.1.1", - "source": { - "type": "Batali::Source::Site", - "url": "https://supermarket.chef.io:443/api/v1/cookbooks/yum-epel/versions/2.1.1/download", - "version": "2.1.1" - } - }, - { - "name": "compat_resource", - "dependencies": [ - - ], - "version": "12.16.3", - "source": { - "type": "Batali::Source::Site", - "url": "https://supermarket.chef.io:443/api/v1/cookbooks/compat_resource/versions/12.16.3/download", - "version": "12.16.3" + "url": "https://supermarket.chef.io:443/api/v1/cookbooks/yum/versions/3.13.0/download", + "version": "3.13.0" } }, { @@ -506,42 +445,27 @@ "version": "0.2.0" } }, - { - "name": "yum-epel", - "dependencies": [ - [ - "yum", - ">= 3.6.3" - ] - ], - "version": "0.7.1", - "source": { - "type": "Batali::Source::Site", - "url": "https://supermarket.chef.io:443/api/v1/cookbooks/yum-epel/versions/0.7.1/download", - "version": "0.7.1" - } - }, { "name": "mysql2_chef_gem", "dependencies": [ [ "build-essential", - ">= 0.0.0" + ">= 2.4.0" ], [ "mysql", - "~> 6.0" + ">= 8.2.0" ], [ "mariadb", ">= 0.0.0" ] ], - "version": "1.0.2", + "version": "2.0.1", "source": { "type": "Batali::Source::Site", - "url": "https://supermarket.chef.io:443/api/v1/cookbooks/mysql2_chef_gem/versions/1.0.2/download", - "version": "1.0.2" + "url": "https://supermarket.chef.io:443/api/v1/cookbooks/mysql2_chef_gem/versions/2.0.1/download", + "version": "2.0.1" } }, { @@ -572,19 +496,18 @@ "dependencies": [ [ "apt", - "> 0" + ">= 0.0.0" ], [ "yum", ">= 3.0" ] ], - "version": "0.7.5", + "version": "0.7.8", "source": { - "url": "https://github.com/67P/cookbook-php-fpm.git", - "ref": "00ae43a225cf23fd3ed937f27ab25aba8d812db9", - "type": "Batali::Source::Git", - "subdirectory": null + "type": "Batali::Source::Site", + "url": "https://supermarket.chef.io:443/api/v1/cookbooks/php-fpm/versions/0.7.8/download", + "version": "0.7.8" } }, { @@ -612,7 +535,7 @@ ], [ "mysql2_chef_gem", - "~> 1.0.1" + ">= 1.0.1" ], [ "build-essential", @@ -642,7 +565,7 @@ "version": "3.0.0", "source": { "url": "https://github.com/67P/wordpress-cookbook.git", - "ref": "bc6a108fcfb05c3fafd903bcf81ac33617e6cef9", + "ref": "d6401db517476e6f3ab36aa92dfc0f5ed6a8a264", "type": "Batali::Source::Git", "subdirectory": null } diff --git a/cookbooks/compat_resource/CHANGELOG.md b/cookbooks/compat_resource/CHANGELOG.md deleted file mode 100644 index 592b3b8..0000000 --- a/cookbooks/compat_resource/CHANGELOG.md +++ /dev/null @@ -1,48 +0,0 @@ -# compat_resource Cookbook CHANGELOG - -This file is used to list changes made in each version of the compat_resource cookbook. - -## 12.16.2 (2016-11-09) - -- Sync chef-client changes from Chef 12.16.42 - -## 12.16.1 (2016-10-20) - -- add delayed_action helper - -## 12.16.0 (2016-10-19) - -- Sync chef-client changes from Chef 12.16.14 - -## 12.14.7 (2016-09-26) - -- Update to 12.14.89 Chef -- Fix autoload by applying fix from #106 - -## 12.14.6 (2016-09-20) - -- Update backported codebase to Chef 12.14.77 which brings in yum_repository updates and why-run enabled by default in custom resources - -## 12.14.5 (2016-09-19) - -- Prevent spamming messages in Chefspec runs for cookbooks that depend on compat_resource - -## 12.14.4 (2016-09-19) - -- Fix delayed notifications cloning - -## 12.14.3 (2016-09-12) - -- Fix subscribes notifications - -## 12.14.2 (2016-09-09) - -- Improve documentation -- keep ChefCompat::Resource defined even if we don't load - -## 12.14.1 (2016-09-07) - -- add yum_repository resource from Chef 12.14 -- Update the minimum chef version in the metadata to 12.1 -- Added maintainers files -- suppress constant redef warnings when running chefspec diff --git a/cookbooks/compat_resource/README.md b/cookbooks/compat_resource/README.md deleted file mode 100644 index f5c17e5..0000000 --- a/cookbooks/compat_resource/README.md +++ /dev/null @@ -1,60 +0,0 @@ -# compat_resource cookbook - -[![Build Status](https://travis-ci.org/chef-cookbooks/compat_resource.svg?branch=master)](https://travis-ci.org/chef-cookbooks/compat_resource) [![Cookbook Version](https://img.shields.io/cookbook/v/compat_resource.svg)](https://supermarket.chef.io/cookbooks/compat_resource) - -This cookbook backports functionality introduced in the latest chef-client releases to any chef-client from 12.1 onwards. This includes [Custom Resource](https://docs.chef.io/custom_resources.html) functionality, notification improvements, as well as new resources added to core chef. It allows for the usage of these new resources in cookbooks without requiring the very latest Chef client release. - -## Backported functionality - -- [Custom Resources](https://docs.chef.io/custom_resources.html) -- [apt_repository](https://docs.chef.io/resource_apt_repository.html) -- [apt_update](https://docs.chef.io/resource_apt_update.html) -- [systemd_unit](https://docs.chef.io/resource_systemd_unit.html) -- [yum_repository](https://docs.chef.io/resource_yum_repository.html) -- [:before notifications](https://docs.chef.io/resources.html#timers) - -## Requirements - -### Platforms - -- All platforms supported by Chef - -### Chef - -- Chef 12.1+ - -### Cookbooks - -- none - -## Usage - -To use this cookbook, put `depends 'compat_resource'` in the metadata.rb of your cookbook. Once this is done, you can use all the new custom resource features to define resources. It Just Works. - -## Custom Resources? - -Curious about how to use custom resources? - -- Docs: -- Slides: - -## License & Authors - -- Author:: Lamont Granquist ([lamont@chef.io](mailto:lamont@chef.io)) -- Author:: John Keiser ([jkeiser@chef.io](mailto:jkeiser@chef.io)) - -```text -Copyright:: 2015-2016 Chef Software, Inc. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -``` diff --git a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef.rb b/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef.rb deleted file mode 100644 index 219b05b..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef.rb +++ /dev/null @@ -1,29 +0,0 @@ -module ChefCompat - module CopiedFromChef - def self.extend_chef_module(chef_module, target) - target.instance_eval do - include chef_module - @chef_module = chef_module - def self.method_missing(name, *args, &block) - @chef_module.send(name, *args, &block) - end - def self.const_missing(name) - @chef_module.const_get(name) - end - end - end - - # This patch to CopiedFromChef's ActionClass is necessary for the include to work - require 'chef/resource' - class Chef < ::Chef - class Resource < ::Chef::Resource - module ActionClass - def self.use_inline_resources - end - def self.include_resource_dsl(include_resource_dsl) - end - end - end - end - end -end diff --git a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/constants.rb b/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/constants.rb deleted file mode 100644 index 4acd742..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/constants.rb +++ /dev/null @@ -1,47 +0,0 @@ -# -# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE -# -# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!! -# -# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE -# - -begin - require 'chef/constants' -rescue LoadError; end - -require 'chef_compat/copied_from_chef' -class Chef -module ::ChefCompat -module CopiedFromChef -# -# Author:: John Keiser -# Copyright:: Copyright 2015-2016, Chef Software Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -class Chef < (defined?(::Chef) ? ::Chef : Object) - NOT_PASSED = Object.new - def NOT_PASSED.to_s - "NOT_PASSED" - end - - def NOT_PASSED.inspect - to_s - end - NOT_PASSED.freeze -end -end -end -end diff --git a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/delayed_evaluator.rb b/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/delayed_evaluator.rb deleted file mode 100644 index 4fb687e..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/delayed_evaluator.rb +++ /dev/null @@ -1,40 +0,0 @@ -# -# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE -# -# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!! -# -# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE -# - -begin - require 'chef/delayed_evaluator' -rescue LoadError; end - -require 'chef_compat/copied_from_chef' -class Chef -module ::ChefCompat -module CopiedFromChef -# -# Author:: John Keiser -# Copyright:: Copyright 2015-2016, Chef Software Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -class Chef < (defined?(::Chef) ? ::Chef : Object) - class DelayedEvaluator < (defined?(::Chef::DelayedEvaluator) ? ::Chef::DelayedEvaluator : Proc) - end -end -end -end -end diff --git a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/dsl/core.rb b/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/dsl/core.rb deleted file mode 100644 index 8e30d30..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/dsl/core.rb +++ /dev/null @@ -1,73 +0,0 @@ -# -# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE -# -# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!! -# -# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE -# - -begin - require 'chef/dsl/core' -rescue LoadError; end - -require 'chef_compat/copied_from_chef' -class Chef -module ::ChefCompat -module CopiedFromChef -#-- -# Author:: Adam Jacob () -# Author:: Christopher Walters () -# Copyright:: Copyright 2008-2016 Chef Software, Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -require "chef_compat/copied_from_chef/chef/dsl/declare_resource" -require "chef_compat/copied_from_chef/chef/dsl/universal" -require "chef_compat/copied_from_chef/chef/mixin/notifying_block" -require "chef_compat/copied_from_chef/chef/mixin/lazy_module_include" - -class Chef < (defined?(::Chef) ? ::Chef : Object) - module DSL - CopiedFromChef.extend_chef_module(::Chef::DSL, self) if defined?(::Chef::DSL) - # Part of a family of DSL mixins. - # - # Chef::DSL::Recipe mixes into Recipes and LWRP Providers. - # - this does not target core chef resources and providers. - # - this is restricted to recipe/resource/provider context where a resource collection exists. - # - cookbook authors should typically include modules into here. - # - # Chef::DSL::Core mixes into Recipes, LWRP Providers and Core Providers - # - this adds cores providers on top of the Recipe DSL. - # - this is restricted to recipe/resource/provider context where a resource collection exists. - # - core chef authors should typically include modules into here. - # - # Chef::DSL::Universal mixes into Recipes, LWRP Resources+Providers, Core Resources+Providers, and Attributes files. - # - this adds resources and attributes files. - # - do not add helpers which manipulate the resource collection. - # - this is for general-purpose stuff that is useful nearly everywhere. - # - it also pollutes the namespace of nearly every context, watch out. - # - module Core - CopiedFromChef.extend_chef_module(::Chef::DSL::Core, self) if defined?(::Chef::DSL::Core) - include Chef::DSL::Universal - include Chef::DSL::DeclareResource - include Chef::Mixin::NotifyingBlock - extend Chef::Mixin::LazyModuleInclude - end - end -end -end -end -end diff --git a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/dsl/declare_resource.rb b/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/dsl/declare_resource.rb deleted file mode 100644 index 45e69dc..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/dsl/declare_resource.rb +++ /dev/null @@ -1,315 +0,0 @@ -# -# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE -# -# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!! -# -# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE -# - -begin - require 'chef/dsl/declare_resource' -rescue LoadError; end - -require 'chef_compat/copied_from_chef' -class Chef -module ::ChefCompat -module CopiedFromChef -#-- -# Author:: Adam Jacob () -# Author:: Christopher Walters -# Copyright:: Copyright 2008-2016 Chef Software, Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - - -class Chef < (defined?(::Chef) ? ::Chef : Object) - module DSL - CopiedFromChef.extend_chef_module(::Chef::DSL, self) if defined?(::Chef::DSL) - module DeclareResource - CopiedFromChef.extend_chef_module(::Chef::DSL::DeclareResource, self) if defined?(::Chef::DSL::DeclareResource) - - # Helper for switching run_contexts. Allows for using :parent or :root in place of - # passing the run_context. Executes the block in the run_context. Returns the return - # value of the passed block. - # - # @param rc [Chef::RunContext,Symbol] Either :root, :parent or a Chef::RunContext - # - # @return return value of the block - # - # @example - # # creates/returns a 'service[foo]' resource in the root run_context - # resource = with_run_context(:root) - # edit_resource(:service, "foo") do - # action :nothing - # end - # end - # - def with_run_context(rc) - raise ArgumentError, "with_run_context is useless without a block" unless block_given? - old_run_context = @run_context - @run_context = - case rc - when Chef::RunContext - rc - when :root - run_context.root_run_context - when :parent - run_context.parent_run_context - else - raise ArgumentError, "bad argument to run_context helper, must be :root, :parent, or a Chef::RunContext" - end - yield - ensure - @run_context = old_run_context - end - - # Lookup a resource in the resource collection by name and delete it. This - # will raise Chef::Exceptions::ResourceNotFound if the resource is not found. - # - # @param type [Symbol] The type of resource (e.g. `:file` or `:package`) - # @param name [String] The name of the resource (e.g. '/x/y.txt' or 'apache2') - # @param run_context [Chef::RunContext] the run_context of the resource collection to operate on - # - # @return [Chef::Resource] The resource - # - # @example - # delete_resource!(:template, '/x/y.txy') - # - def delete_resource!(type, name, run_context: self.run_context) - run_context.resource_collection.delete("#{type}[#{name}]").tap do |resource| - # Purge any pending notifications too. This will not raise an exception - # if there are no notifications. - if resource - run_context.before_notification_collection.delete(resource.declared_key) - run_context.immediate_notification_collection.delete(resource.declared_key) - run_context.delayed_notification_collection.delete(resource.declared_key) - end - end - end - - # Lookup a resource in the resource collection by name and delete it. Returns - # nil if the resource is not found and should not fail. - # - # @param type [Symbol] The type of resource (e.g. `:file` or `:package`) - # @param name [String] The name of the resource (e.g. '/x/y.txt' or 'apache2') - # @param run_context [Chef::RunContext] the run_context of the resource collection to operate on - # - # @return [Chef::Resource] The resource - # - # @example - # delete_resource(:template, '/x/y.txy') - # - def delete_resource(type, name, run_context: self.run_context) - delete_resource!(type, name, run_context: run_context) - rescue Chef::Exceptions::ResourceNotFound - nil - end - - # Lookup a resource in the resource collection by name and edit the resource. If the resource is not - # found this will raise Chef::Exceptions::ResourceNotFound. This is the correct API to use for - # "chef_rewind" functionality. - # - # @param type [Symbol] The type of resource (e.g. `:file` or `:package`) - # @param name [String] The name of the resource (e.g. '/x/y.txt' or 'apache2') - # @param run_context [Chef::RunContext] the run_context of the resource collection to operate on - # @param resource_attrs_block A block that lets you set attributes of the - # resource (it is instance_eval'd on the resource instance). - # - # @return [Chef::Resource] The updated resource - # - # @example - # edit_resource!(:template, '/x/y.txy') do - # cookbook_name: cookbook_name - # end - # - def edit_resource!(type, name, created_at = nil, run_context: self.run_context, &resource_attrs_block) - resource = find_resource!(type, name, run_context: run_context) - if resource_attrs_block - if defined?(new_resource) - resource.instance_exec(new_resource, &resource_attrs_block) - else - resource.instance_exec(&resource_attrs_block) - end - end - resource - end - - # Lookup a resource in the resource collection by name. If it exists, - # return it. If it does not exist, create it. This is a useful function - # for accumulator patterns. In CRUD terminology this is an "upsert" operation and is - # used to assert that the resource must exist with the specified properties. - # - # @param type [Symbol] The type of resource (e.g. `:file` or `:package`) - # @param name [String] The name of the resource (e.g. '/x/y.txt' or 'apache2') - # @param created_at [String] The caller of the resource. Use `caller[0]` - # to get the caller of your function. Defaults to the caller of this - # function. - # @param run_context [Chef::RunContext] the run_context of the resource collection to operate on - # @param resource_attrs_block A block that lets you set attributes of the - # resource (it is instance_eval'd on the resource instance). - # - # @return [Chef::Resource] The updated or created resource - # - # @example - # resource = edit_resource(:template, '/x/y.txy') do - # source "y.txy.erb" - # variables {} - # end - # resource.variables.merge!({ home: "/home/klowns" }) - # - def edit_resource(type, name, created_at = nil, run_context: self.run_context, &resource_attrs_block) - edit_resource!(type, name, created_at, run_context: run_context, &resource_attrs_block) - rescue Chef::Exceptions::ResourceNotFound - declare_resource(type, name, created_at, run_context: run_context, &resource_attrs_block) - end - - # Lookup a resource in the resource collection by name. If the resource is not - # found this will raise Chef::Exceptions::ResourceNotFound. This API is identical to the - # resources() call and while it is a synonym it is not intended to deprecate that call. - # - # @param type [Symbol] The type of resource (e.g. `:file` or `:package`) - # @param name [String] The name of the resource (e.g. '/x/y.txt' or 'apache2') - # @param run_context [Chef::RunContext] the run_context of the resource collection to operate on - # - # @return [Chef::Resource] The updated resource - # - # @example - # resource = find_resource!(:template, '/x/y.txy') - # - def find_resource!(type, name, run_context: self.run_context) - raise ArgumentError, "find_resource! does not take a block" if block_given? - run_context.resource_collection.find(type => name) - end - - # Lookup a resource in the resource collection by name. If the resource is not found - # the will be no exception raised and the call will return nil. If a block is given and - # no resource is found it will create the resource using the block, if the resource is - # found then the block will not be applied. The block version is similar to create_if_missing - # - # @param type [Symbol] The type of resource (e.g. `:file` or `:package`) - # @param name [String] The name of the resource (e.g. '/x/y.txt' or 'apache2') - # @param run_context [Chef::RunContext] the run_context of the resource collection to operate on - # - # @return [Chef::Resource] The updated resource - # - # @example - # if ( find_resource(:template, '/x/y.txy') ) - # # do something - # else - # # don't worry about the error - # end - # - # @example - # # this API can be used to return a resource from an outer run context, and will only create - # # an action :nothing service if one does not already exist. - # resource = with_run_context(:root) do - # find_resource(:service, 'whatever') do - # action :nothing - # end - # end - # - def find_resource(type, name, created_at: nil, run_context: self.run_context, &resource_attrs_block) - find_resource!(type, name, run_context: run_context) - rescue Chef::Exceptions::ResourceNotFound - if resource_attrs_block - declare_resource(type, name, created_at, run_context: run_context, &resource_attrs_block) - end # returns nil otherwise - end - - # Instantiates a resource (via #build_resource), then adds it to the - # resource collection. Note that resource classes are looked up directly, - # so this will create the resource you intended even if the method name - # corresponding to that resource has been overridden. - # - # @param type [Symbol] The type of resource (e.g. `:file` or `:package`) - # @param name [String] The name of the resource (e.g. '/x/y.txt' or 'apache2') - # @param created_at [String] The caller of the resource. Use `caller[0]` - # to get the caller of your function. Defaults to the caller of this - # function. - # @param run_context [Chef::RunContext] the run_context of the resource collection to operate on - # @param resource_attrs_block A block that lets you set attributes of the - # resource (it is instance_eval'd on the resource instance). - # - # @return [Chef::Resource] The new resource. - # - # @example - # declare_resource(:file, '/x/y.txy', caller[0]) do - # action :delete - # end - # # Equivalent to - # file '/x/y.txt' do - # action :delete - # end - # - def declare_resource(type, name, created_at = nil, run_context: self.run_context, create_if_missing: false, &resource_attrs_block) - created_at ||= caller[0] - - if create_if_missing - Chef::Log.deprecation "build_resource with a create_if_missing flag is deprecated, use edit_resource instead" - # midly goofy since we call edit_resource only to re-call ourselves, but that's why its deprecated... - return edit_resource(type, name, created_at, run_context: run_context, &resource_attrs_block) - end - - resource = build_resource(type, name, created_at, &resource_attrs_block) - - run_context.resource_collection.insert(resource, resource_type: type, instance_name: name) - resource - end - - # Instantiate a resource of the given +type+ with the given +name+ and - # attributes as given in the +resource_attrs_block+. - # - # The resource is NOT added to the resource collection. - # - # @param type [Symbol] The type of resource (e.g. `:file` or `:package`) - # @param name [String] The name of the resource (e.g. '/x/y.txt' or 'apache2') - # @param created_at [String] The caller of the resource. Use `caller[0]` - # to get the caller of your function. Defaults to the caller of this - # function. - # @param run_context [Chef::RunContext] the run_context of the resource collection to operate on - # @param resource_attrs_block A block that lets you set attributes of the - # resource (it is instance_eval'd on the resource instance). - # - # @return [Chef::Resource] The new resource. - # - # @example - # build_resource(:file, '/x/y.txy', caller[0]) do - # action :delete - # end - # - def build_resource(type, name, created_at = nil, run_context: self.run_context, &resource_attrs_block) - created_at ||= caller[0] - - # this needs to be lazy in order to avoid circular dependencies since ResourceBuilder - # will requires the entire provider+resolver universe - require "chef_compat/copied_from_chef/chef/resource_builder" unless defined?(Chef::ResourceBuilder) - - Chef::ResourceBuilder.new( - type: type, - name: name, - created_at: created_at, - params: @params, - run_context: run_context, - cookbook_name: cookbook_name, - recipe_name: recipe_name, - enclosing_provider: self.is_a?(Chef::Provider) ? self : nil - ).build(&resource_attrs_block) - end - end - end -end -end -end -end diff --git a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/dsl/platform_introspection.rb b/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/dsl/platform_introspection.rb deleted file mode 100644 index 7886000..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/dsl/platform_introspection.rb +++ /dev/null @@ -1,292 +0,0 @@ -# -# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE -# -# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!! -# -# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE -# - -begin - require 'chef/dsl/platform_introspection' -rescue LoadError; end - -require 'chef_compat/copied_from_chef' -class Chef -module ::ChefCompat -module CopiedFromChef -# -# Author:: Adam Jacob () -# Copyright:: Copyright 2008-2016, Chef Software Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -class Chef < (defined?(::Chef) ? ::Chef : Object) - module DSL - CopiedFromChef.extend_chef_module(::Chef::DSL, self) if defined?(::Chef::DSL) - - # == Chef::DSL::PlatformIntrospection - # Provides the DSL for platform-dependent switch logic, such as - # #value_for_platform. - module PlatformIntrospection - CopiedFromChef.extend_chef_module(::Chef::DSL::PlatformIntrospection, self) if defined?(::Chef::DSL::PlatformIntrospection) - - # Implementation class for determining platform dependent values - class PlatformDependentValue < (defined?(::Chef::DSL::PlatformIntrospection::PlatformDependentValue) ? ::Chef::DSL::PlatformIntrospection::PlatformDependentValue : Object) - - # Create a platform dependent value object. - # === Arguments - # platform_hash (Hash) a hash of the same structure as Chef::Platform, - # like this: - # { - # :debian => {:default => 'the value for all debian'} - # [:centos, :redhat, :fedora] => {:default => "value for all EL variants"} - # :ubuntu => { :default => "default for ubuntu", '10.04' => "value for 10.04 only"}, - # :default => "the default when nothing else matches" - # } - # * platforms can be specified as Symbols or Strings - # * multiple platforms can be grouped by using an Array as the key - # * values for platforms need to be Hashes of the form: - # {platform_version => value_for_that_version} - # * the exception to the above is the default value, which is given as - # :default => default_value - def initialize(platform_hash) -super if defined?(::Chef::DSL::PlatformIntrospection::PlatformDependentValue) - @values = {} - platform_hash.each { |platforms, value| set(platforms, value) } - end - - def value_for_node(node) - platform, version = node[:platform].to_s, node[:platform_version].to_s - # Check if we match a version constraint via Chef::VersionConstraint::Platform and Chef::Version::Platform - matched_value = match_versions(node) - if @values.key?(platform) && @values[platform].key?(version) - @values[platform][version] - elsif matched_value - matched_value - elsif @values.key?(platform) && @values[platform].key?("default") - @values[platform]["default"] - elsif @values.key?("default") - @values["default"] - else - nil - end - end - - private - - def match_versions(node) - begin - platform, version = node[:platform].to_s, node[:platform_version].to_s - return nil unless @values.key?(platform) - node_version = Chef::Version::Platform.new(version) - key_matches = [] - keys = @values[platform].keys - keys.each do |k| - begin - if Chef::VersionConstraint::Platform.new(k).include?(node_version) - key_matches << k - end - rescue Chef::Exceptions::InvalidVersionConstraint => e - Chef::Log.debug "Caught InvalidVersionConstraint. This means that a key in value_for_platform cannot be interpreted as a Chef::VersionConstraint::Platform." - Chef::Log.debug(e) - end - end - return @values[platform][version] if key_matches.include?(version) - case key_matches.length - when 0 - return nil - when 1 - return @values[platform][key_matches.first] - else - raise "Multiple matches detected for #{platform} with values #{@values}. The matches are: #{key_matches}" - end - rescue Chef::Exceptions::InvalidCookbookVersion => e - # Lets not break because someone passes a weird string like 'default' :) - Chef::Log.debug(e) - Chef::Log.debug "InvalidCookbookVersion exceptions are common and expected here: the generic constraint matcher attempted to match something which is not a constraint. Moving on to next version or constraint" - return nil - rescue Chef::Exceptions::InvalidPlatformVersion => e - Chef::Log.debug "Caught InvalidPlatformVersion, this means that Chef::Version::Platform does not know how to turn #{node_version} into an x.y.z format" - Chef::Log.debug(e) - return nil - end - end - - def set(platforms, value) - if platforms.to_s == "default" - @values["default"] = value - else - assert_valid_platform_values!(platforms, value) - Array(platforms).each { |platform| @values[platform.to_s] = normalize_keys(value) } - value - end - end - - def normalize_keys(hash) - hash.inject({}) do |h, key_value| - keys, value = *key_value - Array(keys).each do |key| - h[key.to_s] = value - end - h - end - end - - def assert_valid_platform_values!(platforms, value) - unless value.kind_of?(Hash) - msg = "platform dependent values must be specified in the format :platform => {:version => value} " - msg << "you gave a value #{value.inspect} for platform(s) #{platforms}" - raise ArgumentError, msg - end - end - end - - # Given a hash similar to the one we use for Platforms, select a value from the hash. Supports - # per platform defaults, along with a single base default. Arrays may be passed as hash keys and - # will be expanded. - # - # === Parameters - # platform_hash:: A platform-style hash. - # - # === Returns - # value:: Whatever the most specific value of the hash is. - def value_for_platform(platform_hash) - PlatformDependentValue.new(platform_hash).value_for_node(node) - end - - # Given a list of platforms, returns true if the current recipe is being run on a node with - # that platform, false otherwise. - # - # === Parameters - # args:: A list of platforms. Each platform can be in string or symbol format. - # - # === Returns - # true:: If the current platform is in the list - # false:: If the current platform is not in the list - def platform?(*args) - has_platform = false - - args.flatten.each do |platform| - has_platform = true if platform.to_s == node[:platform] - end - - has_platform - end - - # Implementation class for determining platform family dependent values - class PlatformFamilyDependentValue < (defined?(::Chef::DSL::PlatformIntrospection::PlatformFamilyDependentValue) ? ::Chef::DSL::PlatformIntrospection::PlatformFamilyDependentValue : Object) - - # Create a platform family dependent value object. - # === Arguments - # platform_family_hash (Hash) a map of platform families to values. - # like this: - # { - # :rhel => "value for all EL variants" - # :fedora => "value for fedora variants fedora and amazon" , - # [:fedora, :rhel] => "value for all known redhat variants" - # :debian => "value for debian variants including debian, ubuntu, mint" , - # :default => "the default when nothing else matches" - # } - # * platform families can be specified as Symbols or Strings - # * multiple platform families can be grouped by using an Array as the key - # * values for platform families can be any object, with no restrictions. Some examples: - # - [:stop, :start] - # - "mysql-devel" - # - { :key => "value" } - def initialize(platform_family_hash) -super if defined?(::Chef::DSL::PlatformIntrospection::PlatformFamilyDependentValue) - @values = {} - @values["default"] = nil - platform_family_hash.each { |platform_families, value| set(platform_families, value) } - end - - def value_for_node(node) - if node.key?(:platform_family) - platform_family = node[:platform_family].to_s - if @values.key?(platform_family) - @values[platform_family] - else - @values["default"] - end - else - @values["default"] - end - end - - private - - def set(platform_family, value) - if platform_family.to_s == "default" - @values["default"] = value - else - Array(platform_family).each { |family| @values[family.to_s] = value } - value - end - end - end - - # Given a hash mapping platform families to values, select a value from the hash. Supports a single - # base default if platform family is not in the map. Arrays may be passed as hash keys and will be - # expanded - # - # === Parameters - # platform_family_hash:: A hash in the form { platform_family_name => value } - # - # === Returns - # value:: Whatever the most specific value of the hash is. - def value_for_platform_family(platform_family_hash) - PlatformFamilyDependentValue.new(platform_family_hash).value_for_node(node) - end - - # Given a list of platform families, returns true if the current recipe is being run on a - # node within that platform family, false otherwise. - # - # === Parameters - # args:: A list of platform families. Each platform family can be in string or symbol format. - # - # === Returns - # true:: if the current node platform family is in the list. - # false:: if the current node platform family is not in the list. - def platform_family?(*args) - args.flatten.any? do |platform_family| - platform_family.to_s == node[:platform_family] - end - end - - # Shamelessly stolen from https://github.com/sethvargo/chef-sugar/blob/master/lib/chef/sugar/docker.rb - # Given a node object, returns whether the node is a docker container. - # - # === Parameters - # node:: [Chef::Node] The node to check. - # - # === Returns - # true:: if the current node is a docker container - # false:: if the current node is not a docker container - def docker?(node = run_context.nil? ? nil : run_context.node) - # Using "File.exist?('/.dockerinit') || File.exist?('/.dockerenv')" makes Travis sad, - # and that makes us sad too. - node && node[:virtualization] && node[:virtualization][:systems] && - node[:virtualization][:systems][:docker] && node[:virtualization][:systems][:docker] == "guest" - end - - end - end -end - -# **DEPRECATED** -# This used to be part of chef/mixin/language. Load the file to activate the deprecation code. -end -end -end diff --git a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/dsl/recipe.rb b/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/dsl/recipe.rb deleted file mode 100644 index f896ec7..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/dsl/recipe.rb +++ /dev/null @@ -1,37 +0,0 @@ -# -# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE -# -# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!! -# -# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE -# - -begin - require 'chef/dsl/recipe' -rescue LoadError; end - -require 'chef_compat/copied_from_chef' -class Chef -module ::ChefCompat -module CopiedFromChef -require "chef_compat/copied_from_chef/chef/dsl/core" -require "chef_compat/copied_from_chef/chef/mixin/lazy_module_include" -class Chef < (defined?(::Chef) ? ::Chef : Object) - module DSL - CopiedFromChef.extend_chef_module(::Chef::DSL, self) if defined?(::Chef::DSL) - module Recipe - CopiedFromChef.extend_chef_module(::Chef::DSL::Recipe, self) if defined?(::Chef::DSL::Recipe) - include Chef::DSL::Core - extend Chef::Mixin::LazyModuleInclude - module FullDSL - CopiedFromChef.extend_chef_module(::Chef::DSL::Recipe::FullDSL, self) if defined?(::Chef::DSL::Recipe::FullDSL) - include Chef::DSL::Recipe - extend Chef::Mixin::LazyModuleInclude - end - end - end -end -require "chef_compat/copied_from_chef/chef/resource" -end -end -end diff --git a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/dsl/universal.rb b/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/dsl/universal.rb deleted file mode 100644 index 7f529f1..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/dsl/universal.rb +++ /dev/null @@ -1,70 +0,0 @@ -# -# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE -# -# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!! -# -# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE -# - -begin - require 'chef/dsl/universal' -rescue LoadError; end - -require 'chef_compat/copied_from_chef' -class Chef -module ::ChefCompat -module CopiedFromChef -#-- -# Author:: Adam Jacob () -# Author:: Christopher Walters () -# Copyright:: Copyright 2008-2016 Chef Software, Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -require "chef_compat/copied_from_chef/chef/dsl/platform_introspection" -require "chef_compat/copied_from_chef/chef/mixin/powershell_out" - -class Chef < (defined?(::Chef) ? ::Chef : Object) - module DSL - CopiedFromChef.extend_chef_module(::Chef::DSL, self) if defined?(::Chef::DSL) - # Part of a family of DSL mixins. - # - # Chef::DSL::Recipe mixes into Recipes and LWRP Providers. - # - this does not target core chef resources and providers. - # - this is restricted to recipe/resource/provider context where a resource collection exists. - # - cookbook authors should typically include modules into here. - # - # Chef::DSL::Core mixes into Recipes, LWRP Providers and Core Providers - # - this adds cores providers on top of the Recipe DSL. - # - this is restricted to recipe/resource/provider context where a resource collection exists. - # - core chef authors should typically include modules into here. - # - # Chef::DSL::Universal mixes into Recipes, LWRP Resources+Providers, Core Resources+Providers, and Attributes files. - # - this adds resources and attributes files. - # - do not add helpers which manipulate the resource collection. - # - this is for general-purpose stuff that is useful nearly everywhere. - # - it also pollutes the namespace of nearly every context, watch out. - # - module Universal - CopiedFromChef.extend_chef_module(::Chef::DSL::Universal, self) if defined?(::Chef::DSL::Universal) - include Chef::DSL::PlatformIntrospection - include Chef::Mixin::PowershellOut - include Chef::Mixin::ShellOut - end - end -end -end -end -end diff --git a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/mixin/lazy_module_include.rb b/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/mixin/lazy_module_include.rb deleted file mode 100644 index a6b5244..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/mixin/lazy_module_include.rb +++ /dev/null @@ -1,98 +0,0 @@ -# -# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE -# -# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!! -# -# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE -# - -begin - require 'chef/mixin/lazy_module_include' -rescue LoadError; end - -require 'chef_compat/copied_from_chef' -class Chef -module ::ChefCompat -module CopiedFromChef -# -# Copyright:: Copyright 2011-2016, Chef Software Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -class Chef < (defined?(::Chef) ? ::Chef : Object) - module Mixin - CopiedFromChef.extend_chef_module(::Chef::Mixin, self) if defined?(::Chef::Mixin) - # If you have: - # - # module A - # extend LazyModuleInclude - # end - # - # module B - # include A - # end - # - # module C - # include B - # end - # - # module Monkeypatches - # def monkey - # puts "monkey!" - # end - # end - # - # A.send(:include, Monkeypatches) - # - # Then B and C and any classes that they're included in will also get the #monkey method patched into them. - # - module LazyModuleInclude - CopiedFromChef.extend_chef_module(::Chef::Mixin::LazyModuleInclude, self) if defined?(::Chef::Mixin::LazyModuleInclude) - - # Most of the magick is in this hook which creates a closure over the parent class and then builds an - # "infector" module which infects all descendants and which is responsible for updating the list of - # descendants in the parent class. - def included(klass) - super - parent_klass = self - infector = Module.new do - define_method(:included) do |subklass| - super(subklass) - subklass.extend(infector) - parent_klass.descendants.push(subklass) - end - end - klass.extend(infector) - parent_klass.descendants.push(klass) - end - - def descendants - @descendants ||= [] - end - - def include(*classes) - super - classes.each do |klass| - descendants.each do |descendant| - descendant.send(:include, klass) - end - end - end - end - end -end -end -end -end diff --git a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/mixin/notifying_block.rb b/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/mixin/notifying_block.rb deleted file mode 100644 index 0b90e27..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/mixin/notifying_block.rb +++ /dev/null @@ -1,74 +0,0 @@ -# -# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE -# -# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!! -# -# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE -# - -begin - require 'chef/mixin/notifying_block' -rescue LoadError; end - -require 'chef_compat/copied_from_chef' -class Chef -module ::ChefCompat -module CopiedFromChef -#-- -# Author:: Lamont Granquist -# Copyright:: Copyright 2010-2016, Chef Software Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -class Chef < (defined?(::Chef) ? ::Chef : Object) - module Mixin - CopiedFromChef.extend_chef_module(::Chef::Mixin, self) if defined?(::Chef::Mixin) - module NotifyingBlock - CopiedFromChef.extend_chef_module(::Chef::Mixin::NotifyingBlock, self) if defined?(::Chef::Mixin::NotifyingBlock) - - def notifying_block(&block) - begin - subcontext = subcontext_block(&block) - Chef::Runner.new(subcontext).converge - ensure - # recipes don't have a new_resource - if respond_to?(:new_resource) - if subcontext && subcontext.resource_collection.any?(&:updated?) - new_resource.updated_by_last_action(true) - end - end - end - end - - def subcontext_block(parent_context = nil, &block) - parent_context ||= @run_context - sub_run_context = parent_context.create_child - - begin - outer_run_context = @run_context - @run_context = sub_run_context - instance_eval(&block) - ensure - @run_context = outer_run_context - end - - sub_run_context - end - - end - end -end -end -end -end diff --git a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/mixin/params_validate.rb b/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/mixin/params_validate.rb deleted file mode 100644 index 0a16147..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/mixin/params_validate.rb +++ /dev/null @@ -1,510 +0,0 @@ -# -# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE -# -# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!! -# -# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE -# - -begin - require 'chef/mixin/params_validate' -rescue LoadError; end - -require 'chef_compat/copied_from_chef' -class Chef -module ::ChefCompat -module CopiedFromChef -# -# Author:: Adam Jacob () -# Copyright:: Copyright 2008-2016, Chef Software Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -require "chef_compat/copied_from_chef/chef/constants" -require "chef_compat/copied_from_chef/chef/property" -require "chef_compat/copied_from_chef/chef/delayed_evaluator" - -class Chef < (defined?(::Chef) ? ::Chef : Object) - module Mixin - CopiedFromChef.extend_chef_module(::Chef::Mixin, self) if defined?(::Chef::Mixin) - module ParamsValidate - CopiedFromChef.extend_chef_module(::Chef::Mixin::ParamsValidate, self) if defined?(::Chef::Mixin::ParamsValidate) - # Takes a hash of options, along with a map to validate them. Returns the original - # options hash, plus any changes that might have been made (through things like setting - # default values in the validation map) - # - # For example: - # - # validate({ :one => "neat" }, { :one => { :kind_of => String }}) - # - # Would raise an exception if the value of :one above is not a kind_of? string. Valid - # map options are: - # - # @param opts [Hash] Validation opts. - # @option opts [Object,Array] :is An object, or list of - # objects, that must match the value using Ruby's `===` operator - # (`opts[:is].any? { |v| v === value }`). (See #_pv_is.) - # @option opts [Object,Array] :equal_to An object, or list - # of objects, that must be equal to the value using Ruby's `==` - # operator (`opts[:is].any? { |v| v == value }`) (See #_pv_equal_to.) - # @option opts [Regexp,Array] :regex An object, or - # list of objects, that must match the value with `regex.match(value)`. - # (See #_pv_regex) - # @option opts [Class,Array] :kind_of A class, or - # list of classes, that the value must be an instance of. (See - # #_pv_kind_of.) - # @option opts [Hash] :callbacks A hash of - # messages -> procs, all of which match the value. The proc must - # return a truthy or falsey value (true means it matches). (See - # #_pv_callbacks.) - # @option opts [Symbol,Array] :respond_to A method - # name, or list of method names, the value must respond to. (See - # #_pv_respond_to.) - # @option opts [Symbol,Array] :cannot_be A property, - # or a list of properties, that the value cannot have (such as `:nil` or - # `:empty`). The method with a questionmark at the end is called on the - # value (e.g. `value.empty?`). If the value does not have this method, - # it is considered valid (i.e. if you don't respond to `empty?` we - # assume you are not empty). (See #_pv_cannot_be.) - # @option opts [Proc] :coerce A proc which will be called to - # transform the user input to canonical form. The value is passed in, - # and the transformed value returned as output. Lazy values will *not* - # be passed to this method until after they are evaluated. Called in the - # context of the resource (meaning you can access other properties). - # (See #_pv_coerce.) (See #_pv_coerce.) - # @option opts [Boolean] :required `true` if this property - # must be present and not `nil`; `false` otherwise. This is checked - # after the resource is fully initialized. (See #_pv_required.) - # @option opts [Boolean] :name_property `true` if this - # property defaults to the same value as `name`. Equivalent to - # `default: lazy { name }`, except that #property_is_set? will - # return `true` if the property is set *or* if `name` is set. (See - # #_pv_name_property.) - # @option opts [Boolean] :name_attribute Same as `name_property`. - # @option opts [Object] :default The value this property - # will return if the user does not set one. If this is `lazy`, it will - # be run in the context of the instance (and able to access other - # properties). (See #_pv_default.) - # - def validate(opts, map) - map = map.validation_options if map.is_a?(Property) - - #-- - # validate works by taking the keys in the validation map, assuming it's a hash, and - # looking for _pv_:symbol as methods. Assuming it find them, it calls the right - # one. - #++ - raise ArgumentError, "Options must be a hash" unless opts.kind_of?(Hash) - raise ArgumentError, "Validation Map must be a hash" unless map.kind_of?(Hash) - - map.each do |key, validation| - unless key.kind_of?(Symbol) || key.kind_of?(String) - raise ArgumentError, "Validation map keys must be symbols or strings!" - end - case validation - when true - _pv_required(opts, key) - when false - true - when Hash - validation.each do |check, carg| - check_method = "_pv_#{check}" - if self.respond_to?(check_method, true) - self.send(check_method, opts, key, carg) - else - raise ArgumentError, "Validation map has unknown check: #{check}" - end - end - end - end - opts - end - - def lazy(&block) - DelayedEvaluator.new(&block) - end - - def set_or_return(symbol, value, validation) - property = SetOrReturnProperty.new(name: symbol, **validation) - property.call(self, value) - end - - private - - def explicitly_allows_nil?(key, validation) - validation.has_key?(:is) && _pv_is({ key => nil }, key, validation[:is], raise_error: false) - end - - # Return the value of a parameter, or nil if it doesn't exist. - def _pv_opts_lookup(opts, key) - if opts.has_key?(key.to_s) - opts[key.to_s] - elsif opts.has_key?(key.to_sym) - opts[key.to_sym] - else - nil - end - end - - # Raise an exception if the parameter is not found. - def _pv_required(opts, key, is_required = true, explicitly_allows_nil = false) - if is_required - return true if opts.has_key?(key.to_s) && (explicitly_allows_nil || !opts[key.to_s].nil?) - return true if opts.has_key?(key.to_sym) && (explicitly_allows_nil || !opts[key.to_sym].nil?) - raise Exceptions::ValidationFailed, "Required argument #{key.inspect} is missing!" - end - true - end - - # - # List of things values must be equal to. - # - # Uses Ruby's `==` to evaluate (equal_to == value). At least one must - # match for the value to be valid. - # - # `nil` passes this validation automatically. - # - # @return [Array,nil] List of things values must be equal to, or nil if - # equal_to is unspecified. - # - def _pv_equal_to(opts, key, to_be) - value = _pv_opts_lookup(opts, key) - unless value.nil? - to_be = Array(to_be) - to_be.each do |tb| - return true if value == tb - end - raise Exceptions::ValidationFailed, "Option #{key} must be equal to one of: #{to_be.join(", ")}! You passed #{value.inspect}." - end - end - - # - # List of things values must be instances of. - # - # Uses value.kind_of?(kind_of) to evaluate. At least one must match for - # the value to be valid. - # - # `nil` automatically passes this validation. - # - def _pv_kind_of(opts, key, to_be) - value = _pv_opts_lookup(opts, key) - unless value.nil? - to_be = Array(to_be) - to_be.each do |tb| - return true if value.kind_of?(tb) - end - raise Exceptions::ValidationFailed, "Option #{key} must be a kind of #{to_be}! You passed #{value.inspect}." - end - end - - # - # List of method names values must respond to. - # - # Uses value.respond_to?(respond_to) to evaluate. At least one must match - # for the value to be valid. - # - def _pv_respond_to(opts, key, method_name_list) - value = _pv_opts_lookup(opts, key) - unless value.nil? - Array(method_name_list).each do |method_name| - unless value.respond_to?(method_name) - raise Exceptions::ValidationFailed, "Option #{key} must have a #{method_name} method!" - end - end - end - end - - # - # List of things that must not be true about the value. - # - # Calls `value.?` All responses must be false for the value to be - # valid. - # Values which do not respond to ? are considered valid (because if - # a value doesn't respond to `:readable?`, then it probably isn't - # readable.) - # - # @example - # ```ruby - # property :x, cannot_be: [ :nil, :empty ] - # x [ 1, 2 ] #=> valid - # x 1 #=> valid - # x [] #=> invalid - # x nil #=> invalid - # ``` - # - def _pv_cannot_be(opts, key, predicate_method_base_name) - value = _pv_opts_lookup(opts, key) - if !value.nil? - Array(predicate_method_base_name).each do |method_name| - predicate_method = :"#{method_name}?" - - if value.respond_to?(predicate_method) - if value.send(predicate_method) - raise Exceptions::ValidationFailed, "Option #{key} cannot be #{predicate_method_base_name}" - end - end - end - end - end - - # - # The default value for a property. - # - # When the property is not assigned, this will be used. - # - # If this is a lazy value, it will either be passed the resource as a value, - # or if the lazy proc does not take parameters, it will be run in the - # context of the instance with instance_eval. - # - # @example - # ```ruby - # property :x, default: 10 - # ``` - # - # @example - # ```ruby - # property :x - # property :y, default: lazy { x+2 } - # ``` - # - # @example - # ```ruby - # property :x - # property :y, default: lazy { |r| r.x+2 } - # ``` - # - def _pv_default(opts, key, default_value) - value = _pv_opts_lookup(opts, key) - if value.nil? - default_value = default_value.freeze if !default_value.is_a?(DelayedEvaluator) - opts[key] = default_value - end - end - - # - # List of regexes values that must match. - # - # Uses regex.match() to evaluate. At least one must match for the value to - # be valid. - # - # `nil` passes regex validation automatically. - # - # @example - # ```ruby - # property :x, regex: [ /abc/, /xyz/ ] - # ``` - # - def _pv_regex(opts, key, regex) - value = _pv_opts_lookup(opts, key) - if !value.nil? - Array(regex).flatten.each do |r| - return true if r.match(value.to_s) - end - raise Exceptions::ValidationFailed, "Option #{key}'s value #{value} does not match regular expression #{regex.inspect}" - end - end - - # - # List of procs we pass the value to. - # - # All procs must return true for the value to be valid. If any procs do - # not return true, the key will be used for the message: `"Property x's - # value :y "`. - # - # @example - # ```ruby - # property :x, callbacks: { "is bigger than 10" => proc { |v| v <= 10 }, "is not awesome" => proc { |v| !v.awesome }} - # ``` - # - def _pv_callbacks(opts, key, callbacks) - raise ArgumentError, "Callback list must be a hash!" unless callbacks.kind_of?(Hash) - value = _pv_opts_lookup(opts, key) - if !value.nil? - callbacks.each do |message, zeproc| - unless zeproc.call(value) - raise Exceptions::ValidationFailed, "Option #{key}'s value #{value} #{message}!" - end - end - end - end - - # - # Allows a parameter to default to the value of the resource name. - # - # @example - # ```ruby - # property :x, name_property: true - # ``` - # - def _pv_name_property(opts, key, is_name_property = true) - if is_name_property - if opts[key].nil? - raise CannotValidateStaticallyError, "name_property cannot be evaluated without a resource." if self == Chef::Mixin::ParamsValidate - opts[key] = self.instance_variable_get(:"@name") - end - end - end - alias :_pv_name_attribute :_pv_name_property - - # - # List of valid things values can be. - # - # Uses Ruby's `===` to evaluate (is === value). At least one must match - # for the value to be valid. - # - # If a proc is passed, it is instance_eval'd in the resource, passed the - # value, and must return a truthy or falsey value. - # - # @example Class - # ```ruby - # property :x, String - # x 'valid' #=> valid - # x 1 #=> invalid - # x nil #=> invalid - # - # @example Value - # ```ruby - # property :x, [ :a, :b, :c, nil ] - # x :a #=> valid - # x nil #=> valid - # ``` - # - # @example Regex - # ```ruby - # property :x, /bar/ - # x 'foobar' #=> valid - # x 'foo' #=> invalid - # x nil #=> invalid - # ``` - # - # @example Proc - # ```ruby - # property :x, proc { |x| x > y } - # property :y, default: 2 - # x 3 #=> valid - # x 1 #=> invalid - # ``` - # - # @example Property - # ```ruby - # type = Property.new(is: String) - # property :x, type - # x 'foo' #=> valid - # x 1 #=> invalid - # x nil #=> invalid - # ``` - # - # @example RSpec Matcher - # ```ruby - # include RSpec::Matchers - # property :x, a_string_matching /bar/ - # x 'foobar' #=> valid - # x 'foo' #=> invalid - # x nil #=> invalid - # ``` - # - def _pv_is(opts, key, to_be, raise_error: true) - return true if !opts.has_key?(key.to_s) && !opts.has_key?(key.to_sym) - value = _pv_opts_lookup(opts, key) - to_be = [ to_be ].flatten(1) - errors = [] - passed = to_be.any? do |tb| - case tb - when Proc - raise CannotValidateStaticallyError, "is: proc { } must be evaluated once for each resource" if self == Chef::Mixin::ParamsValidate - instance_exec(value, &tb) - when Property - begin - validate(opts, { key => tb.validation_options }) - true - rescue Exceptions::ValidationFailed - # re-raise immediately if there is only one "is" so we get a better stack - raise if to_be.size == 1 - errors << $! - false - end - else - tb === value - end - end - if passed - true - else - message = "Property #{key} must be one of: #{to_be.map { |v| v.inspect }.join(", ")}! You passed #{value.inspect}." - unless errors.empty? - message << " Errors:\n#{errors.map { |m| "- #{m}" }.join("\n")}" - end - raise Exceptions::ValidationFailed, message - end - end - - # - # Method to mess with a value before it is validated and stored. - # - # Allows you to transform values into a canonical form that is easy to - # work with. - # - # This is passed the value to transform, and is run in the context of the - # instance (so it has access to other resource properties). It must return - # the value that will be stored in the instance. - # - # @example - # ```ruby - # property :x, Integer, coerce: { |v| v.to_i } - # ``` - # - def _pv_coerce(opts, key, coercer) - if opts.has_key?(key.to_s) - raise CannotValidateStaticallyError, "coerce must be evaluated for each resource." if self == Chef::Mixin::ParamsValidate - opts[key.to_s] = instance_exec(opts[key], &coercer) - elsif opts.has_key?(key.to_sym) - raise CannotValidateStaticallyError, "coerce must be evaluated for each resource." if self == Chef::Mixin::ParamsValidate - opts[key.to_sym] = instance_exec(opts[key], &coercer) - end - end - - # We allow Chef::Mixin::ParamsValidate.validate(), but we will raise an - # error if you try to do anything requiring there to be an actual resource. - # This way, you can statically validate things if you have constant validation - # (which is the norm). - extend self - - # Used by #set_or_return to avoid emitting a deprecation warning for - # "value nil" and to keep default stickiness working exactly the same - # @api private - class SetOrReturnProperty < (defined?(::Chef::Mixin::ParamsValidate::SetOrReturnProperty) ? ::Chef::Mixin::ParamsValidate::SetOrReturnProperty : Chef::Property) - def get(resource, nil_set: false) - value = super - # All values are sticky, frozen or not - if !is_set?(resource) - set_value(resource, value) - end - value - end - - def call(resource, value = NOT_PASSED) - # setting to nil does a get - if value.nil? && !explicitly_accepts_nil?(resource) - get(resource, nil_set: true) - else - super - end - end - end - end - end -end -end -end -end diff --git a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/mixin/powershell_out.rb b/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/mixin/powershell_out.rb deleted file mode 100644 index b6b56f9..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/mixin/powershell_out.rb +++ /dev/null @@ -1,117 +0,0 @@ -# -# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE -# -# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!! -# -# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE -# - -begin - require 'chef/mixin/powershell_out' -rescue LoadError; end - -require 'chef_compat/copied_from_chef' -class Chef -module ::ChefCompat -module CopiedFromChef -#-- -# Copyright:: Copyright 2015-2016, Chef Software, Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -class Chef < (defined?(::Chef) ? ::Chef : Object) - module Mixin - CopiedFromChef.extend_chef_module(::Chef::Mixin, self) if defined?(::Chef::Mixin) - module PowershellOut - CopiedFromChef.extend_chef_module(::Chef::Mixin::PowershellOut, self) if defined?(::Chef::Mixin::PowershellOut) - include Chef::Mixin::ShellOut - include Chef::Mixin::WindowsArchitectureHelper - - # Run a command under powershell with the same API as shell_out. The - # options hash is extended to take an "architecture" flag which - # can be set to :i386 or :x86_64 to force the windows architecture. - # - # @param script [String] script to run - # @param options [Hash] options hash - # @return [Mixlib::Shellout] mixlib-shellout object - def powershell_out(*command_args) - script = command_args.first - options = command_args.last.is_a?(Hash) ? command_args.last : nil - - run_command_with_os_architecture(script, options) - end - - # Run a command under powershell with the same API as shell_out! - # (raises exceptions on errors) - # - # @param script [String] script to run - # @param options [Hash] options hash - # @return [Mixlib::Shellout] mixlib-shellout object - def powershell_out!(*command_args) - cmd = powershell_out(*command_args) - cmd.error! - cmd - end - - private - - # Helper function to run shell_out and wrap it with the correct - # flags to possibly disable WOW64 redirection (which we often need - # because chef-client runs as a 32-bit app on 64-bit windows). - # - # @param script [String] script to run - # @param options [Hash] options hash - # @return [Mixlib::Shellout] mixlib-shellout object - def run_command_with_os_architecture(script, options) - options ||= {} - options = options.dup - arch = options.delete(:architecture) - - with_os_architecture(nil, architecture: arch) do - shell_out( - build_powershell_command(script), - options - ) - end - end - - # Helper to build a powershell command around the script to run. - # - # @param script [String] script to run - # @retrurn [String] powershell command to execute - def build_powershell_command(script) - flags = [ - # Hides the copyright banner at startup. - "-NoLogo", - # Does not present an interactive prompt to the user. - "-NonInteractive", - # Does not load the Windows PowerShell profile. - "-NoProfile", - # always set the ExecutionPolicy flag - # see http://technet.microsoft.com/en-us/library/ee176961.aspx - "-ExecutionPolicy Unrestricted", - # Powershell will hang if STDIN is redirected - # http://connect.microsoft.com/PowerShell/feedback/details/572313/powershell-exe-can-hang-if-stdin-is-redirected - "-InputFormat None", - ] - - "powershell.exe #{flags.join(' ')} -Command \"#{script.gsub('"', '\"')}\"" - end - end - end -end -end -end -end diff --git a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/mixin/properties.rb b/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/mixin/properties.rb deleted file mode 100644 index bdf9f7e..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/mixin/properties.rb +++ /dev/null @@ -1,328 +0,0 @@ -# -# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE -# -# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!! -# -# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE -# - -begin - require 'chef/mixin/properties' -rescue LoadError; end - -require 'chef_compat/copied_from_chef' -class Chef -module ::ChefCompat -module CopiedFromChef -require "chef_compat/copied_from_chef/chef/delayed_evaluator" -require "chef_compat/copied_from_chef/chef/mixin/params_validate" -require "chef_compat/copied_from_chef/chef/property" - -class Chef < (defined?(::Chef) ? ::Chef : Object) - module Mixin - CopiedFromChef.extend_chef_module(::Chef::Mixin, self) if defined?(::Chef::Mixin) - module Properties - CopiedFromChef.extend_chef_module(::Chef::Mixin::Properties, self) if defined?(::Chef::Mixin::Properties) - module ClassMethods - CopiedFromChef.extend_chef_module(::Chef::Mixin::Properties::ClassMethods, self) if defined?(::Chef::Mixin::Properties::ClassMethods) - # - # The list of properties defined on this resource. - # - # Everything defined with `property` is in this list. - # - # @param include_superclass [Boolean] `true` to include properties defined - # on superclasses; `false` or `nil` to return the list of properties - # directly on this class. - # - # @return [Hash] The list of property names and types. - # - def properties(include_superclass = true) - if include_superclass - result = {} - ancestors.reverse_each { |c| result.merge!(c.properties(false)) if c.respond_to?(:properties) } - result - else - @properties ||= {} - end - end - - # - # Create a property on this resource class. - # - # If a superclass has this property, or if this property has already been - # defined by this resource, this will *override* the previous value. - # - # @param name [Symbol] The name of the property. - # @param type [Object,Array] The type(s) of this property. - # If present, this is prepended to the `is` validation option. - # @param options [Hash] Validation options. - # @option options [Object,Array] :is An object, or list of - # objects, that must match the value using Ruby's `===` operator - # (`options[:is].any? { |v| v === value }`). - # @option options [Object,Array] :equal_to An object, or list - # of objects, that must be equal to the value using Ruby's `==` - # operator (`options[:is].any? { |v| v == value }`) - # @option options [Regexp,Array] :regex An object, or - # list of objects, that must match the value with `regex.match(value)`. - # @option options [Class,Array] :kind_of A class, or - # list of classes, that the value must be an instance of. - # @option options [Hash] :callbacks A hash of - # messages -> procs, all of which match the value. The proc must - # return a truthy or falsey value (true means it matches). - # @option options [Symbol,Array] :respond_to A method - # name, or list of method names, the value must respond to. - # @option options [Symbol,Array] :cannot_be A property, - # or a list of properties, that the value cannot have (such as `:nil` or - # `:empty`). The method with a questionmark at the end is called on the - # value (e.g. `value.empty?`). If the value does not have this method, - # it is considered valid (i.e. if you don't respond to `empty?` we - # assume you are not empty). - # @option options [Proc] :coerce A proc which will be called to - # transform the user input to canonical form. The value is passed in, - # and the transformed value returned as output. Lazy values will *not* - # be passed to this method until after they are evaluated. Called in the - # context of the resource (meaning you can access other properties). - # @option options [Boolean] :required `true` if this property - # must be present; `false` otherwise. This is checked after the resource - # is fully initialized. - # @option options [Boolean] :name_property `true` if this - # property defaults to the same value as `name`. Equivalent to - # `default: lazy { name }`, except that #property_is_set? will - # return `true` if the property is set *or* if `name` is set. - # @option options [Boolean] :name_attribute Same as `name_property`. - # @option options [Object] :default The value this property - # will return if the user does not set one. If this is `lazy`, it will - # be run in the context of the instance (and able to access other - # properties). - # @option options [Boolean] :desired_state `true` if this property is - # part of desired state. Defaults to `true`. - # @option options [Boolean] :identity `true` if this property - # is part of object identity. Defaults to `false`. - # @option options [Boolean] :sensitive `true` if this property could - # contain sensitive information and whose value should be redacted - # in any resource reporting / auditing output. Defaults to `false`. - # - # @example Bare property - # property :x - # - # @example With just a type - # property :x, String - # - # @example With just options - # property :x, default: 'hi' - # - # @example With type and options - # property :x, String, default: 'hi' - # - def property(name, type = NOT_PASSED, **options) - name = name.to_sym - - options = options.inject({}) { |memo, (key, value)| memo[key.to_sym] = value; memo } - - options[:instance_variable_name] = :"@#{name}" if !options.has_key?(:instance_variable_name) - options[:name] = name - options[:declared_in] = self - - if type == NOT_PASSED - # If a type is not passed, the property derives from the - # superclass property (if any) - if properties.has_key?(name) - property = properties[name].derive(**options) - else - property = property_type(**options) - end - - # If a Property is specified, derive a new one from that. - elsif type.is_a?(Property) || (type.is_a?(Class) && type <= Property) - property = type.derive(**options) - - # If a primitive type was passed, combine it with "is" - else - if options[:is] - options[:is] = ([ type ] + [ options[:is] ]).flatten(1) - else - options[:is] = type - end - property = property_type(**options) - end - - local_properties = properties(false) - local_properties[name] = property - - property.emit_dsl - end - - # - # Create a reusable property type that can be used in multiple properties - # in different resources. - # - # @param options [Hash] Validation options. see #property for - # the list of options. - # - # @example - # property_type(default: 'hi') - # - def property_type(**options) - Property.derive(**options) - end - - # - # Create a lazy value for assignment to a default value. - # - # @param block The block to run when the value is retrieved. - # - # @return [Chef::DelayedEvaluator] The lazy value - # - def lazy(&block) - DelayedEvaluator.new(&block) - end - - # - # Get or set the list of desired state properties for this resource. - # - # State properties are properties that describe the desired state - # of the system, such as file permissions or ownership. - # In general, state properties are properties that could be populated by - # examining the state of the system (e.g., File.stat can tell you the - # permissions on an existing file). Contrarily, properties that are not - # "state properties" usually modify the way Chef itself behaves, for example - # by providing additional options for a package manager to use when - # installing a package. - # - # This list is used by the Chef client auditing system to extract - # information from resources to describe changes made to the system. - # - # This method is unnecessary when declaring properties with `property`; - # properties are added to state_properties by default, and can be turned off - # with `desired_state: false`. - # - # ```ruby - # property :x # part of desired state - # property :y, desired_state: false # not part of desired state - # ``` - # - # @param names [Array] A list of property names to set as desired - # state. - # - # @return [Array] All properties in desired state. - # - def state_properties(*names) - if !names.empty? - names = names.map { |name| name.to_sym }.uniq - - local_properties = properties(false) - # Add new properties to the list. - names.each do |name| - property = properties[name] - if !property - self.property name, instance_variable_name: false, desired_state: true - elsif !property.desired_state? - self.property name, desired_state: true - end - end - - # If state_attrs *excludes* something which is currently desired state, - # mark it as desired_state: false. - local_properties.each do |name, property| - if property.desired_state? && !names.include?(name) - self.property name, desired_state: false - end - end - end - - properties.values.select { |property| property.desired_state? } - end - - # - # Set the identity of this resource to a particular set of properties. - # - # This drives #identity, which returns data that uniquely refers to a given - # resource on the given node (in such a way that it can be correlated - # across Chef runs). - # - # This method is unnecessary when declaring properties with `property`; - # properties can be added to identity during declaration with - # `identity: true`. - # - # ```ruby - # property :x, identity: true # part of identity - # property :y # not part of identity - # ``` - # - # If no properties are marked as identity, "name" is considered the identity. - # - # @param names [Array] A list of property names to set as the identity. - # - # @return [Array] All identity properties. - # - def identity_properties(*names) - if !names.empty? - names = names.map { |name| name.to_sym } - - # Add or change properties that are not part of the identity. - names.each do |name| - property = properties[name] - if !property - self.property name, instance_variable_name: false, identity: true - elsif !property.identity? - self.property name, identity: true - end - end - - # If identity_properties *excludes* something which is currently part of - # the identity, mark it as identity: false. - properties.each do |name, property| - if property.identity? && !names.include?(name) - - self.property name, identity: false - end - end - end - - result = properties.values.select { |property| property.identity? } - result = [ properties[:name] ] if result.empty? - result - end - - def included(other) - other.extend ClassMethods - end - end - - def self.included(other) - other.extend ClassMethods - end - - include Chef::Mixin::ParamsValidate - - # - # Whether this property has been set (or whether it has a default that has - # been retrieved). - # - # @param name [Symbol] The name of the property. - # @return [Boolean] `true` if the property has been set. - # - def property_is_set?(name) - property = self.class.properties[name.to_sym] - raise ArgumentError, "Property #{name} is not defined in class #{self}" if !property - property.is_set?(self) - end - - # - # Clear this property as if it had never been set. It will thereafter return - # the default. - # been retrieved). - # - # @param name [Symbol] The name of the property. - # - def reset_property(name) - property = self.class.properties[name.to_sym] - raise ArgumentError, "Property #{name} is not defined in class #{self}" if !property - property.reset(self) - end - end - end -end -end -end -end diff --git a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/property.rb b/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/property.rb deleted file mode 100644 index 3399596..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/property.rb +++ /dev/null @@ -1,713 +0,0 @@ -# -# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE -# -# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!! -# -# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE -# - -begin - require 'chef/property' -rescue LoadError; end - -require 'chef_compat/copied_from_chef' -class Chef -module ::ChefCompat -module CopiedFromChef -# -# Author:: John Keiser -# Copyright:: Copyright 2015-2016, John Keiser. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -require "chef_compat/copied_from_chef/chef/delayed_evaluator" - -class Chef < (defined?(::Chef) ? ::Chef : Object) - # - # Type and validation information for a property on a resource. - # - # A property named "x" manipulates the "@x" instance variable on a - # resource. The *presence* of the variable (`instance_variable_defined?(@x)`) - # tells whether the variable is defined; it may have any actual value, - # constrained only by validation. - # - # Properties may have validation, defaults, and coercion, and have full - # support for lazy values. - # - # @see Chef::Resource.property - # @see Chef::DelayedEvaluator - # - class Property < (defined?(::Chef::Property) ? ::Chef::Property : Object) - # - # Create a reusable property type that can be used in multiple properties - # in different resources. - # - # @param options [Hash] Validation options. See Chef::Resource.property for - # the list of options. - # - # @example - # Property.derive(default: 'hi') - # - def self.derive(**options) - new(**options) - end - - # - # Create a new property. - # - # @param options [Hash] Property options, including - # control options here, as well as validation options (see - # Chef::Mixin::ParamsValidate#validate for a description of validation - # options). - # @option options [Symbol] :name The name of this property. - # @option options [Class] :declared_in The class this property comes from. - # @option options [Symbol] :instance_variable_name The instance variable - # tied to this property. Must include a leading `@`. Defaults to `@`. - # `nil` means the property is opaque and not tied to a specific instance - # variable. - # @option options [Boolean] :desired_state `true` if this property is part of desired - # state. Defaults to `true`. - # @option options [Boolean] :identity `true` if this property is part of object - # identity. Defaults to `false`. - # @option options [Boolean] :name_property `true` if this - # property defaults to the same value as `name`. Equivalent to - # `default: lazy { name }`, except that #property_is_set? will - # return `true` if the property is set *or* if `name` is set. - # @option options [Boolean] :nillable `true` opt-in to Chef-13 style behavior where - # attempting to set a nil value will really set a nil value instead of issuing - # a warning and operating like a getter - # @option options [Object] :default The value this property - # will return if the user does not set one. If this is `lazy`, it will - # be run in the context of the instance (and able to access other - # properties) and cached. If not, the value will be frozen with Object#freeze - # to prevent users from modifying it in an instance. - # @option options [Proc] :coerce A proc which will be called to - # transform the user input to canonical form. The value is passed in, - # and the transformed value returned as output. Lazy values will *not* - # be passed to this method until after they are evaluated. Called in the - # context of the resource (meaning you can access other properties). - # @option options [Boolean] :required `true` if this property - # must be present; `false` otherwise. This is checked after the resource - # is fully initialized. - # - def initialize(**options) -super if defined?(::Chef::Property) - options = options.inject({}) { |memo, (key, value)| memo[key.to_sym] = value; memo } - @options = options - options[:name] = options[:name].to_sym if options[:name] - options[:instance_variable_name] = options[:instance_variable_name].to_sym if options[:instance_variable_name] - - # Replace name_attribute with name_property - if options.has_key?(:name_attribute) - # If we have both name_attribute and name_property and they differ, raise an error - if options.has_key?(:name_property) - raise ArgumentError, "Cannot specify both name_property and name_attribute together on property #{self}." - end - # replace name_property with name_attribute in place - options = Hash[options.map { |k, v| k == :name_attribute ? [ :name_property, v ] : [ k, v ] }] - @options = options - end - - # Only pick the first of :default, :name_property and :name_attribute if - # more than one is specified. - if options.has_key?(:default) && options[:name_property] - if options[:default].nil? || options.keys.index(:name_property) < options.keys.index(:default) - options.delete(:default) - preferred_default = :name_property - else - options.delete(:name_property) - preferred_default = :default - end - Chef.log_deprecation("Cannot specify both default and name_property together on property #{self}. Only one (#{preferred_default}) will be obeyed. In Chef 13, this will become an error. Please remove one or the other from the property.") - end - - # Validate the default early, so the user gets a good error message, and - # cache it so we don't do it again if so - begin - # If we can validate it all the way to output, do it. - @stored_default = input_to_stored_value(nil, default, is_default: true) - rescue Chef::Exceptions::CannotValidateStaticallyError - # If the validation is not static (i.e. has procs), we will have to - # coerce and validate the default each time we run - end - end - - def to_s - "#{name || ""}#{declared_in ? " of resource #{declared_in.resource_name}" : ""}" - end - - # - # The name of this property. - # - # @return [String] - # - def name - options[:name] - end - - # - # The class this property was defined in. - # - # @return [Class] - # - def declared_in - options[:declared_in] - end - - # - # The instance variable associated with this property. - # - # Defaults to `@` - # - # @return [Symbol] - # - def instance_variable_name - if options.has_key?(:instance_variable_name) - options[:instance_variable_name] - elsif name - :"@#{name}" - end - end - - # - # The raw default value for this resource. - # - # Does not coerce or validate the default. Does not evaluate lazy values. - # - # Defaults to `lazy { name }` if name_property is true; otherwise defaults to - # `nil` - # - def default - return options[:default] if options.has_key?(:default) - return Chef::DelayedEvaluator.new { name } if name_property? - nil - end - - # - # Whether this is part of the resource's natural identity or not. - # - # @return [Boolean] - # - def identity? - options[:identity] - end - - # - # Whether this is part of desired state or not. - # - # Defaults to true. - # - # @return [Boolean] - # - def desired_state? - return true if !options.has_key?(:desired_state) - options[:desired_state] - end - - # - # Whether this is name_property or not. - # - # @return [Boolean] - # - def name_property? - options[:name_property] - end - - # - # Whether this property has a default value. - # - # @return [Boolean] - # - def has_default? - options.has_key?(:default) || name_property? - end - - # - # Whether this property is required or not. - # - # @return [Boolean] - # - def required? - options[:required] - end - - # - # Whether this property is sensitive or not. - # - # Defaults to false. - # - # @return [Boolean] - # - def sensitive? - options.fetch(:sensitive, false) - end - - # - # Validation options. (See Chef::Mixin::ParamsValidate#validate.) - # - # @return [Hash] - # - def validation_options - @validation_options ||= options.reject do |k, v| - [:declared_in, :name, :instance_variable_name, :desired_state, :identity, :default, :name_property, :coerce, :required, :nillable, :sensitive].include?(k) - end - end - - # - # Handle the property being called. - # - # The base implementation does the property get-or-set: - # - # ```ruby - # resource.myprop # get - # resource.myprop value # set - # ``` - # - # Subclasses may implement this with any arguments they want, as long as - # the corresponding DSL calls it correctly. - # - # @param resource [Chef::Resource] The resource to get the property from. - # @param value The value to set (or NOT_PASSED if it is a get). - # - # @return The current value of the property. If it is a `set`, lazy values - # will be returned without running, validating or coercing. If it is a - # `get`, the non-lazy, coerced, validated value will always be returned. - # - def call(resource, value = NOT_PASSED) - if value == NOT_PASSED - return get(resource) - end - - if value.nil? && !nillable? - # In Chef 12, value(nil) does a *get* instead of a set, so we - # warn if the value would have been changed. In Chef 13, it will be - # equivalent to value = nil. - result = get(resource, nil_set: true) - - # Warn about this becoming a set in Chef 13. - begin - input_to_stored_value(resource, value) - # If nil is valid, and it would change the value, warn that this will change to a set. - if !result.nil? - Chef.log_deprecation("An attempt was made to change #{name} from #{result.inspect} to nil by calling #{name}(nil). In Chef 12, this does a get rather than a set. In Chef 13, this will change to set the value to nil.") - end - rescue Chef::Exceptions::DeprecatedFeatureError - raise - rescue - # If nil is invalid, warn that this will become an error. - Chef.log_deprecation("nil is an invalid value for #{self}. In Chef 13, this warning will change to an error. Error: #{$!}") - end - - result - else - # Anything else, such as myprop(value) is a set - set(resource, value) - end - end - - # - # Get the property value from the resource, handling lazy values, - # defaults, and validation. - # - # - If the property's value is lazy, it is evaluated, coerced and validated. - # - If the property has no value, and is required, raises ValidationFailed. - # - If the property has no value, but has a lazy default, it is evaluated, - # coerced and validated. If the evaluated value is frozen, the resulting - # - If the property has no value, but has a default, the default value - # will be returned and frozen. If the default value is lazy, it will be - # evaluated, coerced and validated, and the result stored in the property. - # - If the property has no value, but is name_property, `resource.name` - # is retrieved, coerced, validated and stored in the property. - # - Otherwise, `nil` is returned. - # - # @param resource [Chef::Resource] The resource to get the property from. - # - # @return The value of the property. - # - # @raise Chef::Exceptions::ValidationFailed If the value is invalid for - # this property, or if the value is required and not set. - # - def get(resource, nil_set: false) - # If it's set, return it (and evaluate any lazy values) - if is_set?(resource) - value = get_value(resource) - value = stored_value_to_output(resource, value) - - else - # We are getting the default value. - - # If the user does something like this: - # - # ``` - # class MyResource < Chef::Resource - # property :content - # action :create do - # file '/x.txt' do - # content content - # end - # end - # end - # ``` - # - # It won't do what they expect. This checks whether you try to *read* - # `content` while we are compiling the resource. - if !nil_set && - resource.respond_to?(:resource_initializing) && - resource.resource_initializing && - resource.respond_to?(:enclosing_provider) && - resource.enclosing_provider && - resource.enclosing_provider.new_resource && - resource.enclosing_provider.new_resource.respond_to?(name) - Chef::Log.warn("#{Chef::Log.caller_location}: property #{name} is declared in both #{resource} and #{resource.enclosing_provider}. Use new_resource.#{name} instead. At #{Chef::Log.caller_location}") - end - - if has_default? - # If we were able to cache the stored_default, grab it. - if defined?(@stored_default) - value = @stored_default - else - # Otherwise, we have to validate it now. - value = input_to_stored_value(resource, default, is_default: true) - end - value = stored_value_to_output(resource, value, is_default: true) - - # If the value is mutable (non-frozen), we set it on the instance - # so that people can mutate it. (All constant default values are - # frozen.) - if !value.frozen? && !value.nil? - set_value(resource, value) - end - - value - - elsif required? - raise Chef::Exceptions::ValidationFailed, "#{name} is required" - end - end - end - - # - # Set the value of this property in the given resource. - # - # Non-lazy values are coerced and validated before being set. Coercion - # and validation of lazy values is delayed until they are first retrieved. - # - # @param resource [Chef::Resource] The resource to set this property in. - # @param value The value to set. - # - # @return The value that was set, after coercion (if lazy, still returns - # the lazy value) - # - # @raise Chef::Exceptions::ValidationFailed If the value is invalid for - # this property. - # - def set(resource, value) - set_value(resource, input_to_stored_value(resource, value)) - end - - # - # Find out whether this property has been set. - # - # This will be true if: - # - The user explicitly set the value - # - The property has a default, and the value was retrieved. - # - # From this point of view, it is worth looking at this as "what does the - # user think this value should be." In order words, if the user grabbed - # the value, even if it was a default, they probably based calculations on - # it. If they based calculations on it and the value changes, the rest of - # the world gets inconsistent. - # - # @param resource [Chef::Resource] The resource to get the property from. - # - # @return [Boolean] - # - def is_set?(resource) - value_is_set?(resource) - end - - # - # Reset the value of this property so that is_set? will return false and the - # default will be returned in the future. - # - # @param resource [Chef::Resource] The resource to get the property from. - # - def reset(resource) - reset_value(resource) - end - - # - # Coerce an input value into canonical form for the property. - # - # After coercion, the value is suitable for storage in the resource. - # You must validate values after coercion, however. - # - # Does no special handling for lazy values. - # - # @param resource [Chef::Resource] The resource we're coercing against - # (to provide context for the coerce). - # @param value The value to coerce. - # - # @return The coerced value. - # - # @raise Chef::Exceptions::ValidationFailed If the value is invalid for - # this property. - # - def coerce(resource, value) - if options.has_key?(:coerce) - # If we have no default value, `nil` is never coerced or validated - unless !has_default? && value.nil? - value = exec_in_resource(resource, options[:coerce], value) - end - end - value - end - - # - # Validate a value. - # - # Calls Chef::Mixin::ParamsValidate#validate with #validation_options as - # options. - # - # @param resource [Chef::Resource] The resource we're validating against - # (to provide context for the validate). - # @param value The value to validate. - # - # @raise Chef::Exceptions::ValidationFailed If the value is invalid for - # this property. - # - def validate(resource, value) - # If we have no default value, `nil` is never coerced or validated - unless value.nil? && !has_default? - if resource - resource.validate({ name => value }, { name => validation_options }) - else - name = self.name || :property_type - Chef::Mixin::ParamsValidate.validate({ name => value }, { name => validation_options }) - end - end - end - - # - # Derive a new Property that is just like this one, except with some added or - # changed options. - # - # @param options [Hash] List of options that would be passed - # to #initialize. - # - # @return [Property] The new property type. - # - def derive(**modified_options) - # Since name_property, name_attribute and default override each other, - # if you specify one of them in modified_options it overrides anything in - # the original options. - options = self.options - if modified_options.has_key?(:name_property) || - modified_options.has_key?(:name_attribute) || - modified_options.has_key?(:default) - options = options.reject { |k, v| k == :name_attribute || k == :name_property || k == :default } - end - self.class.new(options.merge(modified_options)) - end - - # - # Emit the DSL for this property into the resource class (`declared_in`). - # - # Creates a getter and setter for the property. - # - def emit_dsl - # We don't create the getter/setter if it's a custom property; we will - # be using the existing getter/setter to manipulate it instead. - return if !instance_variable_name - - # We prefer this form because the property name won't show up in the - # stack trace if you use `define_method`. - declared_in.class_eval <<-EOM, __FILE__, __LINE__ + 1 - def #{name}(value=NOT_PASSED) - raise "Property `#{name}` of `\#{self}` was incorrectly passed a block. Possible property-resource collision. To call a resource named `#{name}` either rename the property or else use `declare_resource(:#{name}, ...)`" if block_given? - self.class.properties[#{name.inspect}].call(self, value) - end - def #{name}=(value) - raise "Property `#{name}` of `\#{self}` was incorrectly passed a block. Possible property-resource collision. To call a resource named `#{name}` either rename the property or else use `declare_resource(:#{name}, ...)`" if block_given? - self.class.properties[#{name.inspect}].set(self, value) - end - EOM - rescue SyntaxError - # If the name is not a valid ruby name, we use define_method. - declared_in.define_method(name) do |value = NOT_PASSED, &block| - raise "Property `#{name}` of `#{self}` was incorrectly passed a block! Possible property-resource collision. To call a resource named `#{name}` either rename the property or else use `declare_resource(:#{name}, ...)`" if block - self.class.properties[name].call(self, value) - end - declared_in.define_method("#{name}=") do |value, &block| - raise "Property `#{name}` of `#{self}` was incorrectly passed a block! Possible property-resource collision. To call a resource named `#{name}` either rename the property or else use `declare_resource(:#{name}, ...)`" if block - self.class.properties[name].set(self, value) - end - end - - # - # The options this Property will use for get/set behavior and validation. - # - # @see #initialize for a list of valid options. - # - attr_reader :options - - # - # Find out whether this type accepts nil explicitly. - # - # A type accepts nil explicitly if "is" allows nil, it validates as nil, *and* is not simply - # an empty type. - # - # A type is presumed to accept nil if it does coercion (which must handle nil). - # - # These examples accept nil explicitly: - # ```ruby - # property :a, [ String, nil ] - # property :a, [ String, NilClass ] - # property :a, [ String, proc { |v| v.nil? } ] - # ``` - # - # This does not (because the "is" doesn't exist or doesn't have nil): - # - # ```ruby - # property :x, String - # ``` - # - # These do not, even though nil would validate fine (because they do not - # have "is"): - # - # ```ruby - # property :a - # property :a, equal_to: [ 1, 2, 3, nil ] - # property :a, kind_of: [ String, NilClass ] - # property :a, respond_to: [ ] - # property :a, callbacks: { "a" => proc { |v| v.nil? } } - # ``` - # - # @param resource [Chef::Resource] The resource we're coercing against - # (to provide context for the coerce). - # - # @return [Boolean] Whether this value explicitly accepts nil. - # - # @api private - def explicitly_accepts_nil?(resource) - options.has_key?(:coerce) || - (options.has_key?(:is) && resource.send(:_pv_is, { name => nil }, name, options[:is], raise_error: false)) - end - - # @api private - def get_value(resource) - if instance_variable_name - resource.instance_variable_get(instance_variable_name) - else - resource.send(name) - end - end - - # @api private - def set_value(resource, value) - if instance_variable_name - resource.instance_variable_set(instance_variable_name, value) - else - resource.send(name, value) - end - end - - # @api private - def value_is_set?(resource) - if instance_variable_name - resource.instance_variable_defined?(instance_variable_name) - else - true - end - end - - # @api private - def reset_value(resource) - if instance_variable_name - if value_is_set?(resource) - resource.remove_instance_variable(instance_variable_name) - end - else - raise ArgumentError, "Property #{name} has no instance variable defined and cannot be reset" - end - end - - private - - def exec_in_resource(resource, proc, *args) - if resource - if proc.arity > args.size - value = proc.call(resource, *args) - else - value = resource.instance_exec(*args, &proc) - end - else - # If we don't have a resource yet, we can't exec in resource! - raise Chef::Exceptions::CannotValidateStaticallyError, "Cannot validate or coerce without a resource" - end - end - - def input_to_stored_value(resource, value, is_default: false) - unless value.is_a?(DelayedEvaluator) - value = coerce_and_validate(resource, value, is_default: is_default) - end - value - end - - def stored_value_to_output(resource, value, is_default: false) - # Crack open lazy values before giving the result to the user - if value.is_a?(DelayedEvaluator) - value = exec_in_resource(resource, value) - value = coerce_and_validate(resource, value, is_default: is_default) - end - value - end - - # Coerces and validates the value. If the value is a default, it will warn - # the user that invalid defaults are bad mmkay, and return it as if it were - # valid. - def coerce_and_validate(resource, value, is_default: false) - result = coerce(resource, value) - begin - # If the input is from a default, we need to emit an invalid default warning on validate. - validate(resource, result) - rescue Chef::Exceptions::CannotValidateStaticallyError - # This one gets re-raised - raise - rescue - # Anything else is just an invalid default: in those cases, we just - # warn and return the (possibly coerced) value to the user. - if is_default - if value.nil? - Chef.log_deprecation("Default value nil is invalid for property #{self}. Possible fixes: 1. Remove 'default: nil' if nil means 'undefined'. 2. Set a valid default value if there is a reasonable one. 3. Allow nil as a valid value of your property (for example, 'property #{name.inspect}, [ String, nil ], default: nil'). Error: #{$!}") - else - Chef.log_deprecation("Default value #{value.inspect} is invalid for property #{self}. In Chef 13 this will become an error: #{$!}.") - end - else - raise - end - end - - result - end - - def nillable? - !!options[:nillable] - end - end -end -end -end -end diff --git a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider.rb b/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider.rb deleted file mode 100644 index 7ccf87b..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider.rb +++ /dev/null @@ -1,164 +0,0 @@ -# -# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE -# -# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!! -# -# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE -# - -begin - require 'chef/provider' -rescue LoadError; end - -require 'chef_compat/copied_from_chef' -class Chef -module ::ChefCompat -module CopiedFromChef -require "chef_compat/copied_from_chef/chef/dsl/core" -class Chef < (defined?(::Chef) ? ::Chef : Object) - class Provider < (defined?(::Chef::Provider) ? ::Chef::Provider : Object) - include Chef::DSL::Core - attr_accessor :action - def initialize(new_resource, run_context) -super if defined?(::Chef::Provider) - @new_resource = new_resource - @action = action - @current_resource = nil - @run_context = run_context - @converge_actions = nil - - @recipe_name = nil - @cookbook_name = nil - self.class.include_resource_dsl_module(new_resource) - end - def converge_if_changed(*properties, &converge_block) - if !converge_block - raise ArgumentError, "converge_if_changed must be passed a block!" - end - - properties = new_resource.class.state_properties.map { |p| p.name } if properties.empty? - properties = properties.map { |p| p.to_sym } - if current_resource - # Collect the list of modified properties - specified_properties = properties.select { |property| new_resource.property_is_set?(property) } - modified = specified_properties.select { |p| new_resource.send(p) != current_resource.send(p) } - if modified.empty? - properties_str = if sensitive - specified_properties.join(", ") - else - specified_properties.map { |p| "#{p}=#{new_resource.send(p).inspect}" }.join(", ") - end - Chef::Log.debug("Skipping update of #{new_resource}: has not changed any of the specified properties #{properties_str}.") - return false - end - - # Print the pretty green text and run the block - property_size = modified.map { |p| p.size }.max - modified.map! do |p| - properties_str = if sensitive - "(suppressed sensitive property)" - else - "#{new_resource.send(p).inspect} (was #{current_resource.send(p).inspect})" - end - " set #{p.to_s.ljust(property_size)} to #{properties_str}" - end - converge_by([ "update #{current_resource.identity}" ] + modified, &converge_block) - - else - # The resource doesn't exist. Mark that we are *creating* this, and - # write down any properties we are setting. - property_size = properties.map { |p| p.size }.max - created = properties.map do |property| - default = " (default value)" unless new_resource.property_is_set?(property) - properties_str = if sensitive - "(suppressed sensitive property)" - else - new_resource.send(property).inspect - end - " set #{property.to_s.ljust(property_size)} to #{properties_str}#{default}" - end - - converge_by([ "create #{new_resource.identity}" ] + created, &converge_block) - end - true - end - def self.include_resource_dsl(include_resource_dsl) - @include_resource_dsl = include_resource_dsl - end - def self.include_resource_dsl_module(resource) - if @include_resource_dsl && !defined?(@included_resource_dsl_module) - provider_class = self - @included_resource_dsl_module = Module.new do - extend Forwardable - define_singleton_method(:to_s) { "forwarder module for #{provider_class}" } - define_singleton_method(:inspect) { to_s } - # Add a delegator for each explicit property that will get the *current* value - # of the property by default instead of the *actual* value. - resource.class.properties.each do |name, property| - class_eval(<<-EOM, __FILE__, __LINE__) - def #{name}(*args, &block) - # If no arguments were passed, we process "get" by defaulting - # the value to current_resource, not new_resource. This helps - # avoid issues where resources accidentally overwrite perfectly - # valid stuff with default values. - if args.empty? && !block - if !new_resource.property_is_set?(__method__) && current_resource - return current_resource.public_send(__method__) - end - end - new_resource.public_send(__method__, *args, &block) - end - EOM - end - dsl_methods = - resource.class.public_instance_methods + - resource.class.protected_instance_methods - - provider_class.instance_methods - - resource.class.properties.keys - def_delegators(:new_resource, *dsl_methods) - end - include @included_resource_dsl_module - end - end - def self.use_inline_resources - extend InlineResources::ClassMethods - include InlineResources - end - module InlineResources - CopiedFromChef.extend_chef_module(::Chef::Provider::InlineResources, self) if defined?(::Chef::Provider::InlineResources) - def compile_and_converge_action(&block) - old_run_context = run_context - @run_context = run_context.create_child - return_value = instance_eval(&block) - Chef::Runner.new(run_context).converge - return_value - ensure - if run_context.resource_collection.any? { |r| r.updated? } - new_resource.updated_by_last_action(true) - end - @run_context = old_run_context - end - module ClassMethods - CopiedFromChef.extend_chef_module(::Chef::Provider::InlineResources::ClassMethods, self) if defined?(::Chef::Provider::InlineResources::ClassMethods) - def action(name, &block) - # We need the block directly in a method so that `super` works - define_method("compile_action_#{name}", &block) - # We try hard to use `def` because define_method doesn't show the method name in the stack. - begin - class_eval <<-EOM - def action_#{name} - compile_and_converge_action { compile_action_#{name} } - end - EOM - rescue SyntaxError - define_method("action_#{name}") { send("compile_action_#{name}") } - end - end - end - end - protected - end -end -end -end -end diff --git a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider/apt_repository.rb b/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider/apt_repository.rb deleted file mode 100644 index ccc07c4..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider/apt_repository.rb +++ /dev/null @@ -1,269 +0,0 @@ -# -# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE -# -# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!! -# -# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE -# - -begin - require 'chef/provider/apt_repository' -rescue LoadError; end - -require 'chef_compat/copied_from_chef' -class Chef -module ::ChefCompat -module CopiedFromChef -# -# Author:: Thom May () -# Copyright:: Copyright (c) 2016 Chef Software, Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -require "chef_compat/copied_from_chef/chef/resource" -require "chef_compat/copied_from_chef/chef/dsl/declare_resource" -require "chef_compat/copied_from_chef/chef/provider/noop" - -class Chef < (defined?(::Chef) ? ::Chef : Object) - class Provider < (defined?(::Chef::Provider) ? ::Chef::Provider : Object) - class AptRepository < (defined?(::Chef::Provider::AptRepository) ? ::Chef::Provider::AptRepository : Chef::Provider) - use_inline_resources - - include Chef::Mixin::ShellOut - extend Chef::Mixin::Which - - provides :apt_repository do - which("apt-get") - end - - def whyrun_supported? - true - end - - def load_current_resource - end - - action :add do - unless new_resource.key.nil? - if is_key_id?(new_resource.key) && !has_cookbook_file?(new_resource.key) - install_key_from_keyserver - else - install_key_from_uri - end - end - - declare_resource(:execute, "apt-cache gencaches") do - ignore_failure true - action :nothing - end - - declare_resource(:apt_update, new_resource.name) do - ignore_failure true - action :nothing - end - - components = if is_ppa_url?(new_resource.uri) && new_resource.components.empty? - "main" - else - new_resource.components - end - - repo = build_repo( - new_resource.uri, - new_resource.distribution, - components, - new_resource.trusted, - new_resource.arch, - new_resource.deb_src - ) - - declare_resource(:file, "/etc/apt/sources.list.d/#{new_resource.name}.list") do - owner "root" - group "root" - mode "0644" - content repo - sensitive new_resource.sensitive - action :create - notifies :run, "execute[apt-cache gencaches]", :immediately - notifies :update, "apt_update[#{new_resource.name}]", :immediately if new_resource.cache_rebuild - end - end - - action :remove do - if ::File.exist?("/etc/apt/sources.list.d/#{new_resource.name}.list") - converge_by "Removing #{new_resource.name} repository from /etc/apt/sources.list.d/" do - declare_resource(:file, "/etc/apt/sources.list.d/#{new_resource.name}.list") do - sensitive new_resource.sensitive - action :delete - notifies :update, "apt_update[#{new_resource.name}]", :immediately if new_resource.cache_rebuild - end - - declare_resource(:apt_update, new_resource.name) do - ignore_failure true - action :nothing - end - - end - end - end - - def is_key_id?(id) - id = id[2..-1] if id.start_with?("0x") - id =~ /^\h+$/ && [8, 16, 40].include?(id.length) - end - - def extract_fingerprints_from_cmd(cmd) - so = shell_out(cmd) - so.run_command - so.stdout.split(/\n/).map do |t| - if z = t.match(/^ +Key fingerprint = ([0-9A-F ]+)/) - z[1].split.join - end - end.compact - end - - def key_is_valid?(cmd, key) - valid = true - - so = shell_out(cmd) - so.run_command - so.stdout.split(/\n/).map do |t| - if t =~ %r{^\/#{key}.*\[expired: .*\]$} - Chef::Log.debug "Found expired key: #{t}" - valid = false - break - end - end - - Chef::Log.debug "key #{key} #{valid ? "is valid" : "is not valid"}" - valid - end - - def cookbook_name - new_resource.cookbook || new_resource.cookbook_name - end - - def has_cookbook_file?(fn) - run_context.has_cookbook_file_in_cookbook?(cookbook_name, fn) - end - - def no_new_keys?(file) - installed_keys = extract_fingerprints_from_cmd("apt-key finger") - proposed_keys = extract_fingerprints_from_cmd("gpg --with-fingerprint #{file}") - (installed_keys & proposed_keys).sort == proposed_keys.sort - end - - def install_key_from_uri - key_name = new_resource.key.gsub(/[^0-9A-Za-z\-]/, "_") - cached_keyfile = ::File.join(Chef::Config[:file_cache_path], key_name) - type = if new_resource.key.start_with?("http") - :remote_file - elsif has_cookbook_file?(new_resource.key) - :cookbook_file - else - raise Chef::Exceptions::FileNotFound, "Cannot locate key file" - end - - declare_resource(type, cached_keyfile) do - source new_resource.key - mode "0644" - sensitive new_resource.sensitive - action :create - end - - raise "The key #{cached_keyfile} is invalid and cannot be used to verify an apt repository." unless key_is_valid?("gpg #{cached_keyfile}", "") - - declare_resource(:execute, "apt-key add #{cached_keyfile}") do - sensitive new_resource.sensitive - action :run - not_if do - no_new_keys?(cached_keyfile) - end - notifies :run, "execute[apt-cache gencaches]", :immediately - end - end - - def install_key_from_keyserver(key = new_resource.key, keyserver = new_resource.keyserver) - cmd = "apt-key adv --recv" - cmd << " --keyserver-options http-proxy=#{new_resource.key_proxy}" if new_resource.key_proxy - cmd << " --keyserver " - cmd << if keyserver.start_with?("hkp://") - keyserver - else - "hkp://#{keyserver}:80" - end - - cmd << " #{key}" - - declare_resource(:execute, "install-key #{key}") do - command cmd - sensitive new_resource.sensitive - not_if do - present = extract_fingerprints_from_cmd("apt-key finger").any? do |fp| - fp.end_with? key.upcase - end - present && key_is_valid?("apt-key list", key.upcase) - end - notifies :run, "execute[apt-cache gencaches]", :immediately - end - - raise "The key #{key} is invalid and cannot be used to verify an apt repository." unless key_is_valid?("apt-key list", key.upcase) - end - - def install_ppa_key(owner, repo) - url = "https://launchpad.net/api/1.0/~#{owner}/+archive/#{repo}" - key_id = Chef::HTTP::Simple.new(url).get("signing_key_fingerprint").delete('"') - install_key_from_keyserver(key_id, "keyserver.ubuntu.com") - rescue Net::HTTPServerException => e - raise "Could not access Launchpad ppa API: #{e.message}" - end - - def is_ppa_url?(url) - url.start_with?("ppa:") - end - - def make_ppa_url(ppa) - return unless is_ppa_url?(ppa) - owner, repo = ppa[4..-1].split("/") - repo ||= "ppa" - - install_ppa_key(owner, repo) - "http://ppa.launchpad.net/#{owner}/#{repo}/ubuntu" - end - - def build_repo(uri, distribution, components, trusted, arch, add_src = false) - uri = make_ppa_url(uri) if is_ppa_url?(uri) - - uri = '"' + uri + '"' unless uri.start_with?("'", '"') - components = Array(components).join(" ") - options = [] - options << "arch=#{arch}" if arch - options << "trusted=yes" if trusted - optstr = unless options.empty? - "[" + options.join(" ") + "]" - end - info = [ optstr, uri, distribution, components ].compact.join(" ") - repo = "deb #{info}\n" - repo << "deb-src #{info}\n" if add_src - repo - end - end - end -end - -Chef::Provider::Noop.provides :apt_repository -end -end -end diff --git a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider/apt_update.rb b/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider/apt_update.rb deleted file mode 100644 index 677cb57..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider/apt_update.rb +++ /dev/null @@ -1,105 +0,0 @@ -# -# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE -# -# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!! -# -# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE -# - -begin - require 'chef/provider/apt_update' -rescue LoadError; end - -require 'chef_compat/copied_from_chef' -class Chef -module ::ChefCompat -module CopiedFromChef -# -# Author:: Thom May () -# Copyright:: Copyright (c) 2016 Chef Software, Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -require "chef_compat/copied_from_chef/chef/provider" -require "chef_compat/copied_from_chef/chef/provider/noop" - -class Chef < (defined?(::Chef) ? ::Chef : Object) - class Provider < (defined?(::Chef::Provider) ? ::Chef::Provider : Object) - class AptUpdate < (defined?(::Chef::Provider::AptUpdate) ? ::Chef::Provider::AptUpdate : Chef::Provider) - use_inline_resources - - extend Chef::Mixin::Which - - provides :apt_update do - which("apt-get") - end - - APT_CONF_DIR = "/etc/apt/apt.conf.d" - STAMP_DIR = "/var/lib/apt/periodic" - - def whyrun_supported? - true - end - - def load_current_resource - end - - action :periodic do - if !apt_up_to_date? - converge_by "update new lists of packages" do - do_update - end - end - end - - action :update do - converge_by "force update new lists of packages" do - do_update - end - end - - private - - # Determines whether we need to run `apt-get update` - # - # @return [Boolean] - def apt_up_to_date? - ::File.exist?("#{STAMP_DIR}/update-success-stamp") && - ::File.mtime("#{STAMP_DIR}/update-success-stamp") > Time.now - new_resource.frequency - end - - def do_update - [STAMP_DIR, APT_CONF_DIR].each do |d| - declare_resource(:directory, d) do - recursive true - end - end - - declare_resource(:file, "#{APT_CONF_DIR}/15update-stamp") do - content "APT::Update::Post-Invoke-Success {\"touch #{STAMP_DIR}/update-success-stamp 2>/dev/null || true\";};\n" - action :create_if_missing - end - - declare_resource(:execute, "apt-get -q update") - end - - end - end -end - -Chef::Provider::Noop.provides :apt_update -end -end -end diff --git a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider/noop.rb b/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider/noop.rb deleted file mode 100644 index 87c34e6..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider/noop.rb +++ /dev/null @@ -1,56 +0,0 @@ -# -# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE -# -# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!! -# -# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE -# - -begin - require 'chef/provider/noop' -rescue LoadError; end - -require 'chef_compat/copied_from_chef' -class Chef -module ::ChefCompat -module CopiedFromChef -# -# Author:: Thom May () -# Copyright:: Copyright (c) 2016 Chef Software, Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -class Chef < (defined?(::Chef) ? ::Chef : Object) - class Provider < (defined?(::Chef::Provider) ? ::Chef::Provider : Object) - class Noop < (defined?(::Chef::Provider::Noop) ? ::Chef::Provider::Noop : Chef::Provider) - def load_current_resource; end - - def respond_to_missing?(method_sym, include_private = false) - method_sym.to_s.start_with?("action_") || super - end - - def method_missing(method_sym, *arguments, &block) - if method_sym.to_s =~ /^action_/ - Chef::Log.debug("NoOp-ing for #{method_sym}") - else - super - end - end - end - end -end -end -end -end diff --git a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider/systemd_unit.rb b/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider/systemd_unit.rb deleted file mode 100644 index 1024cb8..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider/systemd_unit.rb +++ /dev/null @@ -1,253 +0,0 @@ -# -# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE -# -# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!! -# -# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE -# - -begin - require 'chef/provider/systemd_unit' -rescue LoadError; end - -require 'chef_compat/copied_from_chef' -class Chef -module ::ChefCompat -module CopiedFromChef -# -# Author:: Nathan Williams () -# Copyright:: Copyright 2016, Nathan Williams -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -require "chef_compat/copied_from_chef/chef/provider" - -class Chef < (defined?(::Chef) ? ::Chef : Object) - class Provider < (defined?(::Chef::Provider) ? ::Chef::Provider : Object) - class SystemdUnit < (defined?(::Chef::Provider::SystemdUnit) ? ::Chef::Provider::SystemdUnit : Chef::Provider) - include Chef::Mixin::Which - include Chef::Mixin::ShellOut - - provides :systemd_unit, os: "linux" - - def load_current_resource - @current_resource = Chef::Resource::SystemdUnit.new(new_resource.name) - - current_resource.content(::File.read(unit_path)) if ::File.exist?(unit_path) - current_resource.user(new_resource.user) - current_resource.enabled(enabled?) - current_resource.active(active?) - current_resource.masked(masked?) - current_resource.static(static?) - current_resource.triggers_reload(new_resource.triggers_reload) - - current_resource - end - - def define_resource_requirements - super - - requirements.assert(:create) do |a| - a.assertion { IniParse.parse(new_resource.to_ini) } - a.failure_message "Unit content is not valid INI text" - end - end - - def action_create - if current_resource.content != new_resource.to_ini - converge_by("creating unit: #{new_resource.name}") do - manage_unit_file(:create) - daemon_reload if new_resource.triggers_reload - end - end - end - - def action_delete - if ::File.exist?(unit_path) - converge_by("deleting unit: #{new_resource.name}") do - manage_unit_file(:delete) - daemon_reload if new_resource.triggers_reload - end - end - end - - def action_enable - if current_resource.static - Chef::Log.debug("#{new_resource.name} is a static unit, enabling is a NOP.") - end - - unless current_resource.enabled || current_resource.static - converge_by("enabling unit: #{new_resource.name}") do - systemctl_execute!(:enable, new_resource.name) - end - end - end - - def action_disable - if current_resource.static - Chef::Log.debug("#{new_resource.name} is a static unit, disabling is a NOP.") - end - - if current_resource.enabled && !current_resource.static - converge_by("disabling unit: #{new_resource.name}") do - systemctl_execute!(:disable, new_resource.name) - end - end - end - - def action_mask - unless current_resource.masked - converge_by("masking unit: #{new_resource.name}") do - systemctl_execute!(:mask, new_resource.name) - end - end - end - - def action_unmask - if current_resource.masked - converge_by("unmasking unit: #{new_resource.name}") do - systemctl_execute!(:unmask, new_resource.name) - end - end - end - - def action_start - unless current_resource.active - converge_by("starting unit: #{new_resource.name}") do - systemctl_execute!(:start, new_resource.name) - end - end - end - - def action_stop - if current_resource.active - converge_by("stopping unit: #{new_resource.name}") do - systemctl_execute!(:stop, new_resource.name) - end - end - end - - def action_restart - converge_by("restarting unit: #{new_resource.name}") do - systemctl_execute!(:restart, new_resource.name) - end - end - - def action_reload - if current_resource.active - converge_by("reloading unit: #{new_resource.name}") do - systemctl_execute!(:reload, new_resource.name) - end - else - Chef::Log.debug("#{new_resource.name} is not active, skipping reload.") - end - end - - def action_try_restart - converge_by("try-restarting unit: #{new_resource.name}") do - systemctl_execute!("try-restart", new_resource.name) - end - end - - def action_reload_or_restart - converge_by("reload-or-restarting unit: #{new_resource.name}") do - systemctl_execute!("reload-or-restart", new_resource.name) - end - end - - def action_reload_or_try_restart - converge_by("reload-or-try-restarting unit: #{new_resource.name}") do - systemctl_execute!("reload-or-try-restart", new_resource.name) - end - end - - def active? - systemctl_execute("is-active", new_resource.name).exitstatus == 0 - end - - def enabled? - systemctl_execute("is-enabled", new_resource.name).exitstatus == 0 - end - - def masked? - systemctl_execute(:status, new_resource.name).stdout.include?("masked") - end - - def static? - systemctl_execute("is-enabled", new_resource.name).stdout.include?("static") - end - - private - - def unit_path - if new_resource.user - "/etc/systemd/user/#{new_resource.name}" - else - "/etc/systemd/system/#{new_resource.name}" - end - end - - def manage_unit_file(action = :nothing) - Chef::Resource::File.new(unit_path, run_context).tap do |f| - f.owner "root" - f.group "root" - f.mode "0644" - f.content new_resource.to_ini - end.run_action(action) - end - - def daemon_reload - shell_out_with_systems_locale!("#{systemctl_path} daemon-reload") - end - - def systemctl_execute!(action, unit) - shell_out_with_systems_locale!("#{systemctl_cmd} #{action} #{unit}", systemctl_opts) - end - - def systemctl_execute(action, unit) - shell_out("#{systemctl_cmd} #{action} #{unit}", systemctl_opts) - end - - def systemctl_cmd - @systemctl_cmd ||= "#{systemctl_path} #{systemctl_args}" - end - - def systemctl_path - @systemctl_path ||= which("systemctl") - end - - def systemctl_args - @systemctl_args ||= new_resource.user ? "--user" : "--system" - end - - def systemctl_opts - @systemctl_opts ||= - if new_resource.user - { - :user => new_resource.user, - :environment => { - "DBUS_SESSION_BUS_ADDRESS" => "unix:path=/run/user/#{node['etc']['passwd'][new_resource.user]['uid']}/bus", - }, - } - else - {} - end - end - end - end -end -end -end -end diff --git a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider/yum_repository.rb b/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider/yum_repository.rb deleted file mode 100644 index bfe415e..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider/yum_repository.rb +++ /dev/null @@ -1,137 +0,0 @@ -# -# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE -# -# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!! -# -# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE -# - -begin - require 'chef/provider/yum_repository' -rescue LoadError; end - -require 'chef_compat/copied_from_chef' -class Chef -module ::ChefCompat -module CopiedFromChef -# -# Author:: Thom May () -# Copyright:: Copyright (c) 2016 Chef Software, Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -require "chef_compat/copied_from_chef/chef/resource" -require "chef_compat/copied_from_chef/chef/dsl/declare_resource" -require "chef_compat/copied_from_chef/chef/provider/noop" - -class Chef < (defined?(::Chef) ? ::Chef : Object) - class Provider < (defined?(::Chef::Provider) ? ::Chef::Provider : Object) - class YumRepository < (defined?(::Chef::Provider::YumRepository) ? ::Chef::Provider::YumRepository : Chef::Provider) - use_inline_resources - - extend Chef::Mixin::Which - - provides :yum_repository do - which "yum" - end - - def whyrun_supported?; true; end - - def load_current_resource; end - - action :create do - declare_resource(:template, "/etc/yum.repos.d/#{new_resource.repositoryid}.repo") do - if template_available?(new_resource.source) - source new_resource.source - else - source ::File.expand_path("../support/yum_repo.erb", __FILE__) - local true - end - sensitive new_resource.sensitive - variables(config: new_resource) - mode new_resource.mode - if new_resource.make_cache - notifies :run, "execute[yum clean metadata #{new_resource.repositoryid}]", :immediately if new_resource.clean_metadata || new_resource.clean_headers - notifies :run, "execute[yum-makecache-#{new_resource.repositoryid}]", :immediately - notifies :create, "ruby_block[yum-cache-reload-#{new_resource.repositoryid}]", :immediately - end - end - - declare_resource(:execute, "yum clean metadata #{new_resource.repositoryid}") do - command "yum clean metadata --disablerepo=* --enablerepo=#{new_resource.repositoryid}" - action :nothing - end - - # get the metadata for this repo only - declare_resource(:execute, "yum-makecache-#{new_resource.repositoryid}") do - command "yum -q -y makecache --disablerepo=* --enablerepo=#{new_resource.repositoryid}" - action :nothing - only_if { new_resource.enabled } - end - - # reload internal Chef yum cache - declare_resource(:ruby_block, "yum-cache-reload-#{new_resource.repositoryid}") do - block { Chef::Provider::Package::Yum::YumCache.instance.reload } - action :nothing - end - end - - action :delete do - declare_resource(:file, "/etc/yum.repos.d/#{new_resource.repositoryid}.repo") do - action :delete - notifies :run, "execute[yum clean all #{new_resource.repositoryid}]", :immediately - notifies :create, "ruby_block[yum-cache-reload-#{new_resource.repositoryid}]", :immediately - end - - declare_resource(:execute, "yum clean all #{new_resource.repositoryid}") do - command "yum clean all --disablerepo=* --enablerepo=#{new_resource.repositoryid}" - only_if "yum repolist | grep -P '^#{new_resource.repositoryid}([ \t]|$)'" - action :nothing - end - - declare_resource(:ruby_block, "yum-cache-reload-#{new_resource.repositoryid}") do - block { Chef::Provider::Package::Yum::YumCache.instance.reload } - action :nothing - end - end - - action :makecache do - declare_resource(:execute, "yum-makecache-#{new_resource.repositoryid}") do - command "yum -q -y makecache --disablerepo=* --enablerepo=#{new_resource.repositoryid}" - action :run - only_if { new_resource.enabled } - end - - declare_resource(:ruby_block, "yum-cache-reload-#{new_resource.repositoryid}") do - block { Chef::Provider::Package::Yum::YumCache.instance.reload } - action :run - end - end - - alias_method :action_add, :action_create - alias_method :action_remove, :action_delete - - def template_available?(path) - !path.nil? && run_context.has_template_in_cookbook?(new_resource.cookbook_name, path) - end - - end - end -end - -Chef::Provider::Noop.provides :yum_repository -end -end -end diff --git a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/resource.rb b/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/resource.rb deleted file mode 100644 index e5c9a14..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/resource.rb +++ /dev/null @@ -1,214 +0,0 @@ -# -# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE -# -# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!! -# -# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE -# - -begin - require 'chef/resource' -rescue LoadError; end - -require 'chef_compat/copied_from_chef' -class Chef -module ::ChefCompat -module CopiedFromChef -require "chef_compat/copied_from_chef/chef/resource/action_class" -require "chef_compat/copied_from_chef/chef/provider" -require "chef_compat/copied_from_chef/chef/mixin/properties" -require "chef_compat/copied_from_chef/chef/dsl/universal" -class Chef < (defined?(::Chef) ? ::Chef : Object) - class Resource < (defined?(::Chef::Resource) ? ::Chef::Resource : Object) - include Chef::Mixin::Properties - property :name, String, coerce: proc { |v| v.is_a?(Array) ? v.join(", ") : v.to_s }, desired_state: false - def initialize(name, run_context = nil) -super if defined?(::Chef::Resource) - name(name) unless name.nil? - @run_context = run_context - @noop = nil - @before = nil - @params = Hash.new - @provider = nil - @allowed_actions = self.class.allowed_actions.to_a - @action = self.class.default_action - @updated = false - @updated_by_last_action = false - @supports = {} - @ignore_failure = false - @retries = 0 - @retry_delay = 2 - @not_if = [] - @only_if = [] - @source_line = nil - # We would like to raise an error when the user gives us a guard - # interpreter and a ruby_block to the guard. In order to achieve this - # we need to understand when the user overrides the default guard - # interpreter. Therefore we store the default separately in a different - # attribute. - @guard_interpreter = nil - @default_guard_interpreter = :default - @elapsed_time = 0 - @sensitive = false - end - def action(arg = nil) - if arg - arg = Array(arg).map(&:to_sym) - arg.each do |action| - validate( - { action: action }, - { action: { kind_of: Symbol, equal_to: allowed_actions } } - ) - end - @action = arg - else - @action - end - end - alias_method :action=, :action - class UnresolvedSubscribes < (defined?(::Chef::Resource::UnresolvedSubscribes) ? ::Chef::Resource::UnresolvedSubscribes : self) - alias_method :to_s, :name - alias_method :declared_key, :name - end - def state_for_resource_reporter - state = {} - state_properties = self.class.state_properties - state_properties.each do |property| - if property.identity? || property.is_set?(self) - state[property.name] = property.sensitive? ? "*sensitive value suppressed*" : send(property.name) - end - end - state - end - alias_method :state, :state_for_resource_reporter - def identity - result = {} - identity_properties = self.class.identity_properties - identity_properties.each do |property| - result[property.name] = send(property.name) - end - return result.values.first if identity_properties.size == 1 - result - end - attr_reader :resource_initializing - def resource_initializing=(value) - if value - @resource_initializing = true - else - remove_instance_variable(:@resource_initializing) - end - end - def to_hash - # Grab all current state, then any other ivars (backcompat) - result = {} - self.class.state_properties.each do |p| - result[p.name] = p.get(self) - end - safe_ivars = instance_variables.map { |ivar| ivar.to_sym } - FORBIDDEN_IVARS - safe_ivars.each do |iv| - key = iv.to_s.sub(/^@/, "").to_sym - next if result.has_key?(key) - result[key] = instance_variable_get(iv) - end - result - end - def self.identity_property(name = nil) - result = identity_properties(*Array(name)) - if result.size > 1 - raise Chef::Exceptions::MultipleIdentityError, "identity_property cannot be called on an object with more than one identity property (#{result.map { |r| r.name }.join(", ")})." - end - result.first - end - attr_accessor :allowed_actions - def allowed_actions(value = NOT_PASSED) - if value != NOT_PASSED - self.allowed_actions = value - end - @allowed_actions - end - def resource_name - @resource_name || self.class.resource_name - end - def self.use_automatic_resource_name - automatic_name = convert_to_snake_case(self.name.split("::")[-1]) - resource_name automatic_name - end - def self.allowed_actions(*actions) - @allowed_actions ||= - if superclass.respond_to?(:allowed_actions) - superclass.allowed_actions.dup - else - [ :nothing ] - end - @allowed_actions |= actions.flatten - end - def self.allowed_actions=(value) - @allowed_actions = value.uniq - end - def self.default_action(action_name = NOT_PASSED) - unless action_name.equal?(NOT_PASSED) - @default_action = Array(action_name).map(&:to_sym) - self.allowed_actions |= @default_action - end - - if @default_action - @default_action - elsif superclass.respond_to?(:default_action) - superclass.default_action - else - [:nothing] - end - end - def self.default_action=(action_name) - default_action action_name - end - def self.action(action, &recipe_block) - action = action.to_sym - declare_action_class - action_class.action(action, &recipe_block) - self.allowed_actions += [ action ] - default_action action if Array(default_action) == [:nothing] - end - def self.load_current_value(&load_block) - define_method(:load_current_value!, &load_block) - end - def current_value_does_not_exist! - raise Chef::Exceptions::CurrentValueDoesNotExist - end - def self.action_class(&block) - return @action_class if @action_class && !block - # If the superclass needed one, then we need one as well. - if block || (superclass.respond_to?(:action_class) && superclass.action_class) - @action_class = declare_action_class(&block) - end - @action_class - end - def self.declare_action_class(&block) - @action_class ||= begin - if superclass.respond_to?(:action_class) - base_provider = superclass.action_class - end - base_provider ||= Chef::Provider - - resource_class = self - Class.new(base_provider) do - include ActionClass - self.resource_class = resource_class - end - end - @action_class.class_eval(&block) if block - @action_class - end - FORBIDDEN_IVARS = [:@run_context, :@not_if, :@only_if, :@enclosing_provider] - HIDDEN_IVARS = [:@allowed_actions, :@resource_name, :@source_line, :@run_context, :@name, :@not_if, :@only_if, :@elapsed_time, :@enclosing_provider] - class << self - end - @@sorted_descendants = nil - module DeprecatedLWRPClass - CopiedFromChef.extend_chef_module(::Chef::Resource::DeprecatedLWRPClass, self) if defined?(::Chef::Resource::DeprecatedLWRPClass) - end - end -end -end -end -end diff --git a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/resource/action_class.rb b/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/resource/action_class.rb deleted file mode 100644 index 20ff8e5..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/resource/action_class.rb +++ /dev/null @@ -1,114 +0,0 @@ -# -# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE -# -# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!! -# -# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE -# - -begin - require 'chef/resource/action_class' -rescue LoadError; end - -require 'chef_compat/copied_from_chef' -class Chef -module ::ChefCompat -module CopiedFromChef -# -# Author:: John Keiser ("} action #{action ? action.inspect : ""}" - end - - def whyrun_supported? - true - end - - # - # If load_current_value! is defined on the resource, use that. - # - def load_current_resource - if new_resource.respond_to?(:load_current_value!) - # dup the resource and then reset desired-state properties. - current_resource = new_resource.dup - - # We clear desired state in the copy, because it is supposed to be actual state. - # We keep identity properties and non-desired-state, which are assumed to be - # "control" values like `recurse: true` - current_resource.class.properties.each do |name, property| - if property.desired_state? && !property.identity? && !property.name_property? - property.reset(current_resource) - end - end - - # Call the actual load_current_value! method. If it raises - # CurrentValueDoesNotExist, set current_resource to `nil`. - begin - # If the user specifies load_current_value do |desired_resource|, we - # pass in the desired resource as well as the current one. - if current_resource.method(:load_current_value!).arity > 0 - current_resource.load_current_value!(new_resource) - else - current_resource.load_current_value! - end - rescue Chef::Exceptions::CurrentValueDoesNotExist - current_resource = nil - end - end - - @current_resource = current_resource - end - - def self.included(other) - other.extend(ClassMethods) - other.use_inline_resources - other.include_resource_dsl true - end - - module ClassMethods - CopiedFromChef.extend_chef_module(::Chef::Resource::ActionClass::ClassMethods, self) if defined?(::Chef::Resource::ActionClass::ClassMethods) - # - # The Chef::Resource class this ActionClass was declared against. - # - # @return [Class] The Chef::Resource class this ActionClass was declared against. - # - attr_accessor :resource_class - - def to_s - "#{resource_class} action provider" - end - - def inspect - to_s - end - end - end - end -end -end -end -end diff --git a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/resource/apt_repository.rb b/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/resource/apt_repository.rb deleted file mode 100644 index 1580fad..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/resource/apt_repository.rb +++ /dev/null @@ -1,66 +0,0 @@ -# -# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE -# -# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!! -# -# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE -# - -begin - require 'chef/resource/apt_repository' -rescue LoadError; end - -require 'chef_compat/copied_from_chef' -class Chef -module ::ChefCompat -module CopiedFromChef -# -# Author:: Thom May () -# Copyright:: Copyright (c) 2016 Chef Software, Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -require "chef_compat/copied_from_chef/chef/resource" - -class Chef < (defined?(::Chef) ? ::Chef : Object) - class Resource < (defined?(::Chef::Resource) ? ::Chef::Resource : Object) - class AptRepository < (defined?(::Chef::Resource::AptRepository) ? ::Chef::Resource::AptRepository : Chef::Resource) - resource_name :apt_repository - provides :apt_repository - - property :repo_name, String, name_property: true - property :uri, String - property :distribution, [ String, nil, false ], default: lazy { node["lsb"]["codename"] }, nillable: true, coerce: proc { |x| x ? x : nil } - property :components, Array, default: [] - property :arch, [String, nil, false], default: nil, nillable: true, coerce: proc { |x| x ? x : nil } - property :trusted, [TrueClass, FalseClass], default: false - # whether or not to add the repository as a source repo, too - property :deb_src, [TrueClass, FalseClass], default: false - property :keyserver, [String, nil, false], default: "keyserver.ubuntu.com", nillable: true, coerce: proc { |x| x ? x : nil } - property :key, [String, nil, false], default: nil, nillable: true, coerce: proc { |x| x ? x : nil } - property :key_proxy, [String, nil, false], default: nil, nillable: true, coerce: proc { |x| x ? x : nil } - - property :cookbook, [String, nil, false], default: nil, desired_state: false, nillable: true, coerce: proc { |x| x ? x : nil } - property :cache_rebuild, [TrueClass, FalseClass], default: true, desired_state: false - property :sensitive, [TrueClass, FalseClass], default: false, desired_state: false - - default_action :add - allowed_actions :add, :remove - end - end -end -end -end -end diff --git a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/resource/apt_update.rb b/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/resource/apt_update.rb deleted file mode 100644 index 31f5dc3..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/resource/apt_update.rb +++ /dev/null @@ -1,52 +0,0 @@ -# -# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE -# -# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!! -# -# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE -# - -begin - require 'chef/resource/apt_update' -rescue LoadError; end - -require 'chef_compat/copied_from_chef' -class Chef -module ::ChefCompat -module CopiedFromChef -# -# Author:: Thom May () -# Copyright:: Copyright (c) 2016 Chef Software, Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -require "chef_compat/copied_from_chef/chef/resource" - -class Chef < (defined?(::Chef) ? ::Chef : Object) - class Resource < (defined?(::Chef::Resource) ? ::Chef::Resource : Object) - class AptUpdate < (defined?(::Chef::Resource::AptUpdate) ? ::Chef::Resource::AptUpdate : Chef::Resource) - resource_name :apt_update - provides :apt_update, os: "linux" - - property :frequency, Integer, default: 86_400 - - default_action :periodic - allowed_actions :update, :periodic - end - end -end -end -end -end diff --git a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/resource/systemd_unit.rb b/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/resource/systemd_unit.rb deleted file mode 100644 index 5f9f458..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/resource/systemd_unit.rb +++ /dev/null @@ -1,81 +0,0 @@ -# -# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE -# -# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!! -# -# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE -# - -begin - require 'chef/resource/systemd_unit' -rescue LoadError; end - -require 'chef_compat/copied_from_chef' -class Chef -module ::ChefCompat -module CopiedFromChef -# -# Author:: Nathan Williams () -# Copyright:: Copyright 2016, Nathan Williams -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -require "chef_compat/copied_from_chef/chef/resource" - -class Chef < (defined?(::Chef) ? ::Chef : Object) - class Resource < (defined?(::Chef::Resource) ? ::Chef::Resource : Object) - class SystemdUnit < (defined?(::Chef::Resource::SystemdUnit) ? ::Chef::Resource::SystemdUnit : Chef::Resource) - resource_name :systemd_unit - - default_action :nothing - allowed_actions :create, :delete, - :enable, :disable, - :mask, :unmask, - :start, :stop, - :restart, :reload, - :try_restart, :reload_or_restart, - :reload_or_try_restart - - property :enabled, [TrueClass, FalseClass] - property :active, [TrueClass, FalseClass] - property :masked, [TrueClass, FalseClass] - property :static, [TrueClass, FalseClass] - property :user, String, desired_state: false - property :content, [String, Hash] - property :triggers_reload, [TrueClass, FalseClass], - default: true, desired_state: false - - def to_ini - case content - when Hash - IniParse.gen do |doc| - content.each_pair do |sect, opts| - doc.section(sect) do |section| - opts.each_pair do |opt, val| - section.option(opt, val) - end - end - end - end.to_s - else - content.to_s - end - end - end - end -end -end -end -end diff --git a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/resource/yum_repository.rb b/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/resource/yum_repository.rb deleted file mode 100644 index e733daa..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/resource/yum_repository.rb +++ /dev/null @@ -1,98 +0,0 @@ -# -# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE -# -# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!! -# -# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE -# - -begin - require 'chef/resource/yum_repository' -rescue LoadError; end - -require 'chef_compat/copied_from_chef' -class Chef -module ::ChefCompat -module CopiedFromChef -# -# Author:: Thom May () -# Copyright:: Copyright (c) 2016 Chef Software, Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -require "chef_compat/copied_from_chef/chef/resource" - -class Chef < (defined?(::Chef) ? ::Chef : Object) - class Resource < (defined?(::Chef::Resource) ? ::Chef::Resource : Object) - class YumRepository < (defined?(::Chef::Resource::YumRepository) ? ::Chef::Resource::YumRepository : Chef::Resource) - resource_name :yum_repository - provides :yum_repository - - # http://linux.die.net/man/5/yum.conf - property :baseurl, String, regex: /.*/ - property :cost, String, regex: /^\d+$/ - property :clean_headers, [TrueClass, FalseClass], default: false # deprecated - property :clean_metadata, [TrueClass, FalseClass], default: true - property :description, String, regex: /.*/, default: "Yum Repository" - property :enabled, [TrueClass, FalseClass], default: true - property :enablegroups, [TrueClass, FalseClass] - property :exclude, String, regex: /.*/ - property :failovermethod, String, equal_to: %w{priority roundrobin} - property :fastestmirror_enabled, [TrueClass, FalseClass] - property :gpgcheck, [TrueClass, FalseClass], default: true - property :gpgkey, [String, Array], regex: /.*/ - property :http_caching, String, equal_to: %w{packages all none} - property :include_config, String, regex: /.*/ - property :includepkgs, String, regex: /.*/ - property :keepalive, [TrueClass, FalseClass] - property :make_cache, [TrueClass, FalseClass], default: true - property :max_retries, [String, Integer] - property :metadata_expire, String, regex: [/^\d+$/, /^\d+[mhd]$/, /never/] - property :mirrorexpire, String, regex: /.*/ - property :mirrorlist, String, regex: /.*/ - property :mirror_expire, String, regex: [/^\d+$/, /^\d+[mhd]$/] - property :mirrorlist_expire, String, regex: [/^\d+$/, /^\d+[mhd]$/] - property :mode, default: "0644" - property :priority, String, regex: /^(\d?[0-9]|[0-9][0-9])$/ - property :proxy, String, regex: /.*/ - property :proxy_username, String, regex: /.*/ - property :proxy_password, String, regex: /.*/ - property :username, String, regex: /.*/ - property :password, String, regex: /.*/ - property :repo_gpgcheck, [TrueClass, FalseClass] - property :report_instanceid, [TrueClass, FalseClass] - property :repositoryid, String, regex: /.*/, name_property: true - property :sensitive, [TrueClass, FalseClass], default: false - property :skip_if_unavailable, [TrueClass, FalseClass] - property :source, String, regex: /.*/ - property :sslcacert, String, regex: /.*/ - property :sslclientcert, String, regex: /.*/ - property :sslclientkey, String, regex: /.*/ - property :sslverify, [TrueClass, FalseClass] - property :timeout, String, regex: /^\d+$/ - property :options, Hash - - default_action :create - allowed_actions :create, :remove, :makecache, :add, :delete - - # provide compatibility with the yum cookbook < 3.0 properties - alias_method :url, :baseurl - alias_method :keyurl, :gpgkey - end - end -end -end -end -end diff --git a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/resource_builder.rb b/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/resource_builder.rb deleted file mode 100644 index 688e856..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/resource_builder.rb +++ /dev/null @@ -1,174 +0,0 @@ -# -# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE -# -# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!! -# -# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE -# - -begin - require 'chef/resource_builder' -rescue LoadError; end - -require 'chef_compat/copied_from_chef' -class Chef -module ::ChefCompat -module CopiedFromChef -# -# Author:: Lamont Granquist () -# Copyright:: Copyright 2015-2016, Chef Software, Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -# NOTE: this was extracted from the Recipe DSL mixin, relevant specs are in spec/unit/recipe_spec.rb - -class Chef < (defined?(::Chef) ? ::Chef : Object) - class ResourceBuilder < (defined?(::Chef::ResourceBuilder) ? ::Chef::ResourceBuilder : Object) - attr_reader :type - attr_reader :name - attr_reader :created_at - attr_reader :params - attr_reader :run_context - attr_reader :cookbook_name - attr_reader :recipe_name - attr_reader :enclosing_provider - attr_reader :resource - - # FIXME (ruby-2.1 syntax): most of these are mandatory - def initialize(type: nil, name: nil, created_at: nil, params: nil, run_context: nil, cookbook_name: nil, recipe_name: nil, enclosing_provider: nil) -super if defined?(::Chef::ResourceBuilder) - @type = type - @name = name - @created_at = created_at - @params = params - @run_context = run_context - @cookbook_name = cookbook_name - @recipe_name = recipe_name - @enclosing_provider = enclosing_provider - end - - def build(&block) - raise ArgumentError, "You must supply a name when declaring a #{type} resource" if name.nil? - - @resource = resource_class.new(name, run_context) - if resource.resource_name.nil? - raise Chef::Exceptions::InvalidResourceSpecification, "#{resource}.resource_name is `nil`! Did you forget to put `provides :blah` or `resource_name :blah` in your resource class?" - end - resource.source_line = created_at - resource.declared_type = type - - # If we have a resource like this one, we want to steal its state - # This behavior is very counter-intuitive and should be removed. - # See CHEF-3694, https://tickets.opscode.com/browse/CHEF-3694 - # Moved to this location to resolve CHEF-5052, https://tickets.opscode.com/browse/CHEF-5052 - if prior_resource - resource.load_from(prior_resource) - end - - resource.cookbook_name = cookbook_name - resource.recipe_name = recipe_name - # Determine whether this resource is being created in the context of an enclosing Provider - resource.enclosing_provider = enclosing_provider - - # XXX: this is required for definition params inside of the scope of a - # subresource to work correctly. - resource.params = params - - # Evaluate resource attribute DSL - if block_given? - resource.resource_initializing = true - begin - resource.instance_eval(&block) - ensure - resource.resource_initializing = false - end - end - - # emit a cloned resource warning if it is warranted - if prior_resource - if is_trivial_resource?(prior_resource) && identicalish_resources?(prior_resource, resource) - emit_harmless_cloning_debug - else - emit_cloned_resource_warning - end - end - - # Run optional resource hook - resource.after_created - - resource - end - - private - - def resource_class - # Checks the new platform => short_name => resource mapping initially - # then fall back to the older approach (Chef::Resource.const_get) for - # backward compatibility - @resource_class ||= Chef::Resource.resource_for_node(type, run_context.node) - end - - def is_trivial_resource?(resource) - trivial_resource = resource_class.new(name, run_context) - # force un-lazy the name property on the created trivial resource - name_property = resource_class.properties.find { |sym, p| p.name_property? } - trivial_resource.send(name_property[0]) unless name_property.nil? - identicalish_resources?(trivial_resource, resource) - end - - # this is an equality test specific to checking for 3694 cloning warnings - def identicalish_resources?(first, second) - skipped_ivars = [ :@source_line, :@cookbook_name, :@recipe_name, :@params, :@elapsed_time, :@declared_type ] - checked_ivars = ( first.instance_variables | second.instance_variables ) - skipped_ivars - non_matching_ivars = checked_ivars.reject do |iv| - if iv == :@action && ( [first.instance_variable_get(iv)].flatten == [:nothing] || [second.instance_variable_get(iv)].flatten == [:nothing] ) - # :nothing action on either side of the comparison always matches - true - else - first.instance_variable_get(iv) == second.instance_variable_get(iv) - end - end - Chef::Log.debug("ivars which did not match with the prior resource: #{non_matching_ivars}") - non_matching_ivars.empty? - end - - def emit_cloned_resource_warning - message = "Cloning resource attributes for #{resource} from prior resource (CHEF-3694)" - message << "\nPrevious #{prior_resource}: #{prior_resource.source_line}" if prior_resource.source_line - message << "\nCurrent #{resource}: #{resource.source_line}" if resource.source_line - Chef.log_deprecation(message) - end - - def emit_harmless_cloning_debug - Chef::Log.debug("Harmless resource cloning from #{prior_resource}:#{prior_resource.source_line} to #{resource}:#{resource.source_line}") - end - - def prior_resource - @prior_resource ||= - begin - key = "#{type}[#{name}]" - run_context.resource_collection.lookup_local(key) - rescue Chef::Exceptions::ResourceNotFound - nil - end - end - - end -end - -require "chef_compat/copied_from_chef/chef/resource" -end -end -end diff --git a/cookbooks/compat_resource/files/lib/chef_compat/mixin/properties.rb b/cookbooks/compat_resource/files/lib/chef_compat/mixin/properties.rb deleted file mode 100644 index a3920d1..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/mixin/properties.rb +++ /dev/null @@ -1,8 +0,0 @@ -require 'chef_compat/monkeypatches' -require 'chef_compat/copied_from_chef/chef/mixin/properties' - -module ChefCompat - module Mixin - Properties = ChefCompat::CopiedFromChef::Chef::Mixin::Properties - end -end diff --git a/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches.rb b/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches.rb deleted file mode 100644 index 9ac83e8..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches.rb +++ /dev/null @@ -1,41 +0,0 @@ -class Chef - class RunContext - class ChildRunContext < RunContext - # magic that lets us re-parse the ChildRunContext without erroring due to - # cheffish and chef-provisioning hooks having been loaded (on old versions of - # chef-client without the lazy hooks for those gems) - @__skip_method_checking = true - end - end -end - -# fix to quiet constant redefined warnings -if defined?(Chef::RunContext::ChildRunContext::CHILD_STATE) - Chef::RunContext::ChildRunContext.send(:remove_const, :CHILD_STATE) -end - -require 'chef_compat/monkeypatches/chef' -require 'chef_compat/monkeypatches/chef/exceptions' -require 'chef_compat/monkeypatches/chef/log' -require 'chef_compat/monkeypatches/chef/node' -require 'chef_compat/monkeypatches/chef/mixin/params_validate' -require 'chef_compat/monkeypatches/chef/property' -require 'chef_compat/monkeypatches/chef/provider' -require 'chef_compat/monkeypatches/chef/recipe' # copied from chef -require 'chef_compat/monkeypatches/chef/recipe_hook' -require 'chef_compat/monkeypatches/chef/resource' -require 'chef_compat/monkeypatches/chef/resource_builder' -require 'chef_compat/monkeypatches/chef/resource/lwrp_base' -require 'chef_compat/monkeypatches/chef/resource_collection' -require 'chef_compat/monkeypatches/chef/resource_collection/resource_list' -require 'chef_compat/monkeypatches/chef/resource_collection/resource_set' -require 'chef_compat/monkeypatches/chef/run_context' # copied from chef -require 'chef_compat/monkeypatches/chef/runner' # copied from chef - -# fix for Chef::RunContext instance that has already been created -ObjectSpace.each_object(Chef::RunContext) do |run_context| - run_context.node.run_context = run_context - run_context.instance_variable_set(:@loaded_recipes_hash, {}) - run_context.instance_variable_set(:@loaded_attributes_hash, {}) - run_context.initialize_child_state -end diff --git a/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef.rb b/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef.rb deleted file mode 100644 index 9669f6a..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef.rb +++ /dev/null @@ -1,33 +0,0 @@ -class Chef - NOT_PASSED = Object.new if !defined?(NOT_PASSED) - # Earlier versions of Chef didn't have this message - module ChefCompatDeprecation - def log_deprecation(message, location=nil) - if !location - # Pick the first caller that is *not* part of the Chef or ChefCompat gem, - # that's the thing the user wrote. - chef_compat_gem_path = File.expand_path("../../..", __FILE__) - chef_gem_path = File.expand_path("../..",::Chef::Resource.instance_method(:initialize).source_location[0]) - caller(0..10).each do |c| - if !c.start_with?(chef_gem_path) && !c.start_with?(chef_compat_gem_path) - location = c - break - end - end - end - - begin - super - # Bleagh. `super_method` doesn't exist on older rubies and I haven't - # figured out a way to check for its existence otherwise. - rescue NoMethodError - Chef::Log.warn(message) - end - end - end - - class<= 12.5 && Chef::VERSION.to_f <= 12.8 - require 'chef/mixin/params_validate' - class Chef - module Mixin - module ParamsValidate - class SetOrReturnProperty < Chef::Property - # 12.9 introduced a new optional parameter to `get()` to avoid a nil-set warning. - # When their method gets called with 2 args, we need to ignore and call with 1. - alias_method :_original_get2, :get - def get(resource, *args) - _original_get2(resource) - end - end - end - end - end -end diff --git a/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/node.rb b/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/node.rb deleted file mode 100644 index 93379b0..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/node.rb +++ /dev/null @@ -1,9 +0,0 @@ -class Chef - class Node - unless method_defined?(:set_cookbook_attribute) - def set_cookbook_attribute - # this implementation deliberately left blank - we don't need to do anything we just need to not fail - end - end - end -end diff --git a/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/property.rb b/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/property.rb deleted file mode 100644 index 2308d32..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/property.rb +++ /dev/null @@ -1,15 +0,0 @@ -# 12.9 introduced a new optional parameter to `get()` to avoid a nil-set warning. -# We need to mimick it here. -if Chef::VERSION.to_f >= 12.5 && Chef::VERSION.to_f <= 12.8 - require 'chef/property' - class Chef - class Property - # 12.9 introduced a new optional parameter to `get()` to avoid a nil-set warning. - # When their method gets called with 2 args, we need to ignore and call with 1. - alias_method :_original_get, :get - def get(resource, *args) - _original_get(resource) - end - end - end -end diff --git a/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/provider.rb b/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/provider.rb deleted file mode 100644 index 591cedb..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/provider.rb +++ /dev/null @@ -1,65 +0,0 @@ -require 'chef/provider' -require 'chef/provider/lwrp_base' - -class Chef::Provider - if !defined?(InlineResources) - InlineResources = Chef::Provider::LWRPBase::InlineResources - end - module InlineResources - require 'chef/dsl/recipe' - require 'chef/dsl/platform_introspection' - require 'chef/dsl/data_query' - require 'chef/dsl/include_recipe' - include Chef::DSL::Recipe - include Chef::DSL::PlatformIntrospection - include Chef::DSL::DataQuery - include Chef::DSL::IncludeRecipe - - unless Chef::Provider::InlineResources::ClassMethods.instance_method(:action).source_location[0] =~ /chefspec/ - # Don't override action if chefspec is doing its thing - module ::ChefCompat - module Monkeypatches - module InlineResources - module ClassMethods - def action(name, &block) - super(name) { send("compile_action_#{name}") } - # We put the action in its own method so that super() works. - define_method("compile_action_#{name}", &block) - end - end - end - end - end - module ClassMethods - prepend ChefCompat::Monkeypatches::InlineResources::ClassMethods - end - end - end -end - - -class Chef - class Provider - class LWRPBase < Provider - if defined?(InlineResources) - module InlineResources - # since we upgrade the Chef::Runner and Chef::RunContext globally to >= 12.14 style classes, we need to also - # fix the use_inline_resources LWRPBase wrapper that creates a sub-resource collection with the ugpraded code - # from the Chef::Provider subclasses that do similar things in post-12.5 chef. - def recipe_eval_with_update_check(&block) - old_run_context = run_context - @run_context = run_context.create_child - return_value = instance_eval(&block) - Chef::Runner.new(run_context).converge - return_value - ensure - if run_context.resource_collection.any? { |r| r.updated? } - new_resource.updated_by_last_action(true) - end - @run_context = old_run_context - end - end - end - end - end -end diff --git a/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/recipe.rb b/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/recipe.rb deleted file mode 100644 index 7c4c8be..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/recipe.rb +++ /dev/null @@ -1,118 +0,0 @@ -# -# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE -# -# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!! -# -# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE -# - -if Gem::Requirement.new('< 12.16.42').satisfied_by?(Gem::Version.new(Chef::VERSION)) -#-- -# Author:: Adam Jacob () -# Author:: Christopher Walters () -# Copyright:: Copyright 2008-2016, Chef Software Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -require "chef/dsl/recipe" -require "chef/mixin/from_file" -require "chef/mixin/deprecation" - -class Chef - # == Chef::Recipe - # A Recipe object is the context in which Chef recipes are evaluated. - class Recipe - attr_accessor :cookbook_name, :recipe_name, :recipe, :params, :run_context - - include Chef::DSL::Recipe - - include Chef::Mixin::FromFile - include Chef::Mixin::Deprecation - - # Parses a potentially fully-qualified recipe name into its - # cookbook name and recipe short name. - # - # For example: - # "aws::elastic_ip" returns [:aws, "elastic_ip"] - # "aws" returns [:aws, "default"] - # "::elastic_ip" returns [ current_cookbook, "elastic_ip" ] - #-- - # TODO: Duplicates functionality of RunListItem - def self.parse_recipe_name(recipe_name, current_cookbook: nil) - case recipe_name - when /(.+?)::(.+)/ - [ $1.to_sym, $2 ] - when /^::(.+)/ - raise "current_cookbook is nil, cannot resolve #{recipe_name}" if current_cookbook.nil? - [ current_cookbook.to_sym, $1 ] - else - [ recipe_name.to_sym, "default" ] - end - end - - def initialize(cookbook_name, recipe_name, run_context) - @cookbook_name = cookbook_name - @recipe_name = recipe_name - @run_context = run_context - # TODO: 5/19/2010 cw/tim: determine whether this can be removed - @params = Hash.new - end - - # Used in DSL mixins - def node - run_context.node - end - - # Used by the DSL to look up resources when executing in the context of a - # recipe. - def resources(*args) - run_context.resource_collection.find(*args) - end - - # This was moved to Chef::Node#tag, redirecting here for compatibility - def tag(*tags) - run_context.node.tag(*tags) - end - - # Returns true if the node is tagged with *all* of the supplied +tags+. - # - # === Parameters - # tags:: A list of tags - # - # === Returns - # true:: If all the parameters are present - # false:: If any of the parameters are missing - def tagged?(*tags) - tags.each do |tag| - return false unless run_context.node.tags.include?(tag) - end - true - end - - # Removes the list of tags from the node. - # - # === Parameters - # tags:: A list of tags - # - # === Returns - # tags:: The current list of run_context.node.tags - def untag(*tags) - tags.each do |tag| - run_context.node.tags.delete(tag) - end - end - end -end -end diff --git a/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/recipe_hook.rb b/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/recipe_hook.rb deleted file mode 100644 index 24aa20f..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/recipe_hook.rb +++ /dev/null @@ -1,20 +0,0 @@ -require 'chef/recipe' -require 'chef_compat/recipe' - -class Chef::Recipe - # If the cookbook depends on compat_resource, create a ChefCompat::Recipe object - # instead of Chef::Recipe, for the extra goodies. - def self.new(cookbook_name, recipe_name, run_context) - if run_context && - cookbook_name && - recipe_name && - run_context.cookbook_collection && - run_context.cookbook_collection[cookbook_name] && - run_context.cookbook_collection[cookbook_name].metadata.dependencies.has_key?('compat_resource') && - self != ::ChefCompat::Recipe - ::ChefCompat::Recipe.new(cookbook_name, recipe_name, run_context) - else - super - end - end -end diff --git a/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/resource.rb b/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/resource.rb deleted file mode 100644 index d61b60b..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/resource.rb +++ /dev/null @@ -1,156 +0,0 @@ -# this is NOT an AUTOGENERATED file - -require 'chef/resource' - -class Chef - class Resource - - class UnresolvedSubscribes < self - # The full key ise given as the name in {Resource#subscribes} - alias_method :to_s, :name - alias_method :declared_key, :name - end - - # - # Force a delayed notification into this resource's run_context. - # - # This should most likely be paired with action :nothing - # - # @param arg [Array[Symbol], Symbol] A list of actions (e.g. `:create`) - # - def delayed_action(arg) - arg = Array(arg).map(&:to_sym) - arg.map do |action| - validate( - { action: action }, - { action: { kind_of: Symbol, equal_to: allowed_actions } } - ) - # the resource effectively sends a delayed notification to itself - run_context.add_delayed_action(Notification.new(self, action, self)) - end - end - - def subscribes(action, resources, timing = :delayed) - resources = [resources].flatten - resources.each do |resource| - if resource.is_a?(String) - resource = UnresolvedSubscribes.new(resource, run_context) - end - if resource.run_context.nil? - resource.run_context = run_context - end - resource.notifies(action, self, timing) - end - true - end - - def notifies(action, resource_spec, timing = :delayed) - # when using old-style resources(:template => "/foo.txt") style, you - # could end up with multiple resources. - validate_resource_spec!(resource_spec) - - resources = [ resource_spec ].flatten - resources.each do |resource| - - case timing.to_s - when "delayed" - notifies_delayed(action, resource) - when "immediate", "immediately" - notifies_immediately(action, resource) - when "before" - notifies_before(action, resource) - else - raise ArgumentError, "invalid timing: #{timing} for notifies(#{action}, #{resources.inspect}, #{timing}) resource #{self} "\ - "Valid timings are: :delayed, :immediate, :immediately, :before" - end - end - - true - end - - # - # Iterates over all immediate and delayed notifications, calling - # resolve_resource_reference on each in turn, causing them to - # resolve lazy/forward references. - def resolve_notification_references - run_context.before_notifications(self).each { |n| - n.resolve_resource_reference(run_context.resource_collection) - } - run_context.immediate_notifications(self).each { |n| - n.resolve_resource_reference(run_context.resource_collection) - } - run_context.delayed_notifications(self).each {|n| - n.resolve_resource_reference(run_context.resource_collection) - } - end - - # Helper for #notifies - def notifies_before(action, resource_spec) - run_context.notifies_before(Notification.new(resource_spec, action, self)) - end - - # Helper for #notifies - def notifies_immediately(action, resource_spec) - run_context.notifies_immediately(Notification.new(resource_spec, action, self)) - end - - # Helper for #notifies - def notifies_delayed(action, resource_spec) - run_context.notifies_delayed(Notification.new(resource_spec, action, self)) - end - - # - # Get the current actual value of this resource. - # - # This does not cache--a new value will be returned each time. - # - # @return A new copy of the resource, with values filled in from the actual - # current value. - # - def current_value - provider = provider_for_action(Array(action).first) - if provider.whyrun_mode? && !provider.whyrun_supported? - raise "Cannot retrieve #{self.class.current_resource} in why-run mode: #{provider} does not support why-run" - end - provider.load_current_resource - provider.current_resource - end - - # These methods are necessary for new resources to initialize old ones properly - attr_reader :resource_initializing - def resource_initializing=(value) - if value - @resource_initializing = value - else - remove_instance_variable(:@resource_initializing) - end - end - - if !respond_to?(:resource_name) - def self.resource_name(name=Chef::NOT_PASSED) - # Setter - if name != Chef::NOT_PASSED - # remove_canonical_dsl - - # Set the resource_name and call provides - if name - name = name.to_sym - # If our class is not already providing this name, provide it. - # Commented out: use of resource_name and provides will need to be - # mutually exclusive in this world, generally. - # if !Chef::ResourceResolver.includes_handler?(name, self) - provides name#, canonical: true - # end - @resource_name = name - else - @resource_name = nil - end - end - @resource_name - end - def self.resource_name=(name) - resource_name(name) - end - end - end -end diff --git a/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/resource/lwrp_base.rb b/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/resource/lwrp_base.rb deleted file mode 100644 index 5f098fd..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/resource/lwrp_base.rb +++ /dev/null @@ -1,60 +0,0 @@ -require 'chef_compat/resource/lwrp_base' -require 'chef/resource/lwrp_base' - -module ChefCompat - module Monkeypatches - # - # NOTE: LOTS OF METAPROGRAMMING HERE. NOT FOR FAINT OF HEART. - # - - # Add an empty module to Class so we can temporarily override it in build_from_file - module Class - end - class<<::Class - prepend(ChefCompat::Monkeypatches::Class) - end - - module Chef - module Resource - module LWRPBase - def build_from_file(cookbook_name, filename, run_context) - # If the cookbook this LWRP is from depends on compat_resource, fix its LWRPs up real good - if run_context.cookbook_collection[cookbook_name].metadata.dependencies.has_key?('compat_resource') - # All cookbooks do Class.new(Chef::Resource::LWRPBase). Change Class.new - # temporarily to translate Chef::Resource::LWRPBase to ChefCompat::Resource - ChefCompat::Monkeypatches::Class.module_eval do - def new(*args, &block) - # Trick it! Use ChefCompat::Resource instead of Chef::Resource::LWRPBase - if args == [ ::Chef::Resource::LWRPBase ] - ChefCompat::Monkeypatches::Class.module_eval do - remove_method(:new) if method_defined?(:new) - end - args = [ ChefCompat::Resource::LWRPBase ] - end - super(*args, &block) - end - end - - begin - - # Call the actual build_from_file - super - - ensure - class<) -# Copyright:: Copyright 2015-2016, Chef Software, Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -# XXX: we now have two copies of this file in the compat_resource cookbook. I'm uncertain if this is a -# bug or a feature, and I suspect it is actually a feature. The point of this file is that for all -# resources and cookbooks the global Chef::ResourceBuilder class must be upgraded to at least the -# 12.10.24 version. The point of the other copy is that for compat_resource cookbooks all their -# resources should be using the lastest version that has been sync'd. So these two files should -# diverge as times goes on. I believe that is the correct behavior and that we want to have both -# files in this cookbook. - -# NOTE: this was extracted from the Recipe DSL mixin, relevant specs are in spec/unit/recipe_spec.rb - -if Gem::Requirement.new("< 12.10.24").satisfied_by?(Gem::Version.new(Chef::VERSION)) - begin - require 'chef/resource_builder' - # we use the LoadError this creates on early 12.x to not monkeypatch chef client versions that don't have Chef::ResourceBuilder - # (it is lazily included and doesn't appear until compile time so we can't resolve the symbol during library loading) - - class Chef - class ResourceBuilder - attr_reader :type - attr_reader :name - attr_reader :created_at - attr_reader :params - attr_reader :run_context - attr_reader :cookbook_name - attr_reader :recipe_name - attr_reader :enclosing_provider - attr_reader :resource - - # FIXME (ruby-2.1 syntax): most of these are mandatory - def initialize(type:nil, name:nil, created_at: nil, params: nil, run_context: nil, cookbook_name: nil, recipe_name: nil, enclosing_provider: nil) - @type = type - @name = name - @created_at = created_at - @params = params - @run_context = run_context - @cookbook_name = cookbook_name - @recipe_name = recipe_name - @enclosing_provider = enclosing_provider - end - - def build(&block) - raise ArgumentError, "You must supply a name when declaring a #{type} resource" if name.nil? - - @resource = resource_class.new(name, run_context) - if resource.resource_name.nil? - raise Chef::Exceptions::InvalidResourceSpecification, "#{resource}.resource_name is `nil`! Did you forget to put `provides :blah` or `resource_name :blah` in your resource class?" - end - resource.source_line = created_at - resource.declared_type = type - - # If we have a resource like this one, we want to steal its state - # This behavior is very counter-intuitive and should be removed. - # See CHEF-3694, https://tickets.opscode.com/browse/CHEF-3694 - # Moved to this location to resolve CHEF-5052, https://tickets.opscode.com/browse/CHEF-5052 - if prior_resource - resource.load_from(prior_resource) - end - - resource.cookbook_name = cookbook_name - resource.recipe_name = recipe_name - # Determine whether this resource is being created in the context of an enclosing Provider - resource.enclosing_provider = enclosing_provider - - # XXX: this is required for definition params inside of the scope of a - # subresource to work correctly. - resource.params = params - - # Evaluate resource attribute DSL - if block_given? - resource.resource_initializing = true - begin - resource.instance_eval(&block) - ensure - resource.resource_initializing = false - end - end - - # emit a cloned resource warning if it is warranted - if prior_resource - if is_trivial_resource?(prior_resource) && identicalish_resources?(prior_resource, resource) - emit_harmless_cloning_debug - else - emit_cloned_resource_warning - end - end - - # Run optional resource hook - resource.after_created - - resource - end - - private - - def resource_class - # Checks the new platform => short_name => resource mapping initially - # then fall back to the older approach (Chef::Resource.const_get) for - # backward compatibility - @resource_class ||= Chef::Resource.resource_for_node(type, run_context.node) - end - - def is_trivial_resource?(resource) - identicalish_resources?(resource_class.new(name, run_context), resource) - end - - # this is an equality test specific to checking for 3694 cloning warnings - def identicalish_resources?(first, second) - skipped_ivars = [ :@source_line, :@cookbook_name, :@recipe_name, :@params, :@elapsed_time, :@declared_type ] - checked_ivars = ( first.instance_variables | second.instance_variables ) - skipped_ivars - non_matching_ivars = checked_ivars.reject do |iv| - if iv == :@action && ( [first.instance_variable_get(iv)].flatten == [:nothing] || [second.instance_variable_get(iv)].flatten == [:nothing] ) - # :nothing action on either side of the comparison always matches - true - else - first.instance_variable_get(iv) == second.instance_variable_get(iv) - end - end - Chef::Log.debug("ivars which did not match with the prior resource: #{non_matching_ivars}") - non_matching_ivars.empty? - end - - def emit_cloned_resource_warning - Chef::Log.warn("Cloning resource attributes for #{resource} from prior resource (CHEF-3694)") - Chef::Log.warn("Previous #{prior_resource}: #{prior_resource.source_line}") if prior_resource.source_line - Chef::Log.warn("Current #{resource}: #{resource.source_line}") if resource.source_line - end - - def emit_harmless_cloning_debug - Chef::Log.debug("Harmless resource cloning from #{prior_resource}:#{prior_resource.source_line} to #{resource}:#{resource.source_line}") - end - - def prior_resource - @prior_resource ||= - begin - key = "#{type}[#{name}]" - run_context.resource_collection.lookup_local(key) - rescue Chef::Exceptions::ResourceNotFound - nil - end - end - - end - end - rescue LoadError - # cool we're just on early chef 12.x, nothing to do -- we don't have to worry because there's also not parent_run_context pointer, so we don't have to - # use lookup_local to avoid resource cloning shit out of the parent run_context. the resource collection's lookup() method will always use lookup_local - # over lookup_recursive. - end -end diff --git a/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/resource_collection.rb b/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/resource_collection.rb deleted file mode 100644 index 4f07489..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/resource_collection.rb +++ /dev/null @@ -1,103 +0,0 @@ -# -# Author:: Adam Jacob () -# Author:: Christopher Walters () -# Copyright:: Copyright 2008-2016, Chef Software Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -require "chef/resource_collection/resource_set" -require "chef/resource_collection/resource_list" -require "chef/resource_collection" -require "chef/exceptions" - -module ChefCompat - module Monkeypatches - module Chef - module ResourceCollection - module RecursiveNotificationLookup - # - # Copied verbatim from Chef 12.10.24 - # - attr_accessor :run_context - - def initialize(run_context = nil) - super() - @run_context = run_context - end - - def lookup_local(key) - resource_set.lookup(key) - end - - def find_local(*args) - resource_set.find(*args) - end - - def lookup(key) - if run_context.nil? - lookup_local(key) - else - lookup_recursive(run_context, key) - end - end - - def find(*args) - if run_context.nil? - find_local(*args) - else - find_recursive(run_context, *args) - end - end - - private - - def lookup_recursive(rc, key) - rc.resource_collection.send(:resource_set).lookup(key) - rescue ::Chef::Exceptions::ResourceNotFound - raise if !rc.respond_to?(:parent_run_context) || rc.parent_run_context.nil? - lookup_recursive(rc.parent_run_context, key) - end - - def find_recursive(rc, *args) - rc.resource_collection.send(:resource_set).find(*args) - rescue ::Chef::Exceptions::ResourceNotFound - raise if !rc.respond_to?(:parent_run_context) || rc.parent_run_context.nil? - find_recursive(rc.parent_run_context, *args) - end - end - - module DeleteResources - # - # Copied verbatim from Chef 12.10.24 - # - def delete(key) - resource_list.delete(key) - resource_set.delete(key) - end - end - end - end - end -end - - -class Chef::ResourceCollection - unless method_defined?(:lookup_local) - prepend ChefCompat::Monkeypatches::Chef::ResourceCollection::RecursiveNotificationLookup - end - unless method_defined?(:delete) - prepend ChefCompat::Monkeypatches::Chef::ResourceCollection::DeleteResources - end -end diff --git a/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/resource_collection/resource_list.rb b/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/resource_collection/resource_list.rb deleted file mode 100644 index dfbd442..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/resource_collection/resource_list.rb +++ /dev/null @@ -1,49 +0,0 @@ -# -# Author:: Tyler Ball () -# Copyright:: Copyright 2014-2016, Chef Software, Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -require "chef/resource_collection/resource_list" -require "chef/exceptions" - -module ChefCompat - module Monkeypatches - module Chef - module ResourceCollection - module ResourceList - module DeleteResource - # Copied verbatim from Chef 12.10.4 - def delete(key) - raise ArgumentError, "Must pass a Chef::Resource or String to delete" unless key.is_a?(String) || key.is_a?(Chef::Resource) - key = key.to_s - ret = @resources.reject! { |r| r.to_s == key } - if ret.nil? - raise ::Chef::Exceptions::ResourceNotFound, "Cannot find a resource matching #{key} (did you define it first?)" - end - ret - end - end - end - end - end - end -end - -class Chef::ResourceCollection::ResourceList - unless method_defined?(:delete) - prepend ChefCompat::Monkeypatches::Chef::ResourceCollection::ResourceList::DeleteResource - end -end diff --git a/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/resource_collection/resource_set.rb b/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/resource_collection/resource_set.rb deleted file mode 100644 index bcead10..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/resource_collection/resource_set.rb +++ /dev/null @@ -1,49 +0,0 @@ -# -# Author:: Tyler Ball () -# Copyright:: Copyright 2014-2016, Chef Software, Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -require "chef/resource_collection/resource_list" -require "chef/exceptions" - -module ChefCompat - module Monkeypatches - module Chef - module ResourceCollection - module ResourceSet - module DeleteResource - def delete(key) - raise ArgumentError, "Must pass a Chef::Resource or String to delete" unless key.is_a?(String) || key.is_a?(Chef::Resource) - key = key.to_s - res = @resources_by_key.delete(key) - - if res == @resources_by_key.default - raise Chef::Exceptions::ResourceNotFound, "Cannot find a resource matching #{key} (did you define it first?)" - end - res - end - end - end - end - end - end -end - -class Chef::ResourceCollection::ResourceSet - unless method_defined?(:delete) - prepend ChefCompat::Monkeypatches::Chef::ResourceCollection::ResourceSet::DeleteResource - end -end diff --git a/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/run_context.rb b/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/run_context.rb deleted file mode 100644 index 03c9d60..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/run_context.rb +++ /dev/null @@ -1,691 +0,0 @@ -# -# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE -# -# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!! -# -# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE -# - -if Gem::Requirement.new('< 12.16.42').satisfied_by?(Gem::Version.new(Chef::VERSION)) -# -# Author:: Adam Jacob () -# Author:: Christopher Walters () -# Author:: Tim Hinderliter () -# Copyright:: Copyright 2008-2016, Chef Software Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -require "chef/resource_collection" -require "chef/cookbook_version" -require "chef/node" -require "chef/role" -require "chef/log" -require "chef/recipe" -require "chef/run_context/cookbook_compiler" -require "chef/event_dispatch/events_output_stream" -require "forwardable" - -class Chef - - # == Chef::RunContext - # Value object that loads and tracks the context of a Chef run - class RunContext - # - # Global state - # - - # - # The node for this run - # - # @return [Chef::Node] - # - attr_reader :node - - # - # The set of cookbooks involved in this run - # - # @return [Chef::CookbookCollection] - # - attr_reader :cookbook_collection - - # - # Resource Definitions for this run. Populated when the files in - # +definitions/+ are evaluated (this is triggered by #load). - # - # @return [Array[Chef::ResourceDefinition]] - # - attr_reader :definitions - - # - # Event dispatcher for this run. - # - # @return [Chef::EventDispatch::Dispatcher] - # - attr_reader :events - - # - # Hash of factoids for a reboot request. - # - # @return [Hash] - # - attr_accessor :reboot_info - - # - # Scoped state - # - - # - # The parent run context. - # - # @return [Chef::RunContext] The parent run context, or `nil` if this is the - # root context. - # - attr_reader :parent_run_context - - # - # The root run context. - # - # @return [Chef::RunContext] The root run context. - # - def root_run_context - rc = self - rc = rc.parent_run_context until rc.parent_run_context.nil? - rc - end - - # - # The collection of resources intended to be converged (and able to be - # notified). - # - # @return [Chef::ResourceCollection] - # - # @see CookbookCompiler - # - attr_reader :resource_collection - - # - # The list of control groups to execute during the audit phase - # - attr_reader :audits - - # - # Notification handling - # - - # - # A Hash containing the before notifications triggered by resources - # during the converge phase of the chef run. - # - # @return [Hash[String, Array[Chef::Resource::Notification]]] A hash from - # => - # - attr_reader :before_notification_collection - - # - # A Hash containing the immediate notifications triggered by resources - # during the converge phase of the chef run. - # - # @return [Hash[String, Array[Chef::Resource::Notification]]] A hash from - # => - # - attr_reader :immediate_notification_collection - - # - # A Hash containing the delayed (end of run) notifications triggered by - # resources during the converge phase of the chef run. - # - # @return [Hash[String, Array[Chef::Resource::Notification]]] A hash from - # => - # - attr_reader :delayed_notification_collection - - # - # An Array containing the delayed (end of run) notifications triggered by - # resources during the converge phase of the chef run. - # - # @return [Array[Chef::Resource::Notification]] An array of notification objects - # - attr_reader :delayed_actions - - # Creates a new Chef::RunContext object and populates its fields. This object gets - # used by the Chef Server to generate a fully compiled recipe list for a node. - # - # @param node [Chef::Node] The node to run against. - # @param cookbook_collection [Chef::CookbookCollection] The cookbooks - # involved in this run. - # @param events [EventDispatch::Dispatcher] The event dispatcher for this - # run. - # - def initialize(node, cookbook_collection, events) - @node = node - @cookbook_collection = cookbook_collection - @events = events - - node.run_context = self - node.set_cookbook_attribute - - @definitions = Hash.new - @loaded_recipes_hash = {} - @loaded_attributes_hash = {} - @reboot_info = {} - @cookbook_compiler = nil - @delayed_actions = [] - - initialize_child_state - end - - # - # Triggers the compile phase of the chef run. - # - # @param run_list_expansion [Chef::RunList::RunListExpansion] The run list. - # @see Chef::RunContext::CookbookCompiler - # - def load(run_list_expansion) - @cookbook_compiler = CookbookCompiler.new(self, run_list_expansion, events) - cookbook_compiler.compile - end - - # - # Initialize state that applies to both Chef::RunContext and Chef::ChildRunContext - # - def initialize_child_state - @audits = {} - @resource_collection = Chef::ResourceCollection.new(self) - @before_notification_collection = Hash.new { |h, k| h[k] = [] } - @immediate_notification_collection = Hash.new { |h, k| h[k] = [] } - @delayed_notification_collection = Hash.new { |h, k| h[k] = [] } - @delayed_actions = [] - end - - # - # Adds an before notification to the +before_notification_collection+. - # - # @param [Chef::Resource::Notification] The notification to add. - # - def notifies_before(notification) - # Note for the future, notification.notifying_resource may be an instance - # of Chef::Resource::UnresolvedSubscribes when calling {Resource#subscribes} - # with a string value. - before_notification_collection[notification.notifying_resource.declared_key] << notification - end - - # - # Adds an immediate notification to the +immediate_notification_collection+. - # - # @param [Chef::Resource::Notification] The notification to add. - # - def notifies_immediately(notification) - # Note for the future, notification.notifying_resource may be an instance - # of Chef::Resource::UnresolvedSubscribes when calling {Resource#subscribes} - # with a string value. - immediate_notification_collection[notification.notifying_resource.declared_key] << notification - end - - # - # Adds a delayed notification to the +delayed_notification_collection+. - # - # @param [Chef::Resource::Notification] The notification to add. - # - def notifies_delayed(notification) - # Note for the future, notification.notifying_resource may be an instance - # of Chef::Resource::UnresolvedSubscribes when calling {Resource#subscribes} - # with a string value. - delayed_notification_collection[notification.notifying_resource.declared_key] << notification - end - - # - # Adds a delayed action to the +delayed_actions+. - # - def add_delayed_action(notification) - if delayed_actions.any? { |existing_notification| existing_notification.duplicates?(notification) } - Chef::Log.info( "#{notification.notifying_resource} not queuing delayed action #{notification.action} on #{notification.resource}"\ - " (delayed), as it's already been queued") - else - delayed_actions << notification - end - end - - # - # Get the list of before notifications sent by the given resource. - # - # @return [Array[Notification]] - # - def before_notifications(resource) - return before_notification_collection[resource.declared_key] - end - - # - # Get the list of immediate notifications sent by the given resource. - # - # @return [Array[Notification]] - # - def immediate_notifications(resource) - return immediate_notification_collection[resource.declared_key] - end - - # - # Get the list of delayed (end of run) notifications sent by the given - # resource. - # - # @return [Array[Notification]] - # - def delayed_notifications(resource) - return delayed_notification_collection[resource.declared_key] - end - - # - # Cookbook and recipe loading - # - - # - # Evaluates the recipes +recipe_names+. Used by DSL::IncludeRecipe - # - # @param recipe_names [Array[String]] The list of recipe names (e.g. - # 'my_cookbook' or 'my_cookbook::my_resource'). - # @param current_cookbook The cookbook we are currently running in. - # - # @see DSL::IncludeRecipe#include_recipe - # - def include_recipe(*recipe_names, current_cookbook: nil) - result_recipes = Array.new - recipe_names.flatten.each do |recipe_name| - if result = load_recipe(recipe_name, current_cookbook: current_cookbook) - result_recipes << result - end - end - result_recipes - end - - # - # Evaluates the recipe +recipe_name+. Used by DSL::IncludeRecipe - # - # TODO I am sort of confused why we have both this and include_recipe ... - # I don't see anything different beyond accepting and returning an - # array of recipes. - # - # @param recipe_names [Array[String]] The recipe name (e.g 'my_cookbook' or - # 'my_cookbook::my_resource'). - # @param current_cookbook The cookbook we are currently running in. - # - # @return A truthy value if the load occurred; `false` if already loaded. - # - # @see DSL::IncludeRecipe#load_recipe - # - def load_recipe(recipe_name, current_cookbook: nil) - Chef::Log.debug("Loading recipe #{recipe_name} via include_recipe") - - cookbook_name, recipe_short_name = Chef::Recipe.parse_recipe_name(recipe_name, current_cookbook: current_cookbook) - - if unreachable_cookbook?(cookbook_name) # CHEF-4367 - Chef::Log.warn(<<-ERROR_MESSAGE) -MissingCookbookDependency: -Recipe `#{recipe_name}` is not in the run_list, and cookbook '#{cookbook_name}' -is not a dependency of any cookbook in the run_list. To load this recipe, -first add a dependency on cookbook '#{cookbook_name}' in the cookbook you're -including it from in that cookbook's metadata. -ERROR_MESSAGE - end - - if loaded_fully_qualified_recipe?(cookbook_name, recipe_short_name) - Chef::Log.debug("I am not loading #{recipe_name}, because I have already seen it.") - false - else - loaded_recipe(cookbook_name, recipe_short_name) - node.loaded_recipe(cookbook_name, recipe_short_name) - cookbook = cookbook_collection[cookbook_name] - cookbook.load_recipe(recipe_short_name, self) - end - end - - # - # Load the given recipe from a filename. - # - # @param recipe_file [String] The recipe filename. - # - # @return [Chef::Recipe] The loaded recipe. - # - # @raise [Chef::Exceptions::RecipeNotFound] If the file does not exist. - # - def load_recipe_file(recipe_file) - if !File.exist?(recipe_file) - raise Chef::Exceptions::RecipeNotFound, "could not find recipe file #{recipe_file}" - end - - Chef::Log.debug("Loading recipe file #{recipe_file}") - recipe = Chef::Recipe.new("@recipe_files", recipe_file, self) - recipe.from_file(recipe_file) - recipe - end - - # - # Look up an attribute filename. - # - # @param cookbook_name [String] The cookbook name of the attribute file. - # @param attr_file_name [String] The attribute file's name (not path). - # - # @return [String] The filename. - # - # @see DSL::IncludeAttribute#include_attribute - # - # @raise [Chef::Exceptions::CookbookNotFound] If the cookbook could not be found. - # @raise [Chef::Exceptions::AttributeNotFound] If the attribute file could not be found. - # - def resolve_attribute(cookbook_name, attr_file_name) - cookbook = cookbook_collection[cookbook_name] - raise Chef::Exceptions::CookbookNotFound, "could not find cookbook #{cookbook_name} while loading attribute #{name}" unless cookbook - - attribute_filename = cookbook.attribute_filenames_by_short_filename[attr_file_name] - raise Chef::Exceptions::AttributeNotFound, "could not find filename for attribute #{attr_file_name} in cookbook #{cookbook_name}" unless attribute_filename - - attribute_filename - end - - # - # A list of all recipes that have been loaded. - # - # This is stored internally as a Hash, so ordering is predictable. - # - # TODO is the above statement true in a 1.9+ ruby world? Is it relevant? - # - # @return [Array[String]] A list of recipes in fully qualified form, e.g. - # the recipe "nginx" will be given as "nginx::default". - # - # @see #loaded_recipe? To determine if a particular recipe has been loaded. - # - def loaded_recipes - loaded_recipes_hash.keys - end - - # - # A list of all attributes files that have been loaded. - # - # Stored internally using a Hash, so order is predictable. - # - # TODO is the above statement true in a 1.9+ ruby world? Is it relevant? - # - # @return [Array[String]] A list of attribute file names in fully qualified - # form, e.g. the "nginx" will be given as "nginx::default". - # - def loaded_attributes - loaded_attributes_hash.keys - end - - # - # Find out if a given recipe has been loaded. - # - # @param cookbook [String] Cookbook name. - # @param recipe [String] Recipe name. - # - # @return [Boolean] `true` if the recipe has been loaded, `false` otherwise. - # - def loaded_fully_qualified_recipe?(cookbook, recipe) - loaded_recipes_hash.has_key?("#{cookbook}::#{recipe}") - end - - # - # Find out if a given recipe has been loaded. - # - # @param recipe [String] Recipe name. "nginx" and "nginx::default" yield - # the same results. - # - # @return [Boolean] `true` if the recipe has been loaded, `false` otherwise. - # - def loaded_recipe?(recipe) - cookbook, recipe_name = Chef::Recipe.parse_recipe_name(recipe) - loaded_fully_qualified_recipe?(cookbook, recipe_name) - end - - # - # Mark a given recipe as having been loaded. - # - # @param cookbook [String] Cookbook name. - # @param recipe [String] Recipe name. - # - def loaded_recipe(cookbook, recipe) - loaded_recipes_hash["#{cookbook}::#{recipe}"] = true - end - - # - # Find out if a given attribute file has been loaded. - # - # @param cookbook [String] Cookbook name. - # @param attribute_file [String] Attribute file name. - # - # @return [Boolean] `true` if the recipe has been loaded, `false` otherwise. - # - def loaded_fully_qualified_attribute?(cookbook, attribute_file) - loaded_attributes_hash.has_key?("#{cookbook}::#{attribute_file}") - end - - # - # Mark a given attribute file as having been loaded. - # - # @param cookbook [String] Cookbook name. - # @param attribute_file [String] Attribute file name. - # - def loaded_attribute(cookbook, attribute_file) - loaded_attributes_hash["#{cookbook}::#{attribute_file}"] = true - end - - ## - # Cookbook File Introspection - - # - # Find out if the cookbook has the given template. - # - # @param cookbook [String] Cookbook name. - # @param template_name [String] Template name. - # - # @return [Boolean] `true` if the template is in the cookbook, `false` - # otherwise. - # @see Chef::CookbookVersion#has_template_for_node? - # - def has_template_in_cookbook?(cookbook, template_name) - cookbook = cookbook_collection[cookbook] - cookbook.has_template_for_node?(node, template_name) - end - - # - # Find out if the cookbook has the given file. - # - # @param cookbook [String] Cookbook name. - # @param cb_file_name [String] File name. - # - # @return [Boolean] `true` if the file is in the cookbook, `false` - # otherwise. - # @see Chef::CookbookVersion#has_cookbook_file_for_node? - # - def has_cookbook_file_in_cookbook?(cookbook, cb_file_name) - cookbook = cookbook_collection[cookbook] - cookbook.has_cookbook_file_for_node?(node, cb_file_name) - end - - # - # Find out whether the given cookbook is in the cookbook dependency graph. - # - # @param cookbook_name [String] Cookbook name. - # - # @return [Boolean] `true` if the cookbook is reachable, `false` otherwise. - # - # @see Chef::CookbookCompiler#unreachable_cookbook? - def unreachable_cookbook?(cookbook_name) - cookbook_compiler.unreachable_cookbook?(cookbook_name) - end - - # - # Open a stream object that can be printed into and will dispatch to events - # - # @param name [String] The name of the stream. - # @param options [Hash] Other options for the stream. - # - # @return [EventDispatch::EventsOutputStream] The created stream. - # - # @yield If a block is passed, it will be run and the stream will be closed - # afterwards. - # @yieldparam stream [EventDispatch::EventsOutputStream] The created stream. - # - def open_stream(name: nil, **options) - stream = EventDispatch::EventsOutputStream.new(events, name: name, **options) - if block_given? - begin - yield stream - ensure - stream.close - end - else - stream - end - end - - # there are options for how to handle multiple calls to these functions: - # 1. first call always wins (never change reboot_info once set). - # 2. last call always wins (happily change reboot_info whenever). - # 3. raise an exception on the first conflict. - # 4. disable reboot after this run if anyone ever calls :cancel. - # 5. raise an exception on any second call. - # 6. ? - def request_reboot(reboot_info) - Chef::Log.info "Changing reboot status from #{self.reboot_info.inspect} to #{reboot_info.inspect}" - @reboot_info = reboot_info - end - - def cancel_reboot - Chef::Log.info "Changing reboot status from #{reboot_info.inspect} to {}" - @reboot_info = {} - end - - def reboot_requested? - reboot_info.size > 0 - end - - # - # Create a child RunContext. - # - def create_child - ChildRunContext.new(self) - end - - # @api private - attr_writer :resource_collection - - protected - - attr_reader :cookbook_compiler - attr_reader :loaded_attributes_hash - attr_reader :loaded_recipes_hash - - module Deprecated - ### - # These need to be settable so deploy can run a resource_collection - # independent of any cookbooks via +recipe_eval+ - def audits=(value) - Chef.log_deprecation("Setting run_context.audits will be removed in a future Chef. Use run_context.create_child to create a new RunContext instead.") - @audits = value - end - - def immediate_notification_collection=(value) - Chef.log_deprecation("Setting run_context.immediate_notification_collection will be removed in a future Chef. Use run_context.create_child to create a new RunContext instead.") - @immediate_notification_collection = value - end - - def delayed_notification_collection=(value) - Chef.log_deprecation("Setting run_context.delayed_notification_collection will be removed in a future Chef. Use run_context.create_child to create a new RunContext instead.") - @delayed_notification_collection = value - end - end - prepend Deprecated - - # - # A child run context. Delegates all root context calls to its parent. - # - # @api private - # - class ChildRunContext < RunContext - extend Forwardable - def_delegators :parent_run_context, *%w{ - cancel_reboot - config - cookbook_collection - cookbook_compiler - definitions - events - has_cookbook_file_in_cookbook? - has_template_in_cookbook? - load - loaded_attribute - loaded_attributes - loaded_attributes_hash - loaded_fully_qualified_attribute? - loaded_fully_qualified_recipe? - loaded_recipe - loaded_recipe? - loaded_recipes - loaded_recipes_hash - node - open_stream - reboot_info - reboot_info= - reboot_requested? - request_reboot - resolve_attribute - unreachable_cookbook? - } - - def initialize(parent_run_context) - @parent_run_context = parent_run_context - - # We don't call super, because we don't bother initializing stuff we're - # going to delegate to the parent anyway. Just initialize things that - # every instance needs. - initialize_child_state - end - - CHILD_STATE = %w{ - audits - audits= - create_child - add_delayed_action - delayed_actions - delayed_notification_collection - delayed_notification_collection= - delayed_notifications - immediate_notification_collection - immediate_notification_collection= - immediate_notifications - before_notification_collection - before_notifications - include_recipe - initialize_child_state - load_recipe - load_recipe_file - notifies_before - notifies_immediately - notifies_delayed - parent_run_context - root_run_context - resource_collection - resource_collection= - }.map { |x| x.to_sym } - - # Verify that we didn't miss any methods - unless @__skip_method_checking # hook specifically for compat_resource - missing_methods = superclass.instance_methods(false) - instance_methods(false) - CHILD_STATE - if !missing_methods.empty? - raise "ERROR: not all methods of RunContext accounted for in ChildRunContext! All methods must be marked as child methods with CHILD_STATE or delegated to the parent_run_context. Missing #{missing_methods.join(", ")}." - end - end - end - end -end -end diff --git a/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/runner.rb b/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/runner.rb deleted file mode 100644 index 9add7a8..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/runner.rb +++ /dev/null @@ -1,153 +0,0 @@ -# -# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE -# -# THIS IS A FILE AUTOGENERATED BY 'rake update' DO NOT EDIT!!!! -# -# NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE -# - -if Gem::Requirement.new('< 12.16.42').satisfied_by?(Gem::Version.new(Chef::VERSION)) -#-- -# Author:: Adam Jacob () -# Author:: Christopher Walters () -# Author:: Tim Hinderliter () -# Copyright:: Copyright 2008-2016, Chef Software Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -require "chef/exceptions" -require "chef/mixin/params_validate" -require "chef/node" -require "chef/resource_collection" - -class Chef - # == Chef::Runner - # This class is responsible for executing the steps in a Chef run. - class Runner - - attr_reader :run_context - - include Chef::Mixin::ParamsValidate - - def initialize(run_context) - @run_context = run_context - end - - def delayed_actions - @run_context.delayed_actions - end - - def events - @run_context.events - end - - # Determine the appropriate provider for the given resource, then - # execute it. - def run_action(resource, action, notification_type = nil, notifying_resource = nil) - # If there are any before notifications, why-run the resource - # and notify anyone who needs notifying - before_notifications = run_context.before_notifications(resource) || [] - unless before_notifications.empty? - forced_why_run do - Chef::Log.info("#{resource} running why-run #{action} action to support before action") - resource.run_action(action, notification_type, notifying_resource) - end - - if resource.updated_by_last_action? - before_notifications.each do |notification| - Chef::Log.info("#{resource} sending #{notification.action} action to #{notification.resource} (before)") - run_action(notification.resource, notification.action, :before, resource) - end - resource.updated_by_last_action(false) - end - end - - # Actually run the action for realsies - resource.run_action(action, notification_type, notifying_resource) - - # Execute any immediate and queue up any delayed notifications - # associated with the resource, but only if it was updated *this time* - # we ran an action on it. - if resource.updated_by_last_action? - run_context.immediate_notifications(resource).each do |notification| - Chef::Log.info("#{resource} sending #{notification.action} action to #{notification.resource} (immediate)") - run_action(notification.resource, notification.action, :immediate, resource) - end - - run_context.delayed_notifications(resource).each do |notification| - # send the notification to the run_context of the receiving resource - notification.resource.run_context.add_delayed_action(notification) - end - end - end - - # Iterates over the +resource_collection+ in the +run_context+ calling - # +run_action+ for each resource in turn. - def converge - # Resolve all lazy/forward references in notifications - run_context.resource_collection.each do |resource| - resource.resolve_notification_references - end - - # Execute each resource. - run_context.resource_collection.execute_each_resource do |resource| - Array(resource.action).each { |action| run_action(resource, action) } - end - - rescue Exception => e - Chef::Log.info "Running queued delayed notifications before re-raising exception" - run_delayed_notifications(e) - else - run_delayed_notifications(nil) - true - end - - private - - # Run all our :delayed actions - def run_delayed_notifications(error = nil) - collected_failures = Exceptions::MultipleFailures.new - collected_failures.client_run_failure(error) unless error.nil? - delayed_actions.each do |notification| - result = run_delayed_notification(notification) - if result.kind_of?(Exception) - collected_failures.notification_failure(result) - end - end - collected_failures.raise! - end - - def run_delayed_notification(notification) - Chef::Log.info( "#{notification.notifying_resource} sending #{notification.action}"\ - " action to #{notification.resource} (delayed)") - # Struct of resource/action to call - run_action(notification.resource, notification.action, :delayed) - true - rescue Exception => e - e - end - - # helper to run a block of code with why_run forced to true and then restore it correctly - def forced_why_run - saved = Chef::Config[:why_run] - Chef::Config[:why_run] = true - yield - ensure - Chef::Config[:why_run] = saved - end - - end -end -end diff --git a/cookbooks/compat_resource/files/lib/chef_compat/property.rb b/cookbooks/compat_resource/files/lib/chef_compat/property.rb deleted file mode 100644 index be21113..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/property.rb +++ /dev/null @@ -1,6 +0,0 @@ -require 'chef_compat/copied_from_chef/chef/property' - -module ChefCompat - class Property < ChefCompat::CopiedFromChef::Chef::Property - end -end diff --git a/cookbooks/compat_resource/files/lib/chef_compat/recipe.rb b/cookbooks/compat_resource/files/lib/chef_compat/recipe.rb deleted file mode 100644 index 86e39d9..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/recipe.rb +++ /dev/null @@ -1,8 +0,0 @@ -require 'chef/recipe' -require 'chef_compat/copied_from_chef/chef/dsl/recipe' - -module ChefCompat - class Recipe < Chef::Recipe - include ChefCompat::CopiedFromChef::Chef::DSL::Recipe::FullDSL - end -end diff --git a/cookbooks/compat_resource/files/lib/chef_compat/resource.rb b/cookbooks/compat_resource/files/lib/chef_compat/resource.rb deleted file mode 100644 index bcf0fdb..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/resource.rb +++ /dev/null @@ -1,56 +0,0 @@ -require 'chef_compat/monkeypatches' -require 'chef_compat/copied_from_chef/chef/resource' - -# We do NOT want action defined if chefspec is engaged -if Chef::Provider::InlineResources::ClassMethods.instance_method(:action).source_location[0] =~ /chefspec/ - ChefCompat::CopiedFromChef::Chef::Provider::InlineResources::ClassMethods.instance_eval do - remove_method(:action) - end -end - -module ChefCompat - class Resource < ChefCompat::CopiedFromChef::Chef::Resource - def initialize(*args, &block) - super - # @resource_name is used in earlier Chef versions - @resource_name = self.class.resource_name - end - # Things we'll need to define ourselves: - # 1. provider - # 2. resource_name - - def provider(*args, &block) - super || self.class.action_class - end - def provider=(arg) - provider(arg) - end - - if !respond_to?(:resource_name) - def self.resource_name(name=Chef::NOT_PASSED) - # Setter - if name != Chef::NOT_PASSED - # remove_canonical_dsl - - # Set the resource_name and call provides - if name - name = name.to_sym - # If our class is not already providing this name, provide it. - # Commented out: use of resource_name and provides will need to be - # mutually exclusive in this world, generally. - # if !Chef::ResourceResolver.includes_handler?(name, self) - provides name#, canonical: true - # end - @resource_name = name - else - @resource_name = nil - end - end - @resource_name - end - def self.resource_name=(name) - resource_name(name) - end - end - end -end diff --git a/cookbooks/compat_resource/files/lib/chef_compat/resource/lwrp_base.rb b/cookbooks/compat_resource/files/lib/chef_compat/resource/lwrp_base.rb deleted file mode 100644 index 2ebb98f..0000000 --- a/cookbooks/compat_resource/files/lib/chef_compat/resource/lwrp_base.rb +++ /dev/null @@ -1,44 +0,0 @@ -require 'chef_compat/resource' -require 'chef_compat/copied_from_chef/chef/resource' -require 'chef/mixin/convert_to_class_name' -require 'chef/mixin/from_file' - -module ChefCompat - class Resource < ChefCompat::CopiedFromChef::Chef::Resource - class LWRPBase < ChefCompat::Resource - class<= 12.0").satisfied_by?(Gem::Version.new(Chef::VERSION)) - - require 'chef_compat/resource' - require 'chef_compat/property' - require 'chef_compat/mixin/properties' - - resources_dir = File.expand_path("chef_compat/copied_from_chef/chef/resource", File.dirname(__FILE__)) - providers_dir = File.expand_path("chef_compat/copied_from_chef/chef/provider", File.dirname(__FILE__)) - Dir["#{resources_dir}/*.rb"].each {|file| require file } - Dir["#{providers_dir}/*.rb"].each {|file| require file } -else - - class Chef - class Resource - def self.property(args, &block) - raise_chef_11_error - end - - def self.resource_name(args, &block) - raise_chef_11_error - end - - def self.action(args, &block) - raise_chef_11_error - end - - def self.raise_chef_11_error - raise "This resource is written with Chef 12.5 custom resources, and requires at least Chef 12.0 used with the compat_resource cookbook, it will not work with Chef 11.x clients, and those users must pin their cookbooks to older versions or upgrade." - end - end - end - -end diff --git a/cookbooks/compat_resource/libraries/autoload.rb b/cookbooks/compat_resource/libraries/autoload.rb deleted file mode 100644 index db52cfc..0000000 --- a/cookbooks/compat_resource/libraries/autoload.rb +++ /dev/null @@ -1,31 +0,0 @@ -unless Gem::Requirement.new(">= 12.0").satisfied_by?(Gem::Version.new(Chef::VERSION)) - raise "This resource is written with Chef 12.5 custom resources, and requires at least Chef 12.0 used with the compat_resource cookbook, it will not work with Chef 11.x clients, and those users must pin their cookbooks to older versions or upgrade." -end - -# If users are on old verisons of ChefDK which activates an (old) gem via cheffish before this cookbook loads, then -# we just try to monkeypatch over the top of a monkeypatch. Its possible that we have checks in this cookbook which -# will defeat that purpose and fail to monkeypatch on top of monkeypatches -- in which case those checks should be -# removed -- this cookbook needs to win when it gets into a fight with the old gem versions. -if Gem.loaded_specs["compat_resource"] - Chef.log_deprecation "using compat_resource as a gem is deprecated; please update cheffish and chef-provisioning gems (or use the latest Chef/ChefDK packages) or else manually pin your compat_resource cookbook version to the same version as the gem you are using to remove this warning" -end - -# we want to not pollute the libpath with our files until after we've done the version check -require_relative '../files/lib/chef_upstream_version' - -# on any chef client later than the one we were based off of we just turn into a no-op -if Gem::Requirement.new("< #{ChefCompat::CHEF_UPSTREAM_VERSION}").satisfied_by?(Gem::Version.new(Chef::VERSION)) - Chef::Log.debug "loading compat_resource based on chef-version #{ChefCompat::CHEF_UPSTREAM_VERSION} over chef version #{Gem::Version.new(Chef::VERSION)}" - $LOAD_PATH.unshift(File.expand_path("../files/lib", File.dirname(__FILE__))) - require 'compat_resource' -else - Chef::Log.debug "NOT LOADING compat_resource based on chef-version #{ChefCompat::CHEF_UPSTREAM_VERSION} over chef version #{Gem::Version.new(Chef::VERSION)}" - unless defined?(ChefCompat::Resource) && defined?(ChefCompat::Mixin::Properties) - module ChefCompat - Resource = Chef::Resource - module Mixin - Properties = Chef::Mixin::Properties - end - end - end -end diff --git a/cookbooks/compat_resource/metadata.json b/cookbooks/compat_resource/metadata.json deleted file mode 100644 index af64b50..0000000 --- a/cookbooks/compat_resource/metadata.json +++ /dev/null @@ -1 +0,0 @@ -{"name":"compat_resource","version":"12.16.3","description":"Backports functionality introduced in the latest chef-client releases to any chef-client from 12.1 onwards","long_description":"# compat_resource cookbook\n\n[![Build Status](https://travis-ci.org/chef-cookbooks/compat_resource.svg?branch=master)](https://travis-ci.org/chef-cookbooks/compat_resource) [![Cookbook Version](https://img.shields.io/cookbook/v/compat_resource.svg)](https://supermarket.chef.io/cookbooks/compat_resource)\n\nThis cookbook backports functionality introduced in the latest chef-client releases to any chef-client from 12.1 onwards. This includes [Custom Resource](https://docs.chef.io/custom_resources.html) functionality, notification improvements, as well as new resources added to core chef. It allows for the usage of these new resources in cookbooks without requiring the very latest Chef client release.\n\n## Backported functionality\n\n- [Custom Resources](https://docs.chef.io/custom_resources.html)\n- [apt_repository](https://docs.chef.io/resource_apt_repository.html)\n- [apt_update](https://docs.chef.io/resource_apt_update.html)\n- [systemd_unit](https://docs.chef.io/resource_systemd_unit.html)\n- [yum_repository](https://docs.chef.io/resource_yum_repository.html)\n- [:before notifications](https://docs.chef.io/resources.html#timers)\n\n## Requirements\n\n### Platforms\n\n- All platforms supported by Chef\n\n### Chef\n\n- Chef 12.1+\n\n### Cookbooks\n\n- none\n\n## Usage\n\nTo use this cookbook, put `depends 'compat_resource'` in the metadata.rb of your cookbook. Once this is done, you can use all the new custom resource features to define resources. It Just Works.\n\n## Custom Resources?\n\nCurious about how to use custom resources?\n\n- Docs: \n- Slides: \n\n## License & Authors\n\n- Author:: Lamont Granquist ([lamont@chef.io](mailto:lamont@chef.io))\n- Author:: John Keiser ([jkeiser@chef.io](mailto:jkeiser@chef.io))\n\n```text\nCopyright:: 2015-2016 Chef Software, Inc.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n```\n","maintainer":"Lamont Granquist","maintainer_email":"lamont@chef.io","license":"Apache 2.0","platforms":{},"dependencies":{},"recommendations":{},"suggestions":{},"conflicting":{},"providing":{},"replacing":{},"attributes":{},"groupings":{},"recipes":{},"source_url":"https://github.com/chef-cookbooks/compat_resource","issues_url":"https://github.com/chef-cookbooks/compat_resource/issues","chef_version":">= 12.1","ohai_version":{}} \ No newline at end of file diff --git a/cookbooks/mediawiki/recipes/database.rb b/cookbooks/mediawiki/recipes/database.rb index df4a145..382d65c 100644 --- a/cookbooks/mediawiki/recipes/database.rb +++ b/cookbooks/mediawiki/recipes/database.rb @@ -22,6 +22,11 @@ end socket = "/var/run/mysql-#{db['instance_name']}/mysqld.sock" if node['platform_family'] == 'debian' + directory "/var/run/mysqld" do + action :create + owner "mysql" + group "mysql" + end link '/var/run/mysqld/mysqld.sock' do to socket not_if 'test -f /var/run/mysqld/mysqld.sock' diff --git a/cookbooks/mediawiki/recipes/default.rb b/cookbooks/mediawiki/recipes/default.rb index 17e55d4..34e251c 100644 --- a/cookbooks/mediawiki/recipes/default.rb +++ b/cookbooks/mediawiki/recipes/default.rb @@ -10,7 +10,15 @@ include_recipe "apt" include_recipe "php::default" -include_recipe "php::module_apc" + +if node['platform'] == 'ubuntu' and node['platform_version'] >= '16.04' + # APC is now apcu in PHP 7 + include_recipe "php::module_apcu" + # Dependency + package "php7.0-mbstring" +else + include_recipe "php::module_apc" +end include_recipe "php::module_mysql" include_recipe "mediawiki::database" @@ -38,8 +46,11 @@ when "debian" package "libicu-dev" end -php_pear "intl" do - action :install +if platform?('ubuntu') && node[:platform_version].to_f < 16.04 + # bundled with PHP since version 5.3 + php_pear "intl" do + action :install + end end # Configure mediawiki database diff --git a/cookbooks/mediawiki/recipes/nginx.rb b/cookbooks/mediawiki/recipes/nginx.rb index 79561cb..22ff455 100644 --- a/cookbooks/mediawiki/recipes/nginx.rb +++ b/cookbooks/mediawiki/recipes/nginx.rb @@ -7,32 +7,7 @@ node.set_unless['php-fpm']['pools'] = [] include_recipe "php-fpm" include_recipe 'php-fpm::repository' unless node['php-fpm']['skip_repository_install'] - -if node['php-fpm']['package_name'].nil? - if platform_family?("rhel") - php_fpm_package_name = "php-fpm" - else - php_fpm_package_name = "php5-fpm" - end -else - php_fpm_package_name = node['php-fpm']['package_name'] -end - -package php_fpm_package_name do - action :install -end - -if node['php-fpm']['service_name'].nil? - php_fpm_service_name = php_fpm_package_name -else - php_fpm_service_name = node['php-fpm']['service_name'] -end - -service "php-fpm" do - service_name php_fpm_service_name - supports :start => true, :stop => true, :restart => true, :reload => true - action [ :enable, :start ] -end +include_recipe "php-fpm::install" php_fpm_pool "www" do enable false diff --git a/cookbooks/mysql/CHANGELOG.md b/cookbooks/mysql/CHANGELOG.md index 8fd0aa8..aed2f49 100644 --- a/cookbooks/mysql/CHANGELOG.md +++ b/cookbooks/mysql/CHANGELOG.md @@ -2,6 +2,80 @@ This file is used to list changes made in each version of the mysql cookbook. +## 8.3.0 (2017-03-20) +- Refactor mysql_service_manager_upstart.rb to eliminate use of cloned resource + +## 8.2.0 (2016-12-03) + +- Include client development packages on RHEL/SUSE platforms + +## 8.1.1 (2016-10-31) +- Fixing CVE-2016-6662 - Reverting execure bit on mysql config + +## 8.1.0 (2016-10-29) + +- Drop hardcoded, specific package version logic that broke many users + +## 8.0.4 (2016-09-26) +- Bump debian version +- Updated packages for 12.04 and 14.04 too +- Add chef_version metadata +- Update platforms in the kitchen file +- Add selinux to the Berksfile for testing +- Make sure yum repos are setup in local Test Kitchen + +## 8.0.3 (2016-09-14) +- [GH-390] Fix #390 incorrect escaping of initial_root_password +- Updated package versions for Ubuntu 16.04 +- Testing updates + +# v8.0.2 (2016-08-25) +- Various bug fixed and updates to package version strings + +# v8.0.1 (2016-07-20) +- Fixed a regression in the mysql_client resource where the action was changed from create to install in the 8.0 release +- Added oracle, opensuse, and opensuseleap as supported platforms in the metadata + +# v8.0.0 (2016-07-11) + +- Converting from LWRP to custom resources +- Removing yum-mysql and other dependencies. +- ^ BREAKING CHANGE: RHELish users are now responsible + for including a recipe from the "yum-mysql" or equivalent + cookbook before utilizing the mysql_* resources. +- More thoughtful ChefSpec +- Renaming "replication" test suite to "smoke" +- Moving to Inspec + +## v7.2.0 (2016-06-30) + +- Support openeSUSE leap +- Support Fedora 24 + +## v7.1.2 (2016-06-30) + +- Avoid deprecation warnings on the upcoming Chef 12.12 release + +## v7.1.1 (2016-06-03) + +- Fix apparmor blocking writes to non-default tmp_dirs +- Updated apparmor config to allow read & write to sock.lock file +- Use cookstyle instead of Rubocop directly + +## v7.1.0 (2016-05-11) + +- Added support for Ubuntu 16.04 + +## v7.0.0 (2016-04-19) + +- Removed support for legacy distros: Ubuntu 10.04/13.04/14.10/15.04, Fedora 20/21, OmniOS r151006, opensuse 11.3/12.0 +- Added support for Fedora 23, suse 13.X, and Ubuntu 16.04 +- Updated the systemd support to create unit files in /etc/systemd and not /usr/lib/systemd +- Adding umask to bash resource that sets root password PR #386 @gziskind +- Cleaned up the Test Kitchen config to test the right platform version + mysql pairings +- Added Travis CI Test Kitchen testing on Fedora 22/23 and removed Fedora 21 +- Updated the platforms used in the specs + ## v6.1.3 (2016-03-14) - Added support for Ubuntu 15.10 @@ -65,7 +139,7 @@ This file is used to list changes made in each version of the mysql cookbook. ## v6.0.21 (2015-04-08) -- Fix to Upstart prestart script when using custom socket +- Fix to Upstart prestart script when using custom socket - Adding --explicit_defaults_for_timestamp mysql_install_db_cmd for - 5.6 and above @@ -186,7 +260,7 @@ This file is used to list changes made in each version of the mysql cookbook. ## v5.5.4 (2014-10-07) -- Adding sensitive flag to execute resources to protect passwords from logs +- Adding sensitive flag to execute resources to protect passwords from logs ## v5.5.3 (2014-09-24) diff --git a/cookbooks/mysql/MAINTAINERS.md b/cookbooks/mysql/MAINTAINERS.md index c6a51ae..b3548a4 100644 --- a/cookbooks/mysql/MAINTAINERS.md +++ b/cookbooks/mysql/MAINTAINERS.md @@ -1,13 +1,10 @@ # Maintainers -This file lists how this cookbook project is maintained. When making changes to the system, this -file tells you who needs to review your patch - you need a simple majority of maintainers -for the relevant subsystems to provide a :+1: on your pull request. Additionally, you need -to not receive a veto from a Lieutenant or the Project Lead. -Check out [How Cookbooks are Maintained](https://github.com/chef-cookbooks/community_cookbook_documentation/blob/master/CONTRIBUTING.MD) -for details on the process and how to become a maintainer or the project lead. +This file lists how this cookbook project is maintained. When making changes to the system, this file tells you who needs to review your patch - you need a review from an existing maintainer for the cookbook to provide a :+1: on your pull request. Additionally, you need to not receive a veto from a Lieutenant or the Project Lead. + +Check out [How Cookbooks are Maintained](https://github.com/chef-cookbooks/community_cookbook_documentation/blob/master/CONTRIBUTING.MD) for details on the process and how to become a maintainer or the project lead. # Project Maintainer * [Tim Smith](https://github.com/tas50) diff --git a/cookbooks/mysql/README.md b/cookbooks/mysql/README.md index 3baa1f6..3bb971a 100644 --- a/cookbooks/mysql/README.md +++ b/cookbooks/mysql/README.md @@ -2,16 +2,15 @@ [![Build Status](https://travis-ci.org/chef-cookbooks/mysql.svg?branch=master)](https://travis-ci.org/chef-cookbooks/mysql) [![Cookbook Version](https://img.shields.io/cookbook/v/mysql.svg)](https://supermarket.chef.io/cookbooks/mysql) -The Mysql Cookbook is a library cookbook that provides resource primitives (LWRPs) for use in recipes. It is designed to be a reference example for creating highly reusable cross-platform cookbooks. +The MySQL Cookbook is a library cookbook that provides resource primitives (LWRPs) for use in recipes. It is designed to be a reference example for creating highly reusable cross-platform cookbooks. ## Scope -This cookbook is concerned with the "MySQL Community Server", particularly those shipped with F/OSS Unix and Linux distributions. It does not address forks or value-added repackaged MySQL distributions like Drizzle, MariaDB, or Percona. +This cookbook is concerned with the "MySQL Community Server", particularly those shipped with F/OSS Unix and Linux distributions. It does not address forks or value-added repackaged MySQL distributions like MariaDB or Percona. ## Requirements -- Chef 11 or higher -- Ruby 1.9 or higher (preferably from the Chef full-stack installer) +- Chef 12.5 or higher - Network accessible package repositories - 'recipe[selinux::disabled]' on RHEL platforms @@ -20,42 +19,39 @@ This cookbook is concerned with the "MySQL Community Server", particularly those The following platforms have been tested with Test Kitchen: ``` -|----------------+-----+-----+-----+-----+-----| -| | 5.0 | 5.1 | 5.5 | 5.6 | 5.7 | -|----------------+-----+-----+-----+-----+-----| -| debian-7 | | | X | | | -|----------------+-----+-----+-----+-----+-----| -| ubuntu-12.04 | | | X | | | -|----------------+-----+-----+-----+-----+-----| -| ubuntu-14.04 | | | X | X | | -|----------------+-----+-----+-----+-----+-----| -| ubuntu-15.04 | | | | X | | -|----------------+-----+-----+-----+-----+-----| -| centos-5 | X | X | X | X | X | -|----------------+-----+-----+-----+-----+-----| -| centos-6 | | X | X | X | X | -|----------------+-----+-----+-----+-----+-----| -| centos-7 | | | X | X | X | -|----------------+-----+-----+-----+-----+-----| -| amazon | | | X | X | X | -|----------------+-----+-----+-----+-----+-----| -| fedora-22 | | | X | X | X | -|----------------+-----+-----+-----+-----+-----| -| fedora-23 | | | X | X | X | -|----------------+-----+-----+-----+-----+-----| +|----------------+-----+-----+-----+-----| +| | 5.1 | 5.5 | 5.6 | 5.7 | +|----------------+-----+-----+-----+-----| +| debian-7 | | X | | | +|----------------+-----+-----+-----+-----| +| debian-8 | | X | | | +|----------------+-----+-----+-----+-----| +| ubuntu-14.04 | | X | X | | +|----------------+-----+-----+-----+-----| +| ubuntu-16.04 | | | | X | +|----------------+-----+-----+-----+-----| +| centos-6 | X | X | X | X | +|----------------+-----+-----+-----+-----| +| centos-7 | | X | X | X | +|----------------+-----+-----+-----+-----| +| fedora | | | X | X | +|----------------+-----+-----+-----+-----| +| openSUSE 13.2 | | | X | | +|----------------+-----+-----+-----+-----| +| openSUSE Leap | | | X | | +|----------------+-----+-----+-----+-----| ``` ## Cookbook Dependencies -- yum-mysql-community -- smf +There are no hard coupled dependencies. However, there is a loose dependency on `yum-mysql-community` for RHEL/CentOS platforms. As of the 8.0 version of this cookbook, configuration of the package repos is now the responsibility of the user. ## Usage Place a dependency on the mysql cookbook in your cookbook's metadata.rb ```ruby -depends 'mysql', '~> 6.0' +depends 'mysql', '~> 8.0' ``` Then, in a recipe: @@ -180,7 +176,7 @@ Please note that when using `notifies` or `subscribes`, the resource to referenc - `:create` - Configures everything but the underlying operating system service. - `:delete` - Removes everything but the package and data_dir. - `:start` - Starts the underlying operating system service -- `:stop`- Stops the underlying operating system service +- `:stop`- Stops the underlying operating system service - `:restart` - Restarts the underlying operating system service - `:reload` - Reloads the underlying operating system service @@ -274,7 +270,7 @@ mysql_client 'default' do end ``` -#### Parameters +#### Properties - `package_name` - An array of packages to be installed. Defaults to a value looked up in an internal map. - `package_version` - Specific versions of the package to install, passed onto the underlying package manager. Defaults to `nil`. @@ -401,31 +397,16 @@ Or to connect over the network, use something like this: connect over the networ These network or socket ssettings can also be put in you $HOME/.my.cnf, if preferred. -### What about MariaDB, Percona, Drizzle, WebScaleSQL, etc. +### What about MariaDB, Percona, etc. MySQL forks are purposefully out of scope for this cookbook. This is mostly to reduce the testing matrix to a manageable size. Cookbooks for these technologies can easily be created by copying and adapting this cookbook. However, there will be differences. Package repository locations, package version names, software major version numbers, supported platform matrices, and the availability of software such as XtraDB and Galera are the main reasons that creating multiple cookbooks to make sense. -## Warnings - -## Hacking / Testing / TODO - -Please refer to the HACKING.md - -## License & Authors - -- Author:: Joshua Timberman ([joshua@chef.io](mailto:joshua@chef.io)) -- Author:: AJ Christensen ([aj@chef.io](mailto:aj@chef.io)) -- Author:: Seth Chisamore ([schisamo@chef.io](mailto:schisamo@chef.io)) -- Author:: Brian Bianco ([brian.bianco@gmail.com](mailto:brian.bianco@gmail.com)) -- Author:: Jesse Howarth ([him@jessehowarth.com](mailto:him@jessehowarth.com)) -- Author:: Andrew Crump ([andrew@kotirisoftware.com](mailto:andrew@kotirisoftware.com)) -- Author:: Christoph Hartmann ([chris@lollyrock.com](mailto:chris@lollyrock.com)) -- Author:: Sean OMeara ([sean@chef.io](mailto:sean@chef.io)) +## License ```text -Copyright:: 2009-2014 Chef Software, Inc +Copyright:: 2009-2017 Chef Software, Inc Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/cookbooks/mysql/libraries/helpers.rb b/cookbooks/mysql/libraries/helpers.rb index 8b47559..6f33996 100644 --- a/cookbooks/mysql/libraries/helpers.rb +++ b/cookbooks/mysql/libraries/helpers.rb @@ -1,67 +1,120 @@ -require 'shellwords' - module MysqlCookbook - module Helpers - include Chef::DSL::IncludeRecipe + module HelpersBase + require 'shellwords' - def base_dir - prefix_dir || '/usr' + def el6? + return true if node['platform_family'] == 'rhel' && node['platform_version'].to_i == 6 + false end - def configure_package_repositories - # we need to enable the yum-mysql-community repository to get packages - return unless %w(rhel fedora).include? node['platform_family'] - case parsed_version - when '5.5' - # Prefer packages from native repos - return if node['platform_family'] == 'rhel' && node['platform_version'].to_i == 5 - return if node['platform_family'] == 'fedora' - include_recipe('yum-mysql-community::mysql55') - when '5.6' - include_recipe('yum-mysql-community::mysql56') - when '5.7' - include_recipe('yum-mysql-community::mysql57') - end + def el7? + return true if node['platform_family'] == 'rhel' && node['platform_version'].to_i == 7 + false end - def client_package_name - return new_resource.package_name if new_resource.package_name - client_package + def wheezy? + return true if node['platform'] == 'debian' && node['platform_version'].to_i == 7 + false + end + + def jessie? + return true if node['platform'] == 'debian' && node['platform_version'].to_i == 8 + false + end + + def precise? + return true if node['platform'] == 'ubuntu' && node['platform_version'] == '12.04' + false + end + + def trusty? + return true if node['platform'] == 'ubuntu' && node['platform_version'] == '14.04' + return true if node['platform'] == 'linuxmint' && node['platform_version'] =~ /^17\.[0-9]$/ + false + end + + def xenial? + return true if node['platform'] == 'ubuntu' && node['platform_version'] == '16.04' + false end def defaults_file "#{etc_dir}/my.cnf" end - def error_log - return new_resource.error_log if new_resource.error_log + def default_data_dir + return "/var/lib/#{mysql_name}" if node['os'] == 'linux' + return "/opt/local/lib/#{mysql_name}" if node['os'] == 'solaris2' + return "/var/db/#{mysql_name}" if node['os'] == 'freebsd' + end + + def default_error_log "#{log_dir}/error.log" end - def etc_dir - return "/opt/mysql#{pkg_ver_string}/etc/#{mysql_name}" if node['platform_family'] == 'omnios' - return "#{prefix_dir}/etc/#{mysql_name}" if node['platform_family'] == 'smartos' - "#{prefix_dir}/etc/#{mysql_name}" + def default_pid_file + "#{run_dir}/mysqld.pid" end - def include_dir - "#{etc_dir}/conf.d" + def default_major_version + # rhelish + return '5.1' if el6? + return '5.6' if el7? + return '5.5' if node['platform'] == 'amazon' + + # debian + return '5.5' if wheezy? + return '5.5' if jessie? + + # ubuntu + return '5.5' if precise? + return '5.5' if trusty? + return '5.7' if xenial? + + # misc + return '5.6' if node['platform'] == 'freebsd' + return '5.6' if node['platform'] == 'fedora' + return '5.6' if node['platform_family'] == 'suse' end - def lc_messages_dir - end - - def log_dir - return "/var/adm/log/#{mysql_name}" if node['platform_family'] == 'omnios' - "#{prefix_dir}/var/log/#{mysql_name}" + def major_from_full(v) + v.split('.').shift(2).join('.') end def mysql_name - "mysql-#{new_resource.instance}" + "mysql-#{instance}" end - def pkg_ver_string - parsed_version.delete('.') if node['platform_family'] == 'omnios' + def default_socket_file + "#{run_dir}/mysqld.sock" + end + + def default_client_package_name + return ['mysql', 'mysql-devel'] if major_version == '5.1' && el6? + return ['mysql-client-5.5', 'libmysqlclient-dev'] if major_version == '5.5' && node['platform_family'] == 'debian' + return ['mysql-client-5.6', 'libmysqlclient-dev'] if major_version == '5.6' && node['platform_family'] == 'debian' + return ['mysql-client-5.7', 'libmysqlclient-dev'] if major_version == '5.7' && node['platform_family'] == 'debian' + return 'mysql-community-server-client' if major_version == '5.6' && node['platform_family'] == 'suse' + ['mysql-community-client', 'mysql-community-devel'] + end + + def default_server_package_name + return 'mysql-server' if major_version == '5.1' && el6? + return 'mysql-server-5.5' if major_version == '5.5' && node['platform_family'] == 'debian' + return 'mysql-server-5.6' if major_version == '5.6' && node['platform_family'] == 'debian' + return 'mysql-server-5.7' if major_version == '5.7' && node['platform_family'] == 'debian' + return 'mysql-community-server' if major_version == '5.6' && node['platform_family'] == 'suse' + 'mysql-community-server' + end + + def socket_dir + File.dirname(socket) + end + + def run_dir + return "#{prefix_dir}/var/run/#{mysql_name}" if node['platform_family'] == 'rhel' + return "/run/#{mysql_name}" if node['platform_family'] == 'debian' + "/var/run/#{mysql_name}" end def prefix_dir @@ -72,102 +125,70 @@ module MysqlCookbook def scl_name return unless node['platform_family'] == 'rhel' - return 'mysql51' if parsed_version == '5.1' && node['platform_version'].to_i == 5 - return 'mysql55' if parsed_version == '5.5' && node['platform_version'].to_i == 5 + return 'mysql51' if version == '5.1' && node['platform_version'].to_i == 5 + return 'mysql55' if version == '5.5' && node['platform_version'].to_i == 5 end def scl_package? return unless node['platform_family'] == 'rhel' - return true if parsed_version == '5.1' && node['platform_version'].to_i == 5 - return true if parsed_version == '5.5' && node['platform_version'].to_i == 5 + return true if version == '5.1' && node['platform_version'].to_i == 5 + return true if version == '5.5' && node['platform_version'].to_i == 5 false end + def etc_dir + return "/opt/mysql#{pkg_ver_string}/etc/#{mysql_name}" if node['platform_family'] == 'omnios' + return "#{prefix_dir}/etc/#{mysql_name}" if node['platform_family'] == 'smartos' + "#{prefix_dir}/etc/#{mysql_name}" + end + + def base_dir + prefix_dir || '/usr' + end + def system_service_name return 'mysql51-mysqld' if node['platform_family'] == 'rhel' && scl_name == 'mysql51' return 'mysql55-mysqld' if node['platform_family'] == 'rhel' && scl_name == 'mysql55' return 'mysqld' if node['platform_family'] == 'rhel' return 'mysqld' if node['platform_family'] == 'fedora' - return 'mysql' if node['platform_family'] == 'debian' - return 'mysql' if node['platform_family'] == 'suse' - return 'mysql' if node['platform_family'] == 'omnios' - return 'mysql' if node['platform_family'] == 'smartos' + 'mysql' # not one of the above end def v56plus - return false if parsed_version.split('.')[0].to_i < 5 - return false if parsed_version.split('.')[1].to_i < 6 + return false if version.split('.')[0].to_i < 5 + return false if version.split('.')[1].to_i < 6 true end def v57plus - return false if parsed_version.split('.')[0].to_i < 5 - return false if parsed_version.split('.')[1].to_i < 7 + return false if version.split('.')[0].to_i < 5 + return false if version.split('.')[1].to_i < 7 true end - def password_column_name - return 'authentication_string' if v57plus - 'password' + def default_include_dir + "#{etc_dir}/conf.d" end - def password_expired - return ", password_expired='N'" if v57plus - '' + def log_dir + return "/var/adm/log/#{mysql_name}" if node['platform_family'] == 'omnios' + "#{prefix_dir}/var/log/#{mysql_name}" end - def root_password - if new_resource.initial_root_password == '' - Chef::Log.info('Root password is empty') - return '' - end - Shellwords.escape(new_resource.initial_root_password) - end - - # database and initial records - # initialization commands - - def mysqld_initialize_cmd - cmd = mysqld_bin - cmd << " --defaults-file=#{etc_dir}/my.cnf" - cmd << ' --initialize' - cmd << ' --explicit_defaults_for_timestamp' if v56plus - return "scl enable #{scl_name} \"#{cmd}\"" if scl_package? - cmd - end - - def mysql_install_db_cmd - cmd = mysql_install_db_bin - cmd << " --defaults-file=#{etc_dir}/my.cnf" - cmd << " --datadir=#{parsed_data_dir}" - cmd << ' --explicit_defaults_for_timestamp' if v56plus - return "scl enable #{scl_name} \"#{cmd}\"" if scl_package? - cmd - end - - def record_init - cmd = v56plus ? mysqld_bin : mysqld_safe_bin - cmd << " --defaults-file=#{etc_dir}/my.cnf" - cmd << " --init-file=/tmp/#{mysql_name}/my.sql" - cmd << ' --explicit_defaults_for_timestamp' if v56plus - cmd << ' &' - return "scl enable #{scl_name} \"#{cmd}\"" if scl_package? - cmd - end - - def db_init - return mysqld_initialize_cmd if v57plus - mysql_install_db_cmd - end + def lc_messages_dir; end def init_records_script + # Note: shell-escaping passwords in a SQL file may cause corruption - eg + # mysql will read \& as &, but \% as \%. Just escape bare-minimum \ and ' + sql_escaped_password = root_password.gsub('\\') { '\\\\' }.gsub("'") { '\\\'' } + <<-EOS set -e rm -rf /tmp/#{mysql_name} mkdir /tmp/#{mysql_name} - cat > /tmp/#{mysql_name}/my.sql <<-EOSQL -UPDATE mysql.user SET #{password_column_name}=PASSWORD('#{root_password}')#{password_expired} WHERE user = 'root'; + cat > /tmp/#{mysql_name}/my.sql <<-'EOSQL' +UPDATE mysql.user SET #{password_column_name}=PASSWORD('#{sql_escaped_password}')#{password_expired} WHERE user = 'root'; DELETE FROM mysql.user WHERE USER LIKE ''; DELETE FROM mysql.user WHERE user = 'root' and host NOT IN ('127.0.0.1', 'localhost'); FLUSH PRIVILEGES; @@ -185,10 +206,27 @@ EOSQL EOS end - def mysql_bin - return "#{prefix_dir}/bin/mysql" if node['platform_family'] == 'smartos' - return "#{base_dir}/bin/mysql" if node['platform_family'] == 'omnios' - "#{prefix_dir}/usr/bin/mysql" + def password_column_name + return 'authentication_string' if v57plus + 'password' + end + + def root_password + if initial_root_password == '' + Chef::Log.info('Root password is empty') + return '' + end + initial_root_password + end + + def password_expired + return ", password_expired='N'" if v57plus + '' + end + + def db_init + return mysqld_initialize_cmd if v57plus + mysql_install_db_cmd end def mysql_install_db_bin @@ -197,8 +235,13 @@ EOSQL 'mysql_install_db' end - def mysql_version - new_resource.version + def mysql_install_db_cmd + cmd = mysql_install_db_bin + cmd << " --defaults-file=#{etc_dir}/my.cnf" + cmd << " --datadir=#{data_dir}" + cmd << ' --explicit_defaults_for_timestamp' if v56plus && !v57plus + return "scl enable #{scl_name} \"#{cmd}\"" if scl_package? + cmd end def mysqladmin_bin @@ -216,6 +259,15 @@ EOSQL "#{prefix_dir}/usr/sbin/mysqld" end + def mysqld_initialize_cmd + cmd = mysqld_bin + cmd << " --defaults-file=#{etc_dir}/my.cnf" + cmd << ' --initialize' + cmd << ' --explicit_defaults_for_timestamp' if v56plus + return "scl enable #{scl_name} \"#{cmd}\"" if scl_package? + cmd + end + def mysqld_safe_bin return "#{prefix_dir}/bin/mysqld_safe" if node['platform_family'] == 'smartos' return "#{base_dir}/bin/mysqld_safe" if node['platform_family'] == 'omnios' @@ -223,248 +275,18 @@ EOSQL "#{prefix_dir}/usr/bin/mysqld_safe" end - def pid_file - return new_resource.pid_file if new_resource.pid_file - "#{run_dir}/mysqld.pid" - end - - def run_dir - return "#{prefix_dir}/var/run/#{mysql_name}" if node['platform_family'] == 'rhel' - return "/run/#{mysql_name}" if node['platform_family'] == 'debian' - "/var/run/#{mysql_name}" + def record_init + cmd = v56plus ? mysqld_bin : mysqld_safe_bin + cmd << " --defaults-file=#{etc_dir}/my.cnf" + cmd << " --init-file=/tmp/#{mysql_name}/my.sql" + cmd << ' --explicit_defaults_for_timestamp' if v56plus + cmd << ' &' + return "scl enable #{scl_name} \"#{cmd}\"" if scl_package? + cmd end def sensitive_supported? Gem::Version.new(Chef::VERSION) >= Gem::Version.new('11.14.0') end - - def socket_file - return new_resource.socket if new_resource.socket - "#{run_dir}/mysqld.sock" - end - - def socket_dir - return File.dirname(new_resource.socket) if new_resource.socket - run_dir - end - - def tmp_dir - return new_resource.tmp_dir if new_resource.tmp_dir - '/tmp' - end - - ####### - # FIXME: There is a LOT of duplication here.. - # There has to be a less gnarly way to look up this information. Refactor for great good! - ####### - class Pkginfo - def self.pkginfo - # Autovivification is Perl. - @pkginfo = Chef::Node.new - - @pkginfo.set['debian']['10.04']['5.1']['client_package'] = %w(mysql-client-5.1 libmysqlclient-dev) - @pkginfo.set['debian']['10.04']['5.1']['server_package'] = 'mysql-server-5.1' - @pkginfo.set['debian']['12.04']['5.5']['client_package'] = %w(mysql-client-5.5 libmysqlclient-dev) - @pkginfo.set['debian']['12.04']['5.5']['server_package'] = 'mysql-server-5.5' - @pkginfo.set['debian']['13.04']['5.5']['client_package'] = %w(mysql-client-5.5 libmysqlclient-dev) - @pkginfo.set['debian']['13.04']['5.5']['server_package'] = 'mysql-server-5.5' - @pkginfo.set['debian']['13.10']['5.5']['client_package'] = %w(mysql-client-5.5 libmysqlclient-dev) - @pkginfo.set['debian']['13.10']['5.5']['server_package'] = 'mysql-server-5.5' - @pkginfo.set['debian']['14.04']['5.5']['client_package'] = %w(mysql-client-5.5 libmysqlclient-dev) - @pkginfo.set['debian']['14.04']['5.5']['server_package'] = 'mysql-server-5.5' - @pkginfo.set['debian']['14.04']['5.6']['client_package'] = %w(mysql-client-5.6 libmysqlclient-dev) - @pkginfo.set['debian']['14.04']['5.6']['server_package'] = 'mysql-server-5.6' - @pkginfo.set['debian']['14.10']['5.5']['client_package'] = %w(mysql-client-5.5 libmysqlclient-dev) - @pkginfo.set['debian']['14.10']['5.5']['server_package'] = 'mysql-server-5.5' - @pkginfo.set['debian']['14.10']['5.6']['client_package'] = %w(mysql-client-5.6 libmysqlclient-dev) - @pkginfo.set['debian']['14.10']['5.6']['server_package'] = 'mysql-server-5.6' - @pkginfo.set['debian']['15.04']['5.6']['client_package'] = %w(mysql-client-5.6 libmysqlclient-dev) - @pkginfo.set['debian']['15.04']['5.6']['server_package'] = 'mysql-server-5.6' - @pkginfo.set['debian']['15.10']['5.6']['client_package'] = %w(mysql-client-5.6 libmysqlclient-dev) - @pkginfo.set['debian']['15.10']['5.6']['server_package'] = 'mysql-server-5.6' - @pkginfo.set['debian']['6']['5.1']['client_package'] = %w(mysql-client libmysqlclient-dev) - @pkginfo.set['debian']['6']['5.1']['server_package'] = 'mysql-server-5.1' - @pkginfo.set['debian']['7']['5.5']['client_package'] = %w(mysql-client libmysqlclient-dev) - @pkginfo.set['debian']['7']['5.5']['server_package'] = 'mysql-server-5.5' - @pkginfo.set['debian']['7']['5.6']['client_package'] = %w(mysql-client libmysqlclient-dev) # apt-repo from dotdeb - @pkginfo.set['debian']['7']['5.6']['server_package'] = 'mysql-server-5.6' - @pkginfo.set['debian']['7']['5.7']['client_package'] = %w(mysql-client libmysqlclient-dev) # apt-repo from dotdeb - @pkginfo.set['debian']['7']['5.7']['server_package'] = 'mysql-server-5.7' - @pkginfo.set['debian']['8']['5.5']['client_package'] = %w(mysql-client libmysqlclient-dev) - @pkginfo.set['debian']['8']['5.5']['server_package'] = 'mysql-server-5.5' - @pkginfo.set['fedora']['20']['5.5']['client_package'] = %w(community-mysql community-mysql-devel) - @pkginfo.set['fedora']['20']['5.5']['server_package'] = 'community-mysql-server' - @pkginfo.set['fedora']['20']['5.6']['client_package'] = %w(mysql-community-client mysql-community-devel) - @pkginfo.set['fedora']['20']['5.6']['server_package'] = 'mysql-community-server' - @pkginfo.set['fedora']['20']['5.7']['client_package'] = %w(mysql-community-client mysql-community-devel) - @pkginfo.set['fedora']['20']['5.7']['server_package'] = 'mysql-community-server' - @pkginfo.set['fedora']['21']['5.6']['client_package'] = %w(mysql-community-client mysql-community-devel) - @pkginfo.set['fedora']['21']['5.6']['server_package'] = 'mysql-community-server' - @pkginfo.set['fedora']['21']['5.7']['client_package'] = %w(mysql-community-client mysql-community-devel) - @pkginfo.set['fedora']['21']['5.7']['server_package'] = 'mysql-community-server' - @pkginfo.set['fedora']['22']['5.6']['client_package'] = %w(mysql-community-client mysql-community-devel) - @pkginfo.set['fedora']['22']['5.6']['server_package'] = 'mysql-community-server' - @pkginfo.set['fedora']['22']['5.7']['client_package'] = %w(mysql-community-client mysql-community-devel) - @pkginfo.set['fedora']['22']['5.7']['server_package'] = 'mysql-community-server' - @pkginfo.set['freebsd']['10']['5.5']['client_package'] = %w(mysql55-client) - @pkginfo.set['freebsd']['10']['5.5']['server_package'] = 'mysql55-server' - @pkginfo.set['freebsd']['9']['5.5']['client_package'] = %w(mysql55-client) - @pkginfo.set['freebsd']['9']['5.5']['server_package'] = 'mysql55-server' - @pkginfo.set['omnios']['151006']['5.5']['client_package'] = %w(database/mysql-55/library) - @pkginfo.set['omnios']['151006']['5.5']['server_package'] = 'database/mysql-55' - @pkginfo.set['omnios']['151006']['5.6']['client_package'] = %w(database/mysql-56) - @pkginfo.set['omnios']['151006']['5.6']['server_package'] = 'database/mysql-56' - @pkginfo.set['rhel']['2014.09']['5.1']['server_package'] = %w(mysql51 mysql51-devel) - @pkginfo.set['rhel']['2014.09']['5.1']['server_package'] = 'mysql51-server' - @pkginfo.set['rhel']['2014.09']['5.5']['client_package'] = %w(mysql-community-client mysql-community-devel) - @pkginfo.set['rhel']['2014.09']['5.5']['server_package'] = 'mysql-community-server' - @pkginfo.set['rhel']['2014.09']['5.6']['client_package'] = %w(mysql-community-client mysql-community-devel) - @pkginfo.set['rhel']['2014.09']['5.6']['server_package'] = 'mysql-community-server' - @pkginfo.set['rhel']['2014.09']['5.7']['client_package'] = %w(mysql-community-client mysql-community-devel) - @pkginfo.set['rhel']['2014.09']['5.7']['server_package'] = 'mysql-community-server' - @pkginfo.set['rhel']['2015.03']['5.1']['server_package'] = %w(mysql51 mysql51-devel) - @pkginfo.set['rhel']['2015.03']['5.1']['server_package'] = 'mysql51-server' - @pkginfo.set['rhel']['2015.03']['5.5']['client_package'] = %w(mysql-community-client mysql-community-devel) - @pkginfo.set['rhel']['2015.03']['5.5']['server_package'] = 'mysql-community-server' - @pkginfo.set['rhel']['2015.03']['5.6']['client_package'] = %w(mysql-community-client mysql-community-devel) - @pkginfo.set['rhel']['2015.03']['5.6']['server_package'] = 'mysql-community-server' - @pkginfo.set['rhel']['2015.03']['5.7']['client_package'] = %w(mysql-community-client mysql-community-devel) - @pkginfo.set['rhel']['2015.03']['5.7']['server_package'] = 'mysql-community-server' - @pkginfo.set['rhel']['2015.09']['5.1']['server_package'] = %w(mysql51 mysql51-devel) - @pkginfo.set['rhel']['2015.09']['5.1']['server_package'] = 'mysql51-server' - @pkginfo.set['rhel']['2015.09']['5.5']['client_package'] = %w(mysql-community-client mysql-community-devel) - @pkginfo.set['rhel']['2015.09']['5.5']['server_package'] = 'mysql-community-server' - @pkginfo.set['rhel']['2015.09']['5.6']['client_package'] = %w(mysql-community-client mysql-community-devel) - @pkginfo.set['rhel']['2015.09']['5.6']['server_package'] = 'mysql-community-server' - @pkginfo.set['rhel']['2015.09']['5.7']['client_package'] = %w(mysql-community-client mysql-community-devel) - @pkginfo.set['rhel']['2015.09']['5.7']['server_package'] = 'mysql-community-server' - @pkginfo.set['rhel']['2016.03']['5.1']['server_package'] = %w(mysql51 mysql51-devel) - @pkginfo.set['rhel']['2016.03']['5.1']['server_package'] = 'mysql51-server' - @pkginfo.set['rhel']['2016.03']['5.5']['client_package'] = %w(mysql-community-client mysql-community-devel) - @pkginfo.set['rhel']['2016.03']['5.5']['server_package'] = 'mysql-community-server' - @pkginfo.set['rhel']['2016.03']['5.6']['client_package'] = %w(mysql-community-client mysql-community-devel) - @pkginfo.set['rhel']['2016.03']['5.6']['server_package'] = 'mysql-community-server' - @pkginfo.set['rhel']['2016.03']['5.7']['client_package'] = %w(mysql-community-client mysql-community-devel) - @pkginfo.set['rhel']['2016.03']['5.7']['server_package'] = 'mysql-community-server' - @pkginfo.set['rhel']['5']['5.0']['client_package'] = %w(mysql mysql-devel) - @pkginfo.set['rhel']['5']['5.0']['server_package'] = 'mysql-server' - @pkginfo.set['rhel']['5']['5.1']['client_package'] = %w(mysql51-mysql) - @pkginfo.set['rhel']['5']['5.1']['server_package'] = 'mysql51-mysql-server' - @pkginfo.set['rhel']['5']['5.5']['client_package'] = %w(mysql55-mysql mysql55-mysql-devel) - @pkginfo.set['rhel']['5']['5.5']['server_package'] = 'mysql55-mysql-server' - @pkginfo.set['rhel']['5']['5.6']['client_package'] = %w(mysql-community-client mysql-community-devel) - @pkginfo.set['rhel']['5']['5.6']['server_package'] = 'mysql-community-server' - @pkginfo.set['rhel']['5']['5.7']['client_package'] = %w(mysql-community-client mysql-community-devel) - @pkginfo.set['rhel']['5']['5.7']['server_package'] = 'mysql-community-server' - @pkginfo.set['rhel']['6']['5.1']['client_package'] = %w(mysql mysql-devel) - @pkginfo.set['rhel']['6']['5.1']['server_package'] = 'mysql-server' - @pkginfo.set['rhel']['6']['5.5']['client_package'] = %w(mysql-community-client mysql-community-devel) - @pkginfo.set['rhel']['6']['5.5']['server_package'] = 'mysql-community-server' - @pkginfo.set['rhel']['6']['5.6']['client_package'] = %w(mysql-community-client mysql-community-devel) - @pkginfo.set['rhel']['6']['5.6']['server_package'] = 'mysql-community-server' - @pkginfo.set['rhel']['6']['5.7']['client_package'] = %w(mysql-community-client mysql-community-devel) - @pkginfo.set['rhel']['6']['5.7']['server_package'] = 'mysql-community-server' - @pkginfo.set['rhel']['7']['5.5']['client_package'] = %w(mysql-community-client mysql-community-devel) - @pkginfo.set['rhel']['7']['5.5']['server_package'] = 'mysql-community-server' - @pkginfo.set['rhel']['7']['5.6']['client_package'] = %w(mysql-community-client mysql-community-devel) - @pkginfo.set['rhel']['7']['5.6']['server_package'] = 'mysql-community-server' - @pkginfo.set['rhel']['7']['5.7']['client_package'] = %w(mysql-community-client mysql-community-devel) - @pkginfo.set['rhel']['7']['5.7']['server_package'] = 'mysql-community-server' - @pkginfo.set['smartos']['5.11']['5.5']['client_package'] = %w(mysql-client) - @pkginfo.set['smartos']['5.11']['5.5']['server_package'] = 'mysql-server' - @pkginfo.set['smartos']['5.11']['5.6']['client_package'] = %w(mysql-client) - @pkginfo.set['smartos']['5.11']['5.6']['server_package'] = 'mysql-server' - @pkginfo.set['suse']['11.3']['5.5']['client_package'] = %w(mysql-client) - @pkginfo.set['suse']['11.3']['5.5']['server_package'] = 'mysql' - @pkginfo.set['suse']['12.0']['5.5']['client_package'] = %w(mysql-client) - @pkginfo.set['suse']['12.0']['5.5']['server_package'] = 'mysql' - - @pkginfo - end - end - - def package_name_for(platform, platform_family, platform_version, version, type) - keyname = keyname_for(platform, platform_family, platform_version) - info = Pkginfo.pkginfo[platform_family.to_sym][keyname] - type_label = type.to_s.gsub('_package', '').capitalize - unless info[version] - # Show availabe versions if the requested is not available on the current platform - Chef::Log.error("Unsupported Version: You requested to install a Mysql #{type_label} version that is not supported by your platform") - Chef::Log.error("Platform: #{platform_family} #{platform_version} - Request Mysql #{type_label} version: #{version}") - Chef::Log.error("Availabe versions for your platform are: #{info.map { |k, _v| k }.join(' - ')}") - raise "Unsupported Mysql #{type_label} Version" - end - info[version][type] - end - - def keyname_for(platform, platform_family, platform_version) - return platform_version if platform_family == 'debian' && platform == 'ubuntu' - return platform_version if platform_family == 'fedora' - return platform_version if platform_family == 'omnios' - return platform_version if platform_family == 'rhel' && platform == 'amazon' - return platform_version if platform_family == 'smartos' - return platform_version if platform_family == 'suse' - return platform_version.to_i.to_s if platform_family == 'debian' - return platform_version.to_i.to_s if platform_family == 'rhel' - return platform_version.to_s if platform_family == 'debian' && platform_version =~ /sid$/ - return platform_version.to_s if platform_family == 'freebsd' - end - - def parsed_data_dir - return new_resource.data_dir if new_resource.data_dir - return "/opt/local/lib/#{mysql_name}" if node['os'] == 'solaris2' - return "/var/lib/#{mysql_name}" if node['os'] == 'linux' - return "/var/db/#{mysql_name}" if node['os'] == 'freebsd' - end - - def client_package - package_name_for( - node['platform'], - node['platform_family'], - node['platform_version'], - parsed_version, - :client_package - ) - end - - def server_package - package_name_for( - node['platform'], - node['platform_family'], - node['platform_version'], - parsed_version, - :server_package - ) - end - - def server_package_name - return new_resource.package_name if new_resource.package_name - server_package - end - - def parsed_version - return new_resource.version if new_resource.version - return '5.0' if node['platform_family'] == 'rhel' && node['platform_version'].to_i == 5 - return '5.1' if node['platform_family'] == 'debian' && node['platform_version'] == '10.04' - return '5.1' if node['platform_family'] == 'debian' && node['platform_version'].to_i == 6 - return '5.1' if node['platform_family'] == 'rhel' && node['platform_version'].to_i == 6 - return '5.5' if node['platform_family'] == 'debian' && node['platform_version'] == '12.04' - return '5.5' if node['platform_family'] == 'debian' && node['platform_version'] == '13.04' - return '5.5' if node['platform_family'] == 'debian' && node['platform_version'] == '13.10' - return '5.5' if node['platform_family'] == 'debian' && node['platform_version'] == '14.04' - return '5.5' if node['platform_family'] == 'debian' && node['platform_version'] == '14.10' - return '5.5' if node['platform_family'] == 'debian' && node['platform_version'].to_i == 7 - return '5.5' if node['platform_family'] == 'debian' && node['platform_version'].to_i == 8 - return '5.5' if node['platform_family'] == 'freebsd' - return '5.5' if node['platform_family'] == 'omnios' - return '5.5' if node['platform_family'] == 'rhel' && node['platform_version'].to_i == 2014 - return '5.5' if node['platform_family'] == 'rhel' && node['platform_version'].to_i == 2015 - return '5.5' if node['platform_family'] == 'rhel' && node['platform_version'].to_i == 7 - return '5.5' if node['platform_family'] == 'smartos' - return '5.5' if node['platform_family'] == 'suse' - return '5.6' if node['platform_family'] == 'fedora' - return '5.6' if node['platform_family'] == 'debian' && node['platform_version'] == '15.04' - return '5.6' if node['platform_family'] == 'debian' && node['platform_version'] == '15.10' - end end end diff --git a/cookbooks/mysql/libraries/matchers.rb b/cookbooks/mysql/libraries/matchers.rb index 373e3cb..adf5e73 100644 --- a/cookbooks/mysql/libraries/matchers.rb +++ b/cookbooks/mysql/libraries/matchers.rb @@ -1,18 +1,40 @@ if defined?(ChefSpec) - if ChefSpec.respond_to?(:define_matcher) - # ChefSpec >= 4.1 - ChefSpec.define_matcher :mysql_config - ChefSpec.define_matcher :mysql_service - ChefSpec.define_matcher :mysql_client - elsif defined?(ChefSpec::Runner) && - ChefSpec::Runner.respond_to?(:define_runner_method) - # ChefSpec < 4.1 - ChefSpec::Runner.define_runner_method :mysql_config - ChefSpec::Runner.define_runner_method :mysql_service - ChefSpec::Runner.define_runner_method :mysql_client + ChefSpec.define_matcher :mysql_config + ChefSpec.define_matcher :mysql_service + ChefSpec.define_matcher :mysql_client + + # mysql_client_client_installation_package + def install_mysql_client_installation_package(resource_name) + ChefSpec::Matchers::ResourceMatcher.new(:mysql_client_installation_package, :create, resource_name) end - # config + def remove_mysql_client_installation_package(resource_name) + ChefSpec::Matchers::ResourceMatcher.new(:mysql_client_installation_package, :remove, resource_name) + end + + # mysql_server_server_installation_package + def install_mysql_server_installation_package(resource_name) + ChefSpec::Matchers::ResourceMatcher.new(:mysql_server_installation_package, :install, resource_name) + end + + def remove_mysql_server_installation_package(resource_name) + ChefSpec::Matchers::ResourceMatcher.new(:mysql_server_installation_package, :remove, resource_name) + end + + ##### + # old + ##### + + # client + def create_mysql_client(resource_name) + ChefSpec::Matchers::ResourceMatcher.new(:mysql_client, :create, resource_name) + end + + def delete_mysql_client(resource_name) + ChefSpec::Matchers::ResourceMatcher.new(:mysql_client, :delete, resource_name) + end + + # mysql_config def create_mysql_config(resource_name) ChefSpec::Matchers::ResourceMatcher.new(:mysql_config, :create, resource_name) end @@ -46,12 +68,4 @@ if defined?(ChefSpec) ChefSpec::Matchers::ResourceMatcher.new(:mysql_service, :reload, resource_name) end - # client - def create_mysql_client(resource_name) - ChefSpec::Matchers::ResourceMatcher.new(:mysql_client, :create, resource_name) - end - - def delete_mysql_client(resource_name) - ChefSpec::Matchers::ResourceMatcher.new(:mysql_client, :delete, resource_name) - end end diff --git a/cookbooks/mysql/libraries/mysql_base.rb b/cookbooks/mysql/libraries/mysql_base.rb new file mode 100644 index 0000000..b04a129 --- /dev/null +++ b/cookbooks/mysql/libraries/mysql_base.rb @@ -0,0 +1,30 @@ +module MysqlCookbook + class MysqlBase < Chef::Resource + require_relative 'helpers' + + # All resources are composites + def whyrun_supported? + true + end + + ################ + # Type Constants + ################ + + Boolean = property_type( + is: [true, false], + default: false + ) unless defined?(Boolean) + + ################### + # Common Properties + ################### + property :run_group, String, default: 'mysql', desired_state: false + property :run_user, String, default: 'mysql', desired_state: false + property :version, String, default: lazy { default_major_version }, desired_state: false + property :include_dir, String, default: lazy { default_include_dir }, desired_state: false + property :major_version, String, default: lazy { major_from_full(version) }, desired_state: false + + declare_action_class + end +end diff --git a/cookbooks/mysql/libraries/mysql_client_installation_package.rb b/cookbooks/mysql/libraries/mysql_client_installation_package.rb new file mode 100644 index 0000000..1e1d946 --- /dev/null +++ b/cookbooks/mysql/libraries/mysql_client_installation_package.rb @@ -0,0 +1,31 @@ +module MysqlCookbook + class MysqlClientInstallationPackage < MysqlBase + # helper methods + require_relative 'helpers' + include MysqlCookbook::HelpersBase + + # Resource properties + resource_name :mysql_client_installation_package + provides :mysql_client_installation, os: 'linux' + provides :mysql_client, os: 'linux' + + property :package_name, [String, Array], default: lazy { default_client_package_name }, desired_state: false + property :package_options, [String, nil], desired_state: false + property :package_version, [String, nil], default: nil, desired_state: false + + # Actions + action :create do + package package_name do + version package_version if package_version + options package_options if package_options + action :install + end + end + + action :delete do + package package_name do + action :remove + end + end + end +end diff --git a/cookbooks/mysql/libraries/mysql_config.rb b/cookbooks/mysql/libraries/mysql_config.rb new file mode 100644 index 0000000..707119a --- /dev/null +++ b/cookbooks/mysql/libraries/mysql_config.rb @@ -0,0 +1,56 @@ +module MysqlCookbook + class MysqlConfig < MysqlBase + resource_name :mysql_config + + property :config_name, String, name_property: true, desired_state: false + property :cookbook, String, desired_state: false + property :group, String, default: 'mysql', desired_state: false + property :instance, String, default: 'default', desired_state: false + property :owner, String, default: 'mysql', desired_state: false + property :source, String, desired_state: false + property :variables, [Hash], desired_state: false + property :version, String, default: lazy { default_major_version }, desired_state: false + + require_relative 'helpers' + include MysqlCookbook::HelpersBase + + provides :mysql_config + + action :create do + # hax because group property + g = Chef::Resource::Group.new(new_resource.group, run_context) + g.system true if name == 'mysql' + resource_collection.insert g + + user owner do + gid owner + system true if name == 'mysql' + action :create + end + + directory include_dir do + owner new_resource.owner + group new_resource.group + mode '0750' + recursive true + action :create + end + + template "#{include_dir}/#{config_name}.cnf" do + owner new_resource.owner + group new_resource.group + mode '0640' + variables(new_resource.variables) + source new_resource.source + cookbook cookbook + action :create + end + end + + action :delete do + file "#{include_dir}/#{config_name}.cnf" do + action :delete + end + end + end +end diff --git a/cookbooks/mysql/libraries/mysql_server_installation_package.rb b/cookbooks/mysql/libraries/mysql_server_installation_package.rb new file mode 100644 index 0000000..385e202 --- /dev/null +++ b/cookbooks/mysql/libraries/mysql_server_installation_package.rb @@ -0,0 +1,42 @@ +module MysqlCookbook + class MysqlServerInstallationPackage < MysqlBase + # Resource properties + resource_name :mysql_server_installation_package + provides :mysql_server_installation, os: 'linux' + + property :package_name, String, default: lazy { default_server_package_name }, desired_state: false + property :package_options, [String, nil], desired_state: false + property :package_version, [String, nil], default: nil, desired_state: false + + # helper methods + require_relative 'helpers' + include MysqlCookbook::HelpersBase + + # Actions + action :install do + package package_name do + version package_version if package_version + options package_options if package_options + notifies :install, 'package[perl-Sys-Hostname-Long]', :immediately if platform_family?('suse') + notifies :run, 'execute[Initial DB setup script]', :immediately if platform_family?('suse') + action :install + end + + package 'perl-Sys-Hostname-Long' do + action :nothing + end + + execute 'Initial DB setup script' do + environment 'INSTANCE' => new_resource.name + command '/usr/lib/mysql/mysql-systemd-helper install' + action :nothing + end + end + + action :delete do + package package_name do + action :remove + end + end + end +end diff --git a/cookbooks/mysql/libraries/mysql_service.rb b/cookbooks/mysql/libraries/mysql_service.rb new file mode 100644 index 0000000..80fb7c3 --- /dev/null +++ b/cookbooks/mysql/libraries/mysql_service.rb @@ -0,0 +1,105 @@ +module MysqlCookbook + require_relative 'mysql_service_base' + class MysqlService < MysqlServiceBase + resource_name :mysql_service + + # installation type and service_manager + property :install_method, %w(package auto), default: 'auto', desired_state: false + property :service_manager, %w(sysvinit upstart systemd auto), default: 'auto', desired_state: false + + # mysql_server_installation + property :version, String, default: lazy { default_major_version }, desired_state: false + property :major_version, String, default: lazy { major_from_full(version) }, desired_state: false + property :package_name, String, default: lazy { default_package_name }, desired_state: false + property :package_options, [String, nil], desired_state: false + property :package_version, [String, nil], default: nil, desired_state: false + + ################ + # Helper Methods + ################ + + def copy_properties_to(to, *properties) + properties = self.class.properties.keys if properties.empty? + properties.each do |p| + # If the property is set on from, and exists on to, set the + # property on to + if to.class.properties.include?(p) && property_is_set?(p) + to.send(p, send(p)) + end + end + end + + action_class.class_eval do + def installation(&block) + case install_method + when 'auto' + install = mysql_server_installation(name, &block) + when 'package' + install = mysql_server_installation_package(name, &block) + when 'none' + Chef::Log.info('Skipping MySQL installation. Assuming it was handled previously.') + return + end + copy_properties_to(install) + install + end + + def svc_manager(&block) + case service_manager + when 'auto' + svc = mysql_service_manager(name, &block) + when 'sysvinit' + svc = mysql_service_manager_sysvinit(name, &block) + when 'upstart' + svc = mysql_service_manager_upstart(name, &block) + when 'systemd' + svc = mysql_service_manager_systemd(name, &block) + end + copy_properties_to(svc) + svc + end + end + + ######### + # Actions + ######### + + action :create do + installation do + action :install + end + + svc_manager do + action :create + end + end + + action :start do + svc_manager do + action :start + end + end + + action :delete do + svc_manager do + action :delete + end + + installation do + action :delete + end + end + + action :restart do + svc_manager do + action :restart + end + end + + action :stop do + svc_manager do + action :stop + end + end + end +end diff --git a/cookbooks/mysql/libraries/mysql_service_base.rb b/cookbooks/mysql/libraries/mysql_service_base.rb new file mode 100644 index 0000000..01f26c7 --- /dev/null +++ b/cookbooks/mysql/libraries/mysql_service_base.rb @@ -0,0 +1,203 @@ +module MysqlCookbook + class MysqlServiceBase < MysqlBase + property :bind_address, String, desired_state: false + property :charset, String, default: 'utf8', desired_state: false + property :data_dir, String, default: lazy { default_data_dir }, desired_state: false + property :error_log, String, default: lazy { default_error_log }, desired_state: false + property :initial_root_password, String, default: 'ilikerandompasswords', desired_state: false + property :instance, String, name_property: true, desired_state: false + property :mysqld_options, Hash, default: {}, desired_state: false + property :pid_file, String, default: lazy { default_pid_file }, desired_state: false + property :port, [String, Integer], default: '3306', desired_state: false + property :socket, String, default: lazy { default_socket_file }, desired_state: false + property :tmp_dir, String, desired_state: false + + alias socket_file socket + + require_relative 'helpers' + include MysqlCookbook::HelpersBase + + # action class methods are available within the actions and work as if the coded + # was inline the action. No messing with classes or passing in the new_resource + declare_action_class.class_eval do + def create_system_user + group 'mysql' do + action :create + end + + user 'mysql' do + gid 'mysql' + action :create + end + end + + def create_config + # require 'pry' ; binding.pry + + # Yak shaving secion. Account for random errata. + # + # Turns out that mysqld is hard coded to try and read + # /etc/mysql/my.cnf, and its presence causes problems when + # setting up multiple services. + file "#{prefix_dir}/etc/mysql/my.cnf" do + action :delete + end + + file "#{prefix_dir}/etc/my.cnf" do + action :delete + end + + # mysql_install_db is broken on 5.6.13 + link "#{prefix_dir}/usr/share/my-default.cnf" do + to "#{etc_dir}/my.cnf" + not_if { ::File.exist? "#{prefix_dir}/usr/share/my-default.cnf" } # FIXME: Chef bug? + action :create + end + + # Support directories + directory etc_dir do + owner run_user + group run_group + mode '0750' + recursive true + action :create + end + + directory include_dir do + owner run_user + group run_group + mode '0750' + recursive true + action :create + end + + directory run_dir do + owner run_user + group run_group + mode '0755' + recursive true + action :create + end + + directory log_dir do + owner run_user + group run_group + mode '0750' + recursive true + action :create + end + + directory data_dir do + owner run_user + group run_group + mode '0750' + recursive true + action :create + end + + # Main configuration file + template "#{etc_dir}/my.cnf" do + source 'my.cnf.erb' + cookbook 'mysql' + owner run_user + group run_group + mode '0600' + variables(config: new_resource) + action :create + end + end + + def initialize_database + # initialize database and create initial records + bash "#{name} initial records" do + code init_records_script + umask '022' + returns [0, 1, 2] # facepalm + not_if "/usr/bin/test -f #{data_dir}/mysql/user.frm" + action :run + end + end + + def delete_support_directories + # Stop the service before removing support directories + delete_stop_service + + directory etc_dir do + recursive true + action :delete + end + + directory run_dir do + recursive true + action :delete + end + + directory log_dir do + recursive true + action :delete + end + end + + # + # Platform specific bits + # + def configure_apparmor + # Do not add these resource if inside a container + # Only valid on Ubuntu + return if ::File.exist?('/.dockerenv') || ::File.exist?('/.dockerinit') || node['platform'] != 'ubuntu' + + # Apparmor + package 'apparmor' do + action :install + end + + directory '/etc/apparmor.d/local/mysql' do + owner 'root' + group 'root' + mode '0755' + recursive true + action :create + end + + template '/etc/apparmor.d/local/usr.sbin.mysqld' do + cookbook 'mysql' + source 'apparmor/usr.sbin.mysqld-local.erb' + owner 'root' + group 'root' + mode '0644' + action :create + notifies :restart, "service[#{instance} apparmor]", :immediately + end + + template '/etc/apparmor.d/usr.sbin.mysqld' do + cookbook 'mysql' + source 'apparmor/usr.sbin.mysqld.erb' + owner 'root' + group 'root' + mode '0644' + action :create + notifies :restart, "service[#{instance} apparmor]", :immediately + end + + template "/etc/apparmor.d/local/mysql/#{instance}" do + cookbook 'mysql' + source 'apparmor/usr.sbin.mysqld-instance.erb' + owner 'root' + group 'root' + mode '0644' + variables( + config: new_resource, + mysql_name: mysql_name + ) + action :create + notifies :restart, "service[#{instance} apparmor]", :immediately + end + + service "#{instance} apparmor" do + service_name 'apparmor' + action :nothing + end + end + end + end +end diff --git a/cookbooks/mysql/libraries/mysql_service_manager_systemd.rb b/cookbooks/mysql/libraries/mysql_service_manager_systemd.rb new file mode 100644 index 0000000..e18fe74 --- /dev/null +++ b/cookbooks/mysql/libraries/mysql_service_manager_systemd.rb @@ -0,0 +1,142 @@ +module MysqlCookbook + class MysqlServiceManagerSystemd < MysqlServiceBase + resource_name :mysql_service_manager_systemd + + provides :mysql_service_manager, os: 'linux' do |_node| + Chef::Platform::ServiceHelpers.service_resource_providers.include?(:systemd) + end + + action :create do + # from base + create_system_user + stop_system_service + create_config + configure_apparmor + initialize_database + end + + action :start do + # Needed for Debian / Ubuntu + directory '/usr/libexec' do + owner 'root' + group 'root' + mode '0755' + action :create + end + + # this script is called by the main systemd unit file, and + # spins around until the service is actually up and running. + template "/usr/libexec/#{mysql_name}-wait-ready" do + path "/usr/libexec/#{mysql_name}-wait-ready" + source 'systemd/mysqld-wait-ready.erb' + owner 'root' + group 'root' + mode '0755' + variables(socket_file: socket_file) + cookbook 'mysql' + action :create + end + + # this is the main systemd unit file + template "/etc/systemd/system/#{mysql_name}.service" do + path "/etc/systemd/system/#{mysql_name}.service" + source 'systemd/mysqld.service.erb' + owner 'root' + group 'root' + mode '0644' + variables( + config: new_resource, + etc_dir: etc_dir, + base_dir: base_dir, + mysqld_bin: mysqld_bin + ) + cookbook 'mysql' + notifies :run, "execute[#{instance} systemctl daemon-reload]", :immediately + action :create + end + + # avoid 'Unit file changed on disk' warning + execute "#{instance} systemctl daemon-reload" do + command '/bin/systemctl daemon-reload' + action :nothing + end + + # tmpfiles.d config so the service survives reboot + template "/usr/lib/tmpfiles.d/#{mysql_name}.conf" do + path "/usr/lib/tmpfiles.d/#{mysql_name}.conf" + source 'tmpfiles.d.conf.erb' + owner 'root' + group 'root' + mode '0644' + variables( + run_dir: run_dir, + run_user: run_user, + run_group: run_group + ) + cookbook 'mysql' + action :create + end + + # service management resource + service mysql_name.to_s do + service_name mysql_name + provider Chef::Provider::Service::Systemd + supports restart: true, status: true + action [:enable, :start] + end + end + + action :stop do + # service management resource + service mysql_name.to_s do + service_name mysql_name + provider Chef::Provider::Service::Systemd + supports status: true + action [:disable, :stop] + only_if { ::File.exist?("/usr/lib/systemd/system/#{mysql_name}.service") } + end + end + + action :restart do + # service management resource + service mysql_name.to_s do + service_name mysql_name + provider Chef::Provider::Service::Systemd + supports restart: true + action :restart + end + end + + action :reload do + # service management resource + service mysql_name.to_s do + service_name mysql_name + provider Chef::Provider::Service::Systemd + action :reload + end + end + + declare_action_class.class_eval do + def stop_system_service + # service management resource + service 'mysql' do + service_name system_service_name + provider Chef::Provider::Service::Systemd + supports status: true + action [:stop, :disable] + end + end + + def delete_stop_service + # service management resource + service mysql_name.to_s do + service_name mysql_name + provider Chef::Provider::Service::Systemd + supports status: true + action [:disable, :stop] + only_if { ::File.exist?("/usr/lib/systemd/system/#{mysql_name}.service") } + end + end + end + end +end diff --git a/cookbooks/mysql/libraries/mysql_service_manager_sysvinit.rb b/cookbooks/mysql/libraries/mysql_service_manager_sysvinit.rb new file mode 100644 index 0000000..1b76064 --- /dev/null +++ b/cookbooks/mysql/libraries/mysql_service_manager_sysvinit.rb @@ -0,0 +1,79 @@ +module MysqlCookbook + class MysqlServiceManagerSysvinit < MysqlServiceBase + resource_name :mysql_service_manager_sysvinit + + provides :mysql_service_manager, os: 'linux' + + action :create do + # from base + create_system_user + stop_system_service + create_config + initialize_database + configure_apparmor + end + + action :start do + template "/etc/init.d/#{mysql_name}" do + source 'sysvinit/mysqld.erb' + owner 'root' + group 'root' + mode '0755' + variables( + config: new_resource, + defaults_file: defaults_file, + error_log: error_log, + mysql_name: mysql_name, + mysqladmin_bin: mysqladmin_bin, + mysqld_safe_bin: mysqld_safe_bin, + pid_file: pid_file, + scl_name: scl_name + ) + cookbook 'mysql' + action :create + end + + service mysql_name do + supports restart: true, status: true + action [:enable, :start] + end + end + + action :stop do + service mysql_name do + supports restart: true, status: true + action [:stop] + end + end + + action :restart do + service mysql_name do + supports restart: true + action :restart + end + end + + action :reload do + service mysql_name do + action :reload + end + end + + declare_action_class.class_eval do + def stop_system_service + service system_service_name do + supports status: true + action [:stop, :disable] + end + end + + def delete_stop_service + service mysql_name do + supports status: true + action [:disable, :stop] + only_if { ::File.exist?("#{etc_dir}/init.d/#{mysql_name}") } + end + end + end + end +end diff --git a/cookbooks/mysql/libraries/mysql_service_manager_upstart.rb b/cookbooks/mysql/libraries/mysql_service_manager_upstart.rb new file mode 100644 index 0000000..90d4172 --- /dev/null +++ b/cookbooks/mysql/libraries/mysql_service_manager_upstart.rb @@ -0,0 +1,103 @@ +module MysqlCookbook + class MysqlServiceManagerUpstart < MysqlServiceBase + resource_name :mysql_service_manager_upstart + + provides :mysql_service_manager, platform_family: 'debian' do |_node| + Chef::Platform::ServiceHelpers.service_resource_providers.include?(:upstart) && + !Chef::Platform::ServiceHelpers.service_resource_providers.include?(:systemd) && + !Chef::Platform::ServiceHelpers.service_resource_providers.include?(:redhat) && + ::File.exist?('/sbin/status') # Fix for Docker, in 7 and 8 images /sbin/status doesn't exists and Upstart provider doesn't work + end + + action :create do + # from base + create_system_user + stop_system_service + create_config + configure_apparmor + initialize_database + end + + action :start do + template "/usr/sbin/#{mysql_name}-wait-ready" do + source 'upstart/mysqld-wait-ready.erb' + owner 'root' + group 'root' + mode '0755' + variables(socket_file: socket_file) + cookbook 'mysql' + action :create + end + + template "/etc/init/#{mysql_name}.conf" do + source 'upstart/mysqld.erb' + owner 'root' + group 'root' + mode '0644' + variables( + defaults_file: defaults_file, + mysql_name: mysql_name, + run_group: run_group, + run_user: run_user, + socket_dir: socket_dir + ) + cookbook 'mysql' + action :create + end + + service mysql_name do + provider Chef::Provider::Service::Upstart + supports status: true + action [:start] + end + end + + action :stop do + service mysql_name do + provider Chef::Provider::Service::Upstart + supports restart: true, status: true + action [:stop] + end + end + + action :restart do + # With Upstart, restarting the service doesn't behave "as expected". + # We want the post-start stanzas, which wait until the + # service is available before returning + # + # http://upstart.ubuntu.com/cookbook/#restart + service mysql_name do + provider Chef::Provider::Service::Upstart + action [:stop, :start] + end + end + + action :reload do + # With Upstart, reload just sends a HUP signal to the process. + # As far as I can tell, this doesn't work the way it's + # supposed to, so we need to actually restart the service. + service mysql_name do + provider Chef::Provider::Service::Upstart + action [:stop, :start] + end + end + + declare_action_class.class_eval do + def stop_system_service + service system_service_name do + provider Chef::Provider::Service::Upstart + supports status: true + action [:stop, :disable] + end + end + + def delete_stop_service + service mysql_name do + provider Chef::Provider::Service::Upstart + action [:disable, :stop] + only_if { ::File.exist?("#{etc_dir}/init/#{mysql_name}") } + end + end + end + end +end diff --git a/cookbooks/mysql/libraries/provider_mysql_client.rb b/cookbooks/mysql/libraries/provider_mysql_client.rb deleted file mode 100644 index c796d11..0000000 --- a/cookbooks/mysql/libraries/provider_mysql_client.rb +++ /dev/null @@ -1,39 +0,0 @@ -require 'chef/provider/lwrp_base' -require_relative 'helpers' - -class Chef - class Provider - class MysqlClient < Chef::Provider::LWRPBase - include MysqlCookbook::Helpers - provides :mysql_client if defined?(provides) - - use_inline_resources if defined?(use_inline_resources) - - def whyrun_supported? - true - end - - action :create do - # From helpers.rb - configure_package_repositories - - client_package_name.each do |p| - package "#{new_resource.name} :create #{p}" do - package_name p - version new_resource.version if node['platform'] == 'smartos' - version new_resource.package_version - action :install - end - end - end - - action :delete do - parsed_package_name.each do |p| - package "#{new_resource.name} :delete #{p}" do - action :remove - end - end - end - end - end -end diff --git a/cookbooks/mysql/libraries/provider_mysql_config.rb b/cookbooks/mysql/libraries/provider_mysql_config.rb deleted file mode 100644 index 3732c1c..0000000 --- a/cookbooks/mysql/libraries/provider_mysql_config.rb +++ /dev/null @@ -1,59 +0,0 @@ -require 'chef/provider/lwrp_base' -require_relative 'helpers' - -class Chef - class Provider - class MysqlConfig < Chef::Provider::LWRPBase - include MysqlCookbook::Helpers - provides :mysql_config if defined?(provides) - - use_inline_resources if defined?(use_inline_resources) - - def whyrun_supported? - true - end - - action :create do - group "#{new_resource.name} :create #{new_resource.group}" do - group_name new_resource.group - system true if new_resource.name == 'mysql' - action :create - end - - user "#{new_resource.name} :create #{new_resource.owner}" do - username new_resource.owner - gid new_resource.owner - system true if new_resource.name == 'mysql' - action :create - end - - directory "#{new_resource.name} :create #{include_dir}" do - path include_dir - owner new_resource.owner - group new_resource.group - mode '0750' - recursive true - action :create - end - - template "#{new_resource.name} :create #{include_dir}/#{new_resource.config_name}.cnf" do - path "#{include_dir}/#{new_resource.config_name}.cnf" - owner new_resource.owner - group new_resource.group - mode '0640' - variables(new_resource.variables) - source new_resource.source - cookbook new_resource.cookbook - action :create - end - end - - action :delete do - file "#{new_resource.name} :delete #{include_dir}/#{new_resource.config_name}.conf" do - path "#{include_dir}/#{new_resource.config_name}.conf" - action :delete - end - end - end - end -end diff --git a/cookbooks/mysql/libraries/provider_mysql_service_base.rb b/cookbooks/mysql/libraries/provider_mysql_service_base.rb deleted file mode 100644 index 5f19a45..0000000 --- a/cookbooks/mysql/libraries/provider_mysql_service_base.rb +++ /dev/null @@ -1,250 +0,0 @@ -require 'chef/provider/lwrp_base' -require_relative 'helpers' - -class Chef - class Provider - class MysqlServiceBase < Chef::Provider::LWRPBase - use_inline_resources if defined?(use_inline_resources) - - def whyrun_supported? - true - end - - # Mix in helpers from libraries/helpers.rb - include MysqlCookbook::Helpers - - # Service related methods referred to in the :create and :delete - # actions need to be implemented in the init system subclasses. - # - # create_stop_system_service - # delete_stop_service - - # All other methods are found in libraries/helpers.rb - # - # etc_dir, run_dir, log_dir, etc - - action :create do - # Yum, Apt, etc. From helpers.rb - configure_package_repositories - - # Software installation - package "#{new_resource.name} :create #{server_package_name}" do - package_name server_package_name - version parsed_version if node['platform'] == 'smartos' - version new_resource.package_version - action new_resource.package_action - end - - create_stop_system_service - - # Apparmor - configure_apparmor - - # System users - group "#{new_resource.name} :create mysql" do - group_name 'mysql' - action :create - end - - user "#{new_resource.name} :create mysql" do - username 'mysql' - gid 'mysql' - action :create - end - - # Yak shaving secion. Account for random errata. - # - # Turns out that mysqld is hard coded to try and read - # /etc/mysql/my.cnf, and its presence causes problems when - # setting up multiple services. - file "#{new_resource.name} :create #{prefix_dir}/etc/mysql/my.cnf" do - path "#{prefix_dir}/etc/mysql/my.cnf" - action :delete - end - - file "#{new_resource.name} :create #{prefix_dir}/etc/my.cnf" do - path "#{prefix_dir}/etc/my.cnf" - action :delete - end - - # mysql_install_db is broken on 5.6.13 - link "#{new_resource.name} :create #{prefix_dir}/usr/share/my-default.cnf" do - target_file "#{prefix_dir}/usr/share/my-default.cnf" - to "#{etc_dir}/my.cnf" - action :create - end - - # Support directories - directory "#{new_resource.name} :create #{etc_dir}" do - path etc_dir - owner new_resource.run_user - group new_resource.run_group - mode '0750' - recursive true - action :create - end - - directory "#{new_resource.name} :create #{include_dir}" do - path include_dir - owner new_resource.run_user - group new_resource.run_group - mode '0750' - recursive true - action :create - end - - directory "#{new_resource.name} :create #{run_dir}" do - path run_dir - owner new_resource.run_user - group new_resource.run_group - mode '0755' - recursive true - action :create - end - - directory "#{new_resource.name} :create #{log_dir}" do - path log_dir - owner new_resource.run_user - group new_resource.run_group - mode '0750' - recursive true - action :create - end - - directory "#{new_resource.name} :create #{parsed_data_dir}" do - path parsed_data_dir - owner new_resource.run_user - group new_resource.run_group - mode '0750' - recursive true - action :create - end - - # Main configuration file - template "#{new_resource.name} :create #{etc_dir}/my.cnf" do - path "#{etc_dir}/my.cnf" - source 'my.cnf.erb' - cookbook 'mysql' - owner new_resource.run_user - group new_resource.run_group - mode '0600' - variables( - config: new_resource, - error_log: error_log, - include_dir: include_dir, - lc_messages_dir: lc_messages_dir, - pid_file: pid_file, - socket_file: socket_file, - tmp_dir: tmp_dir, - data_dir: parsed_data_dir - ) - action :create - end - - # initialize database and create initial records - bash "#{new_resource.name} :create initial records" do - code init_records_script - returns [0, 1, 2] # facepalm - not_if "/usr/bin/test -f #{parsed_data_dir}/mysql/user.frm" - action :run - end - end - - action :delete do - # Stop the service before removing support directories - delete_stop_service - - directory "#{new_resource.name} :delete #{etc_dir}" do - path etc_dir - recursive true - action :delete - end - - directory "#{new_resource.name} :delete #{run_dir}" do - path run_dir - recursive true - action :delete - end - - directory "#{new_resource.name} :delete #{log_dir}" do - path log_dir - recursive true - action :delete - end - end - - # - # Platform specific bits - # - def configure_apparmor - # Do not add these resource if inside a container - # Only valid on Ubuntu - - unless ::File.exist?('/.dockerenv') || ::File.exist?('/.dockerinit') - if node['platform'] == 'ubuntu' - # Apparmor - package "#{new_resource.name} :create apparmor" do - package_name 'apparmor' - action :install - end - - directory "#{new_resource.name} :create /etc/apparmor.d/local/mysql" do - path '/etc/apparmor.d/local/mysql' - owner 'root' - group 'root' - mode '0755' - recursive true - action :create - end - - template "#{new_resource.name} :create /etc/apparmor.d/local/usr.sbin.mysqld" do - path '/etc/apparmor.d/local/usr.sbin.mysqld' - cookbook 'mysql' - source 'apparmor/usr.sbin.mysqld-local.erb' - owner 'root' - group 'root' - mode '0644' - action :create - notifies :restart, "service[#{new_resource.name} :create apparmor]", :immediately - end - - template "#{new_resource.name} :create /etc/apparmor.d/usr.sbin.mysqld" do - path '/etc/apparmor.d/usr.sbin.mysqld' - cookbook 'mysql' - source 'apparmor/usr.sbin.mysqld.erb' - owner 'root' - group 'root' - mode '0644' - action :create - notifies :restart, "service[#{new_resource.name} :create apparmor]", :immediately - end - - template "#{new_resource.name} :create /etc/apparmor.d/local/mysql/#{new_resource.instance}" do - path "/etc/apparmor.d/local/mysql/#{new_resource.instance}" - cookbook 'mysql' - source 'apparmor/usr.sbin.mysqld-instance.erb' - owner 'root' - group 'root' - mode '0644' - variables( - data_dir: parsed_data_dir, - mysql_name: mysql_name, - log_dir: log_dir, - run_dir: run_dir, - pid_file: pid_file, - socket_file: socket_file - ) - action :create - notifies :restart, "service[#{new_resource.name} :create apparmor]", :immediately - end - - service "#{new_resource.name} :create apparmor" do - service_name 'apparmor' - action :nothing - end - end - end - end - end - end -end diff --git a/cookbooks/mysql/libraries/provider_mysql_service_smf.rb b/cookbooks/mysql/libraries/provider_mysql_service_smf.rb deleted file mode 100644 index cc208c1..0000000 --- a/cookbooks/mysql/libraries/provider_mysql_service_smf.rb +++ /dev/null @@ -1,91 +0,0 @@ -class Chef - class Provider - class MysqlServiceSmf < Chef::Provider::MysqlServiceBase - # FIXME: we should have a service_helper to determine if the platform supports SMF similarly - # to how we handle systemd on linux - if defined?(provides) # foodcritic ~FC023 - provides :mysql_service, os: %w(solaris2 omnios smartos openindiana opensolaris nexentacore) do - File.exist?('/usr/sbin/svccfg') - end - end - - action :start do - method_script_path = "/lib/svc/method/#{mysql_name}" if node['platform'] == 'omnios' - method_script_path = "/opt/local/lib/svc/method/#{mysql_name}" if node['platform'] == 'smartos' - - template "#{new_resource.name} :start #{method_script_path}" do - path method_script_path - cookbook 'mysql' - source 'smf/svc.method.mysqld.erb' - owner 'root' - group 'root' - mode '0555' - variables( - base_dir: base_dir, - data_dir: parsed_data_dir, - defaults_file: defaults_file, - error_log: error_log, - mysql_name: mysql_name, - mysqld_bin: mysqld_bin, - pid_file: pid_file - ) - action :create - end - - smf "#{new_resource.name} :start #{mysql_name}" do - name mysql_name - user new_resource.run_user - group new_resource.run_group - start_command "#{method_script_path} start" - end - - service "#{new_resource.name} :start #{mysql_name}" do - service_name mysql_name - provider Chef::Provider::Service::Solaris - supports restart: true - action [:enable] - end - end - - action :stop do - service "#{new_resource.name} :stop #{mysql_name}" do - service_name mysql_name - provider Chef::Provider::Service::Solaris - supports restart: true - action :stop - end - end - - action :restart do - service "#{new_resource.name} :restart #{mysql_name}" do - service_name mysql_name - provider Chef::Provider::Service::Solaris - supports restart: true - action :restart - end - end - - action :reload do - service "#{new_resource.name} :reload #{mysql_name}" do - provider Chef::Provider::Service::Solaris - service_name mysql_name - supports reload: true - action :reload - end - end - - def create_stop_system_service - # nothing to do here - end - - def delete_stop_service - service "#{new_resource.name} :delete #{mysql_name}" do - service_name mysql_name - provider Chef::Provider::Service::Solaris - supports restart: true - action :stop - end - end - end - end -end diff --git a/cookbooks/mysql/libraries/provider_mysql_service_systemd.rb b/cookbooks/mysql/libraries/provider_mysql_service_systemd.rb deleted file mode 100644 index 7ef415b..0000000 --- a/cookbooks/mysql/libraries/provider_mysql_service_systemd.rb +++ /dev/null @@ -1,135 +0,0 @@ -require_relative 'provider_mysql_service_base' - -class Chef - class Provider - class MysqlServiceSystemd < Chef::Provider::MysqlServiceBase - if defined?(provides) # foodcritic ~FC023 - provides :mysql_service, os: 'linux' do - Chef::Platform::ServiceHelpers.service_resource_providers.include?(:systemd) - end - end - - action :start do - # Needed for Debian / Ubuntu - directory '/usr/libexec' do - owner 'root' - group 'root' - mode '0755' - action :create - end - - # this script is called by the main systemd unit file, and - # spins around until the service is actually up and running. - template "#{new_resource.name} :start /usr/libexec/#{mysql_name}-wait-ready" do - path "/usr/libexec/#{mysql_name}-wait-ready" - source 'systemd/mysqld-wait-ready.erb' - owner 'root' - group 'root' - mode '0755' - variables(socket_file: socket_file) - cookbook 'mysql' - action :create - end - - # this is the main systemd unit file - template "#{new_resource.name} :start /lib/systemd/system/#{mysql_name}.service" do - path "/lib/systemd/system/#{mysql_name}.service" - source 'systemd/mysqld.service.erb' - owner 'root' - group 'root' - mode '0644' - variables( - config: new_resource, - etc_dir: etc_dir, - base_dir: base_dir, - mysqld_bin: mysqld_bin - ) - cookbook 'mysql' - notifies :run, "execute[#{new_resource.name} :start systemctl daemon-reload]", :immediately - action :create - end - - # avoid 'Unit file changed on disk' warning - execute "#{new_resource.name} :start systemctl daemon-reload" do - command '/bin/systemctl daemon-reload' - action :nothing - end - - # tmpfiles.d config so the service survives reboot - template "#{new_resource.name} :start /usr/lib/tmpfiles.d/#{mysql_name}.conf" do - path "/usr/lib/tmpfiles.d/#{mysql_name}.conf" - source 'tmpfiles.d.conf.erb' - owner 'root' - group 'root' - mode '0644' - variables( - run_dir: run_dir, - run_user: new_resource.run_user, - run_group: new_resource.run_group - ) - cookbook 'mysql' - action :create - end - - # service management resource - service "#{new_resource.name} :start #{mysql_name}" do - service_name mysql_name - provider Chef::Provider::Service::Systemd - supports restart: true, status: true - action [:enable, :start] - end - end - - action :stop do - # service management resource - service "#{new_resource.name} :stop #{mysql_name}" do - service_name mysql_name - provider Chef::Provider::Service::Systemd - supports status: true - action [:disable, :stop] - only_if { ::File.exist?("/usr/lib/systemd/system/#{mysql_name}.service") } - end - end - - action :restart do - # service management resource - service "#{new_resource.name} :restart #{mysql_name}" do - service_name mysql_name - provider Chef::Provider::Service::Systemd - supports restart: true - action :restart - end - end - - action :reload do - # service management resource - service "#{new_resource.name} :reload #{mysql_name}" do - service_name mysql_name - provider Chef::Provider::Service::Systemd - action :reload - end - end - - def create_stop_system_service - # service management resource - service "#{new_resource.name} :create mysql" do - service_name system_service_name - provider Chef::Provider::Service::Systemd - supports status: true - action [:stop, :disable] - end - end - - def delete_stop_service - # service management resource - service "#{new_resource.name} :delete #{mysql_name}" do - service_name mysql_name - provider Chef::Provider::Service::Systemd - supports status: true - action [:disable, :stop] - only_if { ::File.exist?("/usr/lib/systemd/system/#{mysql_name}.service") } - end - end - end - end -end diff --git a/cookbooks/mysql/libraries/provider_mysql_service_sysvinit.rb b/cookbooks/mysql/libraries/provider_mysql_service_sysvinit.rb deleted file mode 100644 index b3f2259..0000000 --- a/cookbooks/mysql/libraries/provider_mysql_service_sysvinit.rb +++ /dev/null @@ -1,89 +0,0 @@ -require_relative 'provider_mysql_service_base' - -class Chef - class Provider - class MysqlServiceSysvinit < Chef::Provider::MysqlServiceBase - provides :mysql_service, os: '!windows' if defined?(provides) - - action :start do - template "#{new_resource.name} :start /etc/init.d/#{mysql_name}" do - path "/etc/init.d/#{mysql_name}" - source 'sysvinit/mysqld.erb' - owner 'root' - group 'root' - mode '0755' - variables( - config: new_resource, - defaults_file: defaults_file, - error_log: error_log, - mysql_name: mysql_name, - mysqladmin_bin: mysqladmin_bin, - mysqld_safe_bin: mysqld_safe_bin, - pid_file: pid_file, - scl_name: scl_name - ) - cookbook 'mysql' - action :create - end - - service "#{new_resource.name} :start #{mysql_name}" do - service_name mysql_name - provider Chef::Provider::Service::Init::Redhat if node['platform_family'] == 'redhat' - provider Chef::Provider::Service::Init::Insserv if node['platform_family'] == 'debian' - supports restart: true, status: true - action [:enable, :start] - end - end - - action :stop do - service "#{new_resource.name} :stop #{mysql_name}" do - service_name mysql_name - provider Chef::Provider::Service::Init::Redhat if node['platform_family'] == 'redhat' - provider Chef::Provider::Service::Init::Insserv if node['platform_family'] == 'debian' - supports restart: true, status: true - action [:stop] - end - end - - action :restart do - service "#{new_resource.name} :restart #{mysql_name}" do - service_name mysql_name - provider Chef::Provider::Service::Init::Redhat if node['platform_family'] == 'redhat' - provider Chef::Provider::Service::Init::Insserv if node['platform_family'] == 'debian' - supports restart: true - action :restart - end - end - - action :reload do - service "#{new_resource.name} :reload #{mysql_name}" do - service_name mysql_name - provider Chef::Provider::Service::Init::Redhat if node['platform_family'] == 'redhat' - provider Chef::Provider::Service::Init::Insserv if node['platform_family'] == 'debian' - action :reload - end - end - - def create_stop_system_service - service "#{new_resource.name} :create #{system_service_name}" do - service_name system_service_name - provider Chef::Provider::Service::Init::Redhat if node['platform_family'] == 'redhat' - provider Chef::Provider::Service::Init::Insserv if node['platform_family'] == 'debian' - supports status: true - action [:stop, :disable] - end - end - - def delete_stop_service - service "#{new_resource.name} :delete #{mysql_name}" do - service_name mysql_name - provider Chef::Provider::Service::Init::Redhat if node['platform_family'] == 'redhat' - provider Chef::Provider::Service::Init::Insserv if node['platform_family'] == 'debian' - supports status: true - action [:disable, :stop] - only_if { ::File.exist?("#{etc_dir}/init.d/#{mysql_name}") } - end - end - end - end -end diff --git a/cookbooks/mysql/libraries/provider_mysql_service_upstart.rb b/cookbooks/mysql/libraries/provider_mysql_service_upstart.rb deleted file mode 100644 index 3a328b6..0000000 --- a/cookbooks/mysql/libraries/provider_mysql_service_upstart.rb +++ /dev/null @@ -1,114 +0,0 @@ -require_relative 'provider_mysql_service_base' - -class Chef - class Provider - class MysqlServiceUpstart < Chef::Provider::MysqlServiceBase - if defined?(provides) # foodcritic ~FC023 - provides :mysql_service, os: 'linux' do - Chef::Platform::ServiceHelpers.service_resource_providers.include?(:upstart) && - !Chef::Platform::ServiceHelpers.service_resource_providers.include?(:redhat) - end - end - - action :start do - template "#{new_resource.name} :start /usr/sbin/#{mysql_name}-wait-ready" do - path "/usr/sbin/#{mysql_name}-wait-ready" - source 'upstart/mysqld-wait-ready.erb' - owner 'root' - group 'root' - mode '0755' - variables(socket_file: socket_file) - cookbook 'mysql' - action :create - end - - template "#{new_resource.name} :start /etc/init/#{mysql_name}.conf" do - path "/etc/init/#{mysql_name}.conf" - source 'upstart/mysqld.erb' - owner 'root' - group 'root' - mode '0644' - variables( - defaults_file: defaults_file, - mysql_name: mysql_name, - run_group: new_resource.run_group, - run_user: new_resource.run_user, - socket_dir: socket_dir - ) - cookbook 'mysql' - action :create - end - - service "#{new_resource.name} :start #{mysql_name}" do - service_name mysql_name - provider Chef::Provider::Service::Upstart - supports status: true - action [:start] - end - end - - action :stop do - service "#{new_resource.name} :stop #{mysql_name}" do - service_name mysql_name - provider Chef::Provider::Service::Upstart - supports restart: true, status: true - action [:stop] - end - end - - action :restart do - # With Upstart, restarting the service doesn't behave "as expected". - # We want the post-start stanzas, which wait until the - # service is available before returning - # - # http://upstart.ubuntu.com/cookbook/#restart - service "#{new_resource.name} :restart stop #{mysql_name}" do - service_name mysql_name - provider Chef::Provider::Service::Upstart - action :stop - end - - service "#{new_resource.name} :restart start #{mysql_name}" do - service_name mysql_name - provider Chef::Provider::Service::Upstart - action :start - end - end - - action :reload do - # With Upstart, reload just sends a HUP signal to the process. - # As far as I can tell, this doesn't work the way it's - # supposed to, so we need to actually restart the service. - service "#{new_resource.name} :reload stop #{mysql_name}" do - service_name mysql_name - provider Chef::Provider::Service::Upstart - action :stop - end - - service "#{new_resource.name} :reload start #{mysql_name}" do - service_name mysql_name - provider Chef::Provider::Service::Upstart - action :start - end - end - - def create_stop_system_service - service "#{new_resource.name} :create #{system_service_name}" do - service_name system_service_name - provider Chef::Provider::Service::Upstart - supports status: true - action [:stop, :disable] - end - end - - def delete_stop_service - service "#{new_resource.name} :delete #{mysql_name}" do - service_name mysql_name - provider Chef::Provider::Service::Upstart - action [:disable, :stop] - only_if { ::File.exist?("#{etc_dir}/init/#{mysql_name}") } - end - end - end - end -end diff --git a/cookbooks/mysql/libraries/provider_priority_linux.rb b/cookbooks/mysql/libraries/provider_priority_linux.rb deleted file mode 100644 index cea5b11..0000000 --- a/cookbooks/mysql/libraries/provider_priority_linux.rb +++ /dev/null @@ -1,45 +0,0 @@ - -begin - require 'chef/platform/provider_priority_map' -rescue LoadError # rubocop: disable Lint/HandleExceptions -end - -require_relative 'provider_mysql_service_smf' -require_relative 'provider_mysql_service_systemd' -require_relative 'provider_mysql_service_sysvinit' -require_relative 'provider_mysql_service_upstart' -require_relative 'provider_mysql_config' -require_relative 'provider_mysql_client' - -if defined? Chef::Platform::ProviderPriorityMap - Chef::Platform::ProviderPriorityMap.instance.priority( - :mysql_service, - [Chef::Provider::MysqlServiceSystemd, Chef::Provider::MysqlServiceUpstart, Chef::Provider::MysqlServiceSysvinit], - os: 'linux' - ) -else - # provider mappings for Chef 11 - - # systemd service - Chef::Platform.set platform: :fedora, version: '>= 19', resource: :mysql_service, provider: Chef::Provider::MysqlServiceSystemd - Chef::Platform.set platform: :redhat, version: '>= 7.0', resource: :mysql_service, provider: Chef::Provider::MysqlServiceSystemd - Chef::Platform.set platform: :centos, version: '>= 7.0', resource: :mysql_service, provider: Chef::Provider::MysqlServiceSystemd - Chef::Platform.set platform: :scientific, version: '>= 7.0', resource: :mysql_service, provider: Chef::Provider::MysqlServiceSystemd - Chef::Platform.set platform: :oracle, version: '>= 7.0', resource: :mysql_service, provider: Chef::Provider::MysqlServiceSystemd - - # smf service - Chef::Platform.set platform: :omnios, resource: :mysql_service, provider: Chef::Provider::MysqlServiceSmf - Chef::Platform.set platform: :smartos, resource: :mysql_service, provider: Chef::Provider::MysqlServiceSmf - - # upstart service - Chef::Platform.set platform: :ubuntu, resource: :mysql_service, provider: Chef::Provider::MysqlServiceUpstart - - # default service - Chef::Platform.set resource: :mysql_service, provider: Chef::Provider::MysqlServiceSysvinit - - # config - Chef::Platform.set resource: :mysql_config, provider: Chef::Provider::MysqlConfig - - # client - Chef::Platform.set resource: :mysql_client, provider: Chef::Provider::MysqlClient -end diff --git a/cookbooks/mysql/libraries/resource_mysql_client.rb b/cookbooks/mysql/libraries/resource_mysql_client.rb deleted file mode 100644 index 8585dbe..0000000 --- a/cookbooks/mysql/libraries/resource_mysql_client.rb +++ /dev/null @@ -1,18 +0,0 @@ -require 'chef/resource/lwrp_base' - -class Chef - class Resource - class MysqlClient < Chef::Resource::LWRPBase - provides :mysql_client - - self.resource_name = :mysql_client - actions :create, :delete - default_action :create - - attribute :client_name, kind_of: String, name_attribute: true, required: true - attribute :package_name, kind_of: Array, default: nil - attribute :package_version, kind_of: String, default: nil - attribute :version, kind_of: String, default: nil # mysql_version - end - end -end diff --git a/cookbooks/mysql/libraries/resource_mysql_config.rb b/cookbooks/mysql/libraries/resource_mysql_config.rb deleted file mode 100644 index a8767ce..0000000 --- a/cookbooks/mysql/libraries/resource_mysql_config.rb +++ /dev/null @@ -1,22 +0,0 @@ -require 'chef/resource/lwrp_base' - -class Chef - class Resource - class MysqlConfig < Chef::Resource::LWRPBase - provides :mysql_config - - self.resource_name = :mysql_config - actions :create, :delete - default_action :create - - attribute :config_name, kind_of: String, name_attribute: true, required: true - attribute :cookbook, kind_of: String, default: nil - attribute :group, kind_of: String, default: 'mysql' - attribute :instance, kind_of: String, default: 'default' - attribute :owner, kind_of: String, default: 'mysql' - attribute :source, kind_of: String, default: nil - attribute :variables, kind_of: [Hash], default: nil - attribute :version, kind_of: String, default: nil - end - end -end diff --git a/cookbooks/mysql/libraries/resource_mysql_service.rb b/cookbooks/mysql/libraries/resource_mysql_service.rb deleted file mode 100644 index 8d4f5d3..0000000 --- a/cookbooks/mysql/libraries/resource_mysql_service.rb +++ /dev/null @@ -1,31 +0,0 @@ -require 'chef/resource/lwrp_base' - -class Chef - class Resource - class MysqlService < Chef::Resource::LWRPBase - provides :mysql_service - - self.resource_name = :mysql_service - actions :create, :delete, :start, :stop, :restart, :reload - default_action :create - - attribute :charset, kind_of: String, default: 'utf8' - attribute :data_dir, kind_of: String, default: nil - attribute :initial_root_password, kind_of: String, default: 'ilikerandompasswords' - attribute :instance, kind_of: String, name_attribute: true - attribute :package_action, kind_of: Symbol, default: :install - attribute :package_name, kind_of: String, default: nil - attribute :package_version, kind_of: String, default: nil - attribute :bind_address, kind_of: String, default: nil - attribute :port, kind_of: [String, Integer], default: '3306' - attribute :run_group, kind_of: String, default: 'mysql' - attribute :run_user, kind_of: String, default: 'mysql' - attribute :socket, kind_of: String, default: nil - attribute :mysqld_options, kind_of: Hash, default: {} - attribute :version, kind_of: String, default: nil - attribute :error_log, kind_of: String, default: nil - attribute :tmp_dir, kind_of: String, default: nil - attribute :pid_file, kind_of: String, default: nil - end - end -end diff --git a/cookbooks/mysql/metadata.json b/cookbooks/mysql/metadata.json index 54c8e71..a3a60ab 100644 --- a/cookbooks/mysql/metadata.json +++ b/cookbooks/mysql/metadata.json @@ -1 +1 @@ -{"name":"mysql","version":"6.1.3","description":"Provides mysql_service, mysql_config, and mysql_client resources","long_description":"# MySQL Cookbook\n\n[![Build Status](https://travis-ci.org/chef-cookbooks/mysql.svg?branch=master)](https://travis-ci.org/chef-cookbooks/mysql) [![Cookbook Version](https://img.shields.io/cookbook/v/mysql.svg)](https://supermarket.chef.io/cookbooks/mysql)\n\nThe Mysql Cookbook is a library cookbook that provides resource primitives (LWRPs) for use in recipes. It is designed to be a reference example for creating highly reusable cross-platform cookbooks.\n\n## Scope\n\nThis cookbook is concerned with the \"MySQL Community Server\", particularly those shipped with F/OSS Unix and Linux distributions. It does not address forks or value-added repackaged MySQL distributions like Drizzle, MariaDB, or Percona.\n\n## Requirements\n\n- Chef 11 or higher\n- Ruby 1.9 or higher (preferably from the Chef full-stack installer)\n- Network accessible package repositories\n- 'recipe[selinux::disabled]' on RHEL platforms\n\n## Platform Support\n\nThe following platforms have been tested with Test Kitchen:\n\n```\n|----------------+-----+-----+-----+-----+-----|\n| | 5.0 | 5.1 | 5.5 | 5.6 | 5.7 |\n|----------------+-----+-----+-----+-----+-----|\n| debian-7 | | | X | | |\n|----------------+-----+-----+-----+-----+-----|\n| ubuntu-12.04 | | | X | | |\n|----------------+-----+-----+-----+-----+-----|\n| ubuntu-14.04 | | | X | X | |\n|----------------+-----+-----+-----+-----+-----|\n| ubuntu-15.04 | | | | X | |\n|----------------+-----+-----+-----+-----+-----|\n| centos-5 | X | X | X | X | X |\n|----------------+-----+-----+-----+-----+-----|\n| centos-6 | | X | X | X | X |\n|----------------+-----+-----+-----+-----+-----|\n| centos-7 | | | X | X | X |\n|----------------+-----+-----+-----+-----+-----|\n| amazon | | | X | X | X |\n|----------------+-----+-----+-----+-----+-----|\n| fedora-22 | | | X | X | X |\n|----------------+-----+-----+-----+-----+-----|\n| fedora-23 | | | X | X | X |\n|----------------+-----+-----+-----+-----+-----|\n```\n\n## Cookbook Dependencies\n\n- yum-mysql-community\n- smf\n\n## Usage\n\nPlace a dependency on the mysql cookbook in your cookbook's metadata.rb\n\n```ruby\ndepends 'mysql', '~> 6.0'\n```\n\nThen, in a recipe:\n\n```ruby\nmysql_service 'foo' do\n port '3306'\n version '5.5'\n initial_root_password 'change me'\n action [:create, :start]\nend\n```\n\nThe service name on the OS is `mysql-foo`. You can manually start and stop it with `service mysql-foo start` and `service mysql-foo stop`.\n\nThe configuration file is at `/etc/mysql-foo/my.cnf`. It contains the minimum options to get the service running. It looks like this.\n\n```\n# Chef generated my.cnf for instance mysql-foo\n\n[client]\ndefault-character-set = utf8\nport = 3306\nsocket = /var/run/mysql-foo/mysqld.sock\n\n[mysql]\ndefault-character-set = utf8\n\n[mysqld]\nuser = mysql\npid-file = /var/run/mysql-foo/mysqld.pid\nsocket = /var/run/mysql-foo/mysqld.sock\nport = 3306\ndatadir = /var/lib/mysql-foo\ntmpdir = /tmp\nlog-error = /var/log/mysql-foo/error.log\n!includedir /etc/mysql-foo/conf.d\n\n[mysqld_safe]\nsocket = /var/run/mysql-foo/mysqld.sock\n```\n\nYou can put extra configuration into the conf.d directory by using the `mysql_config` resource, like this:\n\n```ruby\nmysql_service 'foo' do\n port '3306'\n version '5.5'\n initial_root_password 'change me'\n action [:create, :start]\nend\n\nmysql_config 'foo' do\n source 'my_extra_settings.erb'\n notifies :restart, 'mysql_service[foo]'\n action :create\nend\n```\n\nYou are responsible for providing `my_extra_settings.erb` in your own cookbook's templates folder.\n\n## Connecting with the mysql CLI command\n\nLogging into the machine and typing `mysql` with no extra arguments will fail. You need to explicitly connect over the socket with `mysql -S /var/run/mysql-foo/mysqld.sock`, or over the network with `mysql -h 127.0.0.1`\n\n## Upgrading from older version of the mysql cookbook\n\n- It is strongly recommended that you rebuild the machine from scratch. This is easy if you have your `data_dir` on a dedicated mount point. If you _must_ upgrade in-place, follow the instructions below.\n- The 6.x series supports multiple service instances on a single machine. It dynamically names the support directories and service names. `/etc/mysql becomes /etc/mysql-instance_name`. Other support directories in `/var` `/run` etc work the same way. Make sure to specify the `data_dir` property on the `mysql_service` resource to point to the old `/var/lib/mysql` directory.\n\n## Resources Overview\n\n### mysql_service\n\nThe `mysql_service` resource manages the basic plumbing needed to get a MySQL server instance running with minimal configuration.\n\nThe `:create` action handles package installation, support directories, socket files, and other operating system level concerns. The internal configuration file contains just enough to get the service up and running, then loads extra configuration from a conf.d directory. Further configurations are managed with the `mysql_config` resource.\n\n- If the `data_dir` is empty, a database will be initialized, and a\n- root user will be set up with `initial_root_password`. If this\n- directory already contains database files, no action will be taken.\n\nThe `:start` action starts the service on the machine using the appropriate provider for the platform. The `:start` action should be omitted when used in recipes designed to build containers.\n\n#### Example\n\n```ruby\nmysql_service 'default' do\n version '5.7'\n bind_address '0.0.0.0'\n port '3306'\n data_dir '/data'\n initial_root_password 'Ch4ng3me'\n action [:create, :start]\nend\n```\n\nPlease note that when using `notifies` or `subscribes`, the resource to reference is `mysql_service[name]`, not `service[mysql]`.\n\n#### Parameters\n\n- `charset` - specifies the default character set. Defaults to `utf8`.\n- `data_dir` - determines where the actual data files are kept on the machine. This is useful when mounting external storage. When omitted, it will default to the platform's native location.\n- `error_log` - Tunable location of the error_log\n- `initial_root_password` - allows the user to specify the initial root password for mysql when initializing new databases. This can be set explicitly in a recipe, driven from a node attribute, or from data_bags. When omitted, it defaults to `ilikerandompasswords`. Please be sure to change it.\n- `instance` - A string to identify the MySQL service. By convention, to allow for multiple instances of the `mysql_service`, directories and files on disk are named `mysql-`. Defaults to the resource name.\n- `package_action` - Defaults to `:install`.\n- `package_name` - Defaults to a value looked up in an internal map.\n- `package_version` - Specific version of the package to install,passed onto the underlying package manager. Defaults to `nil`.\n- `bind_address` - determines the listen IP address for the mysqld service. When omitted, it will be determined by MySQL. If the address is \"regular\" IPv4/IPv6address (e.g 127.0.0.1 or ::1), the server accepts TCP/IP connections only for that particular address. If the address is \"0.0.0.0\" (IPv4) or \"::\" (IPv6), the server accepts TCP/IP connections on all IPv4 or IPv6 interfaces.\n- `mysqld_options` - A key value hash of options to be rendered into the main my.cnf. WARNING - It is highly recommended that you use the `mysql_config` resource instead of sending extra config into a `mysql_service` resource. This will allow you to set up notifications and subscriptions between the service and its configuration. That being said, this can be useful for adding extra options needed for database initialization at first run.\n- `port` - determines the listen port for the mysqld service. When omitted, it will default to '3306'.\n- `run_group` - The name of the system group the `mysql_service` should run as. Defaults to 'mysql'.\n- `run_user` - The name of the system user the `mysql_service` should run as. Defaults to 'mysql'.\n- `pid_file` - Tunable location of the pid file.\n- `socket` - determines where to write the socket file for the `mysql_service` instance. Useful when configuring clients on the same machine to talk over socket and skip the networking stack. Defaults to a calculated value based on platform and instance name.\n- `tmp_dir` - Tunable location of the tmp_dir\n- `version` - allows the user to select from the versions available for the platform, where applicable. When omitted, it will install the default MySQL version for the target platform. Available version numbers are `5.0`, `5.1`, `5.5`, `5.6`, and `5.7`, depending on platform.\n\n#### Actions\n\n- `:create` - Configures everything but the underlying operating system service.\n- `:delete` - Removes everything but the package and data_dir.\n- `:start` - Starts the underlying operating system service\n- `:stop`- Stops the underlying operating system service\n- `:restart` - Restarts the underlying operating system service\n- `:reload` - Reloads the underlying operating system service\n\n#### Providers\n\nChef selects the appropriate provider based on platform and version, but you can specify one if your platform support it.\n\n```ruby\nmysql_service[instance-1] do\n port '1234'\n data_dir '/mnt/lottadisk'\n provider Chef::Provider::MysqlServiceSysvinit\n action [:create, :start]\nend\n```\n\n- `Chef::Provider::MysqlServiceBase` - Configures everything needed to run a MySQL service except the platform service facility. This provider should never be used directly. The `:start`, `:stop`, `:restart`, and `:reload` actions are stubs meant to be overridden by the providers below.\n- `Chef::Provider::MysqlServiceSmf` - Starts a `mysql_service` using the Service Management Facility, used by Solaris and Illumos. Manages the FMRI and method script.\n- `Chef::Provider::MysqlServiceSystemd` - Starts a `mysql_service` using SystemD. Manages the unit file and activation state\n- `Chef::Provider::MysqlServiceSysvinit` - Starts a `mysql_service` using SysVinit. Manages the init script and status.\n- `Chef::Provider::MysqlServiceUpstart` - Starts a `mysql_service` using Upstart. Manages job definitions and status.\n\n### mysql_config\n\nThe `mysql_config` resource is a wrapper around the core Chef `template` resource. Instead of a `path` parameter, it uses the `instance` parameter to calculate the path on the filesystem where file is rendered.\n\n#### Example\n\n```ruby\nmysql_config[default] do\n source 'site.cnf.erb'\n action :create\nend\n```\n\n#### Parameters\n\n- `config_name` - The base name of the configuration file to be rendered into the conf.d directory on disk. Defaults to the resource name.\n- `cookbook` - The name of the cookbook to look for the template source. Defaults to nil\n- `group` - System group for file ownership. Defaults to 'mysql'.\n- `instance` - Name of the `mysql_service` instance the config is meant for. Defaults to 'default'.\n- `owner` - System user for file ownership. Defaults to 'mysql'.\n- `source` - Template in cookbook to be rendered.\n- `variables` - Variables to be passed to the underlying `template` resource.\n- `version` - Version of the `mysql_service` instance the config is meant for. Used to calculate path. Only necessary when using packages with unique configuration paths, such as RHEL Software Collections or OmniOS. Defaults to 'nil'\n\n#### Actions\n\n- `:create` - Renders the template to disk at a path calculated using the instance parameter.\n- `:delete` - Deletes the file from the conf.d directory calculated using the instance parameter.\n\n#### More Examples\n\n```ruby\nmysql_service 'instance-1' do\n action [:create, :start]\nend\n\nmysql_service 'instance-2' do\n action [:create, :start]\nend\n\nmysql_config 'logging' do\n instance 'instance-1'\n source 'logging.cnf.erb'\n action :create\n notifies :restart, 'mysql_service[instance-1]'\nend\n\nmysql_config 'security settings for instance-2' do\n config_name 'security'\n instance 'instance-2'\n source 'security_stuff.cnf.erb'\n variables(:foo => 'bar')\n action :create\n notifies :restart, 'mysql_service[instance-2]'\nend\n```\n\n### mysql_client\n\nThe `mysql_client` resource manages the MySQL client binaries and development libraries.\n\nIt is an example of a \"singleton\" resource. Declaring two `mysql_client` resources on a machine usually won't yield two separate copies of the client binaries, except for platforms that support multiple versions (RHEL SCL, OmniOS).\n\n#### Example\n\n```ruby\nmysql_client 'default' do\n action :create\nend\n```\n\n#### Parameters\n\n- `package_name` - An array of packages to be installed. Defaults to a value looked up in an internal map.\n- `package_version` - Specific versions of the package to install, passed onto the underlying package manager. Defaults to `nil`.\n- `version` - Major MySQL version number of client packages. Only valid on for platforms that support multiple versions, such as RHEL via Software Collections and OmniOS.\n\n#### Actions\n\n- `:create` - Installs the client software\n- `:delete` - Removes the client software\n\n## Advanced Usage Examples\n\nThere are a number of configuration scenarios supported by the use of resource primitives in recipes. For example, you might want to run multiple MySQL services, as different users, and mount block devices that contain pre-existing databases.\n\n### Multiple Instances as Different Users\n\n```ruby\n# instance-1\nuser 'alice' do\n action :create\nend\n\ndirectory '/mnt/data/mysql/instance-1' do\n owner 'alice'\n action :create\nend\n\nmount '/mnt/data/mysql/instance-1' do\n device '/dev/sdb1'\n fstype 'ext4'\n action [:mount, :enable]\nend\n\nmysql_service 'instance-1' do\n port '3307'\n run_user 'alice'\n data_dir '/mnt/data/mysql/instance-1'\n action [:create, :start]\nend\n\nmysql_config 'site config for instance-1' do\n instance 'instance-1'\n source 'instance-1.cnf.erb'\n notifies :restart, 'mysql_service[instance-1]'\nend\n\n# instance-2\nuser 'bob' do\n action :create\nend\n\ndirectory '/mnt/data/mysql/instance-2' do\n owner 'bob'\n action :create\nend\n\nmount '/mnt/data/mysql/instance-2' do\n device '/dev/sdc1'\n fstype 'ext3'\n action [:mount, :enable]\nend\n\nmysql_service 'instance-2' do\n port '3308'\n run_user 'bob'\n data_dir '/mnt/data/mysql/instance-2'\n action [:create, :start]\nend\n\nmysql_config 'site config for instance-2' do\n instance 'instance-2'\n source 'instance-2.cnf.erb'\n notifies :restart, 'mysql_service[instance-2]'\nend\n```\n\n### Replication Testing\n\nUse multiple `mysql_service` instances to test a replication setup. This particular example serves as a smoke test in Test Kitchen because it exercises different resources and requires service restarts.\n\n\n\n## Frequently Asked Questions\n\n### How do I run this behind my firewall?\n\nOn Linux, the `mysql_service` resource uses the platform's underlying package manager to install software. For this to work behind firewalls, you'll need to either:\n\n- Configure the system yum/apt utilities to use a proxy server that\n- can reach the Internet\n- Host a package repository on a network that the machine can talk to\n\nOn the RHEL platform_family, applying the `yum::default` recipe will allow you to drive the `yum_globalconfig` resource with attributes to change the global yum proxy settings.\n\nIf hosting repository mirrors, applying one of the following recipes and adjust the settings with node attributes.\n\n- `recipe[yum-centos::default]` from the Supermarket\n\n \n\n \n\n- `recipe[yum-mysql-community::default]` from the Supermarket\n\n \n\n \n\n### The mysql command line doesn't work\n\nIf you log into the machine and type `mysql`, you may see an error like this one:\n\n`Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'`\n\nThis is because MySQL is hardcoded to read the defined default my.cnf file, typically at /etc/my.cnf, and this LWRP deletes it to prevent overlap among multiple MySQL configurations.\n\nTo connect to the socket from the command line, check the socket in the relevant my.cnf file and use something like this:\n\n`mysql -S /var/run/mysql-foo/mysqld.sock -Pwhatever`\n\nOr to connect over the network, use something like this: connect over the network..\n\n`mysql -h 127.0.0.1 -Pwhatever`\n\nThese network or socket ssettings can also be put in you $HOME/.my.cnf, if preferred.\n\n### What about MariaDB, Percona, Drizzle, WebScaleSQL, etc.\n\nMySQL forks are purposefully out of scope for this cookbook. This is mostly to reduce the testing matrix to a manageable size. Cookbooks for these technologies can easily be created by copying and adapting this cookbook. However, there will be differences.\n\nPackage repository locations, package version names, software major version numbers, supported platform matrices, and the availability of software such as XtraDB and Galera are the main reasons that creating multiple cookbooks to make sense.\n\n## Warnings\n\n## Hacking / Testing / TODO\n\nPlease refer to the HACKING.md\n\n## License & Authors\n\n- Author:: Joshua Timberman ([joshua@chef.io](mailto:joshua@chef.io))\n- Author:: AJ Christensen ([aj@chef.io](mailto:aj@chef.io))\n- Author:: Seth Chisamore ([schisamo@chef.io](mailto:schisamo@chef.io))\n- Author:: Brian Bianco ([brian.bianco@gmail.com](mailto:brian.bianco@gmail.com))\n- Author:: Jesse Howarth ([him@jessehowarth.com](mailto:him@jessehowarth.com))\n- Author:: Andrew Crump ([andrew@kotirisoftware.com](mailto:andrew@kotirisoftware.com))\n- Author:: Christoph Hartmann ([chris@lollyrock.com](mailto:chris@lollyrock.com))\n- Author:: Sean OMeara ([sean@chef.io](mailto:sean@chef.io))\n\n```text\nCopyright:: 2009-2014 Chef Software, Inc\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n```\n","maintainer":"Chef Software, Inc.","maintainer_email":"cookbooks@chef.io","license":"Apache 2.0","platforms":{"amazon":">= 0.0.0","redhat":">= 0.0.0","centos":">= 0.0.0","scientific":">= 0.0.0","fedora":">= 0.0.0","debian":">= 0.0.0","ubuntu":">= 0.0.0","smartos":">= 0.0.0","omnios":">= 0.0.0","suse":">= 0.0.0"},"dependencies":{"yum-mysql-community":">= 0.0.0","smf":">= 0.0.0"},"recommendations":{},"suggestions":{},"conflicting":{},"providing":{},"replacing":{},"attributes":{},"groupings":{},"recipes":{}} \ No newline at end of file +{"name":"mysql","version":"8.3.0","description":"Provides mysql_service, mysql_config, and mysql_client resources","long_description":"","maintainer":"Chef Software, Inc.","maintainer_email":"cookbooks@chef.io","license":"Apache 2.0","platforms":{"amazon":">= 0.0.0","redhat":">= 0.0.0","centos":">= 0.0.0","scientific":">= 0.0.0","oracle":">= 0.0.0","fedora":">= 0.0.0","debian":">= 0.0.0","ubuntu":">= 0.0.0","suse":">= 0.0.0","opensuse":">= 0.0.0","opensuseleap":">= 0.0.0"},"dependencies":{},"recommendations":{},"suggestions":{},"conflicting":{},"providing":{},"replacing":{},"attributes":{},"groupings":{},"recipes":{},"source_url":"https://github.com/chef-cookbooks/mysql","issues_url":"https://github.com/chef-cookbooks/mysql/issues","chef_version":">= 12.1","ohai_version":{}} \ No newline at end of file diff --git a/cookbooks/mysql/templates/default/apparmor/usr.sbin.mysqld-instance.erb b/cookbooks/mysql/templates/default/apparmor/usr.sbin.mysqld-instance.erb index 430a311..130beb7 100644 --- a/cookbooks/mysql/templates/default/apparmor/usr.sbin.mysqld-instance.erb +++ b/cookbooks/mysql/templates/default/apparmor/usr.sbin.mysqld-instance.erb @@ -2,12 +2,13 @@ /etc/<%= @mysql_name %>/conf.d/ r, /etc/<%= @mysql_name %>/conf.d/* r, /etc/<%= @mysql_name %>/my.cnf r, -<%= @log_dir %>/ r, -<%= @log_dir %>/* rw, -<%= @data_dir %>/ r, -<%= @data_dir %>/** rwk, -<%= @run_dir %>/** rw, -<%= @pid_file %> rw, -<%= @socket_file %> rw, +<%= @config.log_dir %>/ r, +<%= @config.log_dir %>/* rw, +<%= @config.data_dir %>/ r, +<%= @config.data_dir %>/** rwk, +<%= @config.run_dir %>/** rw, +<%= @config.pid_file %> rw, +<%= @config.socket_file %> rw, /tmp/<%= @mysql_name %>/ r, /tmp/<%= @mysql_name %>/my.sql r, +<%= @config.tmp_dir %>/* rw, diff --git a/cookbooks/mysql/templates/default/apparmor/usr.sbin.mysqld.erb b/cookbooks/mysql/templates/default/apparmor/usr.sbin.mysqld.erb index 3e1f1b0..19ddbf5 100644 --- a/cookbooks/mysql/templates/default/apparmor/usr.sbin.mysqld.erb +++ b/cookbooks/mysql/templates/default/apparmor/usr.sbin.mysqld.erb @@ -35,8 +35,10 @@ /var/log/mysql/* rw, /var/run/mysqld/mysqld.pid rw, /var/run/mysqld/mysqld.sock w, + /var/run/mysqld/mysqld.sock.lock rw, /run/mysqld/mysqld.pid rw, /run/mysqld/mysqld.sock w, + /run/mysqld/mysqld.sock.lock rw, /sys/devices/system/cpu/ r, diff --git a/cookbooks/mysql/templates/default/my.cnf.erb b/cookbooks/mysql/templates/default/my.cnf.erb index faa8d3e..ff10156 100644 --- a/cookbooks/mysql/templates/default/my.cnf.erb +++ b/cookbooks/mysql/templates/default/my.cnf.erb @@ -7,8 +7,8 @@ default-character-set = <%= @config.charset %> <% if @config.port %> port = <%= @config.port %> <% end %> -<% if @socket_file %> -socket = <%= @socket_file %> +<% if @config.socket_file %> +socket = <%= @config.socket_file %> <% end %> [mysql] @@ -20,11 +20,11 @@ default-character-set = <%= @config.charset %> <% if @config.run_user %> user = <%= @config.run_user %> <% end %> -<% if @pid_file %> -pid-file = <%= @pid_file %> +<% if @config.pid_file %> +pid-file = <%= @config.pid_file %> <% end %> -<% if @socket_file %> -socket = <%= @socket_file %> +<% if @config.socket_file %> +socket = <%= @config.socket_file %> <% end %> <% if @config.bind_address %> bind-address = <%= @config.bind_address %> @@ -32,26 +32,26 @@ bind-address = <%= @config.bind_address %> <% if @config.port %> port = <%= @config.port %> <% end %> -<% if @data_dir %> -datadir = <%= @data_dir %> +<% if @config.data_dir %> +datadir = <%= @config.data_dir %> <% end %> -<% if @tmp_dir %> -tmpdir = <%= @tmp_dir %> +<% if @config.tmp_dir %> +tmpdir = <%= @config.tmp_dir %> <% end %> <% @config.mysqld_options.each do |option,value| %> <%= option %> = <%= value %> <% end %> -<% if @lc_messages_dir %> -lc-messages-dir = <%= @lc_messages_dir %> +<% if @config.lc_messages_dir %> +lc-messages-dir = <%= @config.lc_messages_dir %> <% end %> -<% if @error_log %> -log-error = <%= @error_log %> +<% if @config.error_log %> +log-error = <%= @config.error_log %> <% end %> -<% if @include_dir %> -!includedir <%= @include_dir %> +<% if @config.include_dir %> +!includedir <%= @config.include_dir %> <% end %> [mysqld_safe] -<% if @socket_file %> -socket = <%= @socket_file %> +<% if @config.socket_file %> +socket = <%= @config.socket_file %> <% end %> diff --git a/cookbooks/yum/.foodcritic b/cookbooks/mysql2_chef_gem/.foodcritic similarity index 100% rename from cookbooks/yum/.foodcritic rename to cookbooks/mysql2_chef_gem/.foodcritic diff --git a/cookbooks/mysql2_chef_gem/CHANGELOG.md b/cookbooks/mysql2_chef_gem/CHANGELOG.md index f41303c..aa192b0 100644 --- a/cookbooks/mysql2_chef_gem/CHANGELOG.md +++ b/cookbooks/mysql2_chef_gem/CHANGELOG.md @@ -1,30 +1,56 @@ -mysql2_chef_gem CHANGELOG -======================== +# mysql2_chef_gem CHANGELOG + +## 2.0.1 (2017-03-28) + +- Include usage examples for installing on a mariadb server and included a note in the readme regarding the 2.0 changes. + +## 2.0.0 (2017-03-28) + +- Converted the previously HWRP resources/providers to a custom resource. This changes the behavior of choosing to install on mysql or mariadb in a breaking way. Instead of specifying the providers you need to call the resources directly. Specifying mysql2_chef_gem will default to mysql, but using mariadb will require using the mysql2_chef_gem_mariadb resource directly. +- Increase the minimum chef version to 12.5 +- Require mysql cookbook 8.2+ and build-essential cookbook 2.4+ +- Install the 0.4.5 gem by default +- Expand test recipe to cover more scenarios +- Switched testing to use Delivery local mode +- Switched from kitchen-docker to kitchen-dokken and removed testing for CentOS 5 / Ubuntu 12.04 as these are both going EOL +- Switched from Rubocop to cookstyle for linting +- Removed yum/apt from the Berksfile +- Remove test dependencies from the Gemfile and instead use ChefDK for testing + +## 1.1.0 (2016-04-27) + +- Added a chefignore file +- Loosen the dependency on mysql cookbook to allow for the use of the latest version +- Added source_url and issue_url metadata +- Added long_description metadata +- Removed the AWS based Test Kitchen testing and replaced with with kitchen-docker in Travis +- Updated Chefspec format to remove deprecation warnings +- Added Oracle Linux to the metadata + +## 1.0.2 (2015-06-29) -1.0.2 (2015-06-29) ------------------- - Updating metadata to depend on mysql ~> 6.0 -1.0.1 (2014-12-25) ------------------- +## 1.0.1 (2014-12-25) + - Moving from recipe_eval in to include_recipe LWRP -1.0.0 (2014-12-23) ------------------- +## 1.0.0 (2014-12-23) + - Replacing recipes with resources - Mysql and MariaDB providers for linking mysql2 gem - Expanded platform test coverage -0.1.1 (2014-09-15) ------------------- +## 0.1.1 (2014-09-15) + - Correct a typo in documentation - Correct a test failing with Travis CI -0.1.0 (2014-09-15) ------------------- +## 0.1.0 (2014-09-15) + - Correct documentation - Correct rubocop offenses -0.0.3 (2014-09-12) ------------------- +## 0.0.3 (2014-09-12) + - Initial release (copy of mysql-chef_gem, but for mysql2) diff --git a/cookbooks/mysql2_chef_gem/README.md b/cookbooks/mysql2_chef_gem/README.md index 97c4f68..e294bba 100644 --- a/cookbooks/mysql2_chef_gem/README.md +++ b/cookbooks/mysql2_chef_gem/README.md @@ -1,29 +1,20 @@ -Mysql2 Chef Gem Installer Cookbook -================================== +# Mysql2 Chef Gem Installer Cookbook -[![Build Status](https://travis-ci.org/sinfomicien/mysql2_chef_gem.png)](https://travis-ci.org/sinfomicien/mysql2_chef_gem) +[![Build Status](https://travis-ci.org/sinfomicien/mysql2_chef_gem.svg)](https://travis-ci.org/sinfomicien/mysql2_chef_gem) [![Cookbook Version](http://img.shields.io/cookbook/v/mysql2_chef_gem.svg)](https://supermarket.chef.io/cookbooks/mysql2_chef_gem) -mysql2_chef_gem is a library cookbook that provides an LWRP for use -in recipes. It provides a wrapper around `chef_gem` called -`mysql2_chef_gem` that eases the installation process, collecting the -prerequisites and side-stepping the compilation phase arms race. +mysql2_chef_gem is a library cookbook that provides a resource for installing the mysql2 gem against either mysql or mariadb depending on usage. -Scope ------ -This cookbook is concerned with the installation of the `mysql2` -Rubygem into Chef's gem path. Installation into other Ruby -environments, or installation of related gems such as `mysql` are -outside the scope of this cookbook. +## Scope -Requirements ------------- -* Chef 11 or higher -* Ruby 1.9 (preferably from the Chef full-stack installer) +This cookbook is concerned with the installation of the `mysql2` Rubygem into Chef's gem path. Installation into other Ruby environments, or installation of related gems such as `mysql` are outside the scope of this cookbook. -Platform Support ----------------- -The following platforms have been tested with Test Kitchen and are -known to work. +## Requirements + +- Chef 12.5+ + +## Platform Support + +The following platforms have been tested with Test Kitchen and are known to work. ``` |---------------------------------------+-----+-----+-----+-----+-----| @@ -35,27 +26,24 @@ known to work. |---------------------------------------+-----+-----+-----+-----+-----| | Mysql2ChefGem::Mysql / centos-7 | | | X | X | X | |---------------------------------------+-----+-----+-----+-----+-----| -| Mysql2ChefGem::Mysql / fedora-20 | | | X | X | X | +| Mysql2ChefGem::Mysql / fedora | | | X | X | X | |---------------------------------------+-----+-----+-----+-----+-----| | Mysql2ChefGem::Mysql / debian-7 | | | X | | | |---------------------------------------+-----+-----+-----+-----+-----| -| Mysql2ChefGem::Mysql / ubuntu-10.04 | | X | | | | -|---------------------------------------+-----+-----+-----+-----+-----| -| Mysql2ChefGem::Mysql / ubuntu-12.04 | | | X | | | -|---------------------------------------+-----+-----+-----+-----+-----| | Mysql2ChefGem::Mysql / ubuntu-14.04 | | | X | X | | |---------------------------------------+-----+-----+-----+-----+-----| -| Mysql2ChefGem::Mariadb / fedora-20 | | | X | | | +| Mysql2ChefGem::Mariadb / fedora | | | X | | | |---------------------------------------+-----+-----+-----+-----+-----| | Mysql2ChefGem::Mariadb / ubuntu-14.04 | | | X | | | |---------------------------------------+-----+-----+-----+-----+-----| ``` -Usage ------ +## Usage + Place a dependency on the mysql cookbook in your cookbook's metadata.rb + ```ruby -depends 'mysql2_chef_gem', '~> 1.0' +depends 'mysql2_chef_gem' ``` Then, in a recipe: @@ -66,43 +54,61 @@ mysql2_chef_gem 'default' do end ``` -Resources Overview ------------------- +### 2.0 Compatibility + +In order to ensure compatibility with Chef 13, the 2.0 release of this cookbook changed the method used to specify installation against mariadb. Instead of specifying the underlying provider, you instead reference the mariadb specific resource. See the example below for the new syntax. + +## Resources Overview + ### mysql2_chef_gem -The `mysql2_chef_gem` resource the build dependencies and installation -of the `mysql2` rubygem into Chef's Ruby environment +The `mysql2_chef_gem` resource installs mysql client development dependencies and installs the `mysql2` rubygem into Chef's Ruby environment. #### Example + ```ruby mysql2_chef_gem 'default' do - gem_version '0.3.17' + gem_version '0.4.5' action :install end ``` -#### Parameters -- `gem_version` - The version of the `mysql` Rubygem to install into - the Chef environment. Defaults to '0.3.17' - connector libraries -- `client_version` - The version of the mysql client libraries to - install and link against + +#### Properties + +- `gem_version` - The version of the `mysql` Rubygem to install into the Chef environment. Defaults to '0.4.5' connector libraries +- `package_version` - The version of the mysql client libraries to install and link against #### Actions + - `:install` - Build and install the gem into the Chef environment - `:remove` - Delete the gem from the Chef environment -#### Providers -Chef selects a default provider based on platform and version, -but you can specify one if your platform support it. +### mysql2_chef_gem_mariadb + +To install the mysql2 gem against an installation of mariadb reference the `mysql2_chef_gem_mariadb` resource directly. This resource includes all the same properties of the standard `mysql2_chef_gem` resource. ```ruby -mysql2_chef_gem 'default' do - provider Chef::Provider::Mysql2ChefGem::Mariadb +mysql2_chef_gem_mariadb 'default' do action :install end ``` -Authors -------- -- Author:: Sean OMeara () -- Author:: Nicolas Blanc() +## License & Authors + +- Author:: Sean OMeara ([someara@sean.io](mailto:someara@sean.io)) +- Author:: Tim Smith ([tsmith@chef.io](mailto:tsmith@chef.io)) +- Author:: Nicolas Blanc([sinfomicien@gmail.com](mailto:sinfomicien@gmail.com)) + +``` +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +``` diff --git a/cookbooks/mysql2_chef_gem/libraries/provider_mysql2_chef_gem_mariadb.rb b/cookbooks/mysql2_chef_gem/libraries/provider_mysql2_chef_gem_mariadb.rb deleted file mode 100644 index e25a427..0000000 --- a/cookbooks/mysql2_chef_gem/libraries/provider_mysql2_chef_gem_mariadb.rb +++ /dev/null @@ -1,37 +0,0 @@ -class Chef - class Provider - class Mysql2ChefGem - class Mariadb < Chef::Provider::LWRPBase - use_inline_resources if defined?(use_inline_resources) - - def whyrun_supported? - true - end - - action :install do - recipe_eval do - run_context.include_recipe 'build-essential::default' - end - - # As a recipe: must rely on global node attributes - recipe_eval do - run_context.include_recipe 'mariadb::client' - end - - gem_package 'mysql2' do - gem_binary RbConfig::CONFIG['bindir'] + '/gem' - version new_resource.gem_version - action :install - end - end - - action :remove do - gem_package 'mysql2' do - gem_binary RbConfig::CONFIG['bindir'] + '/gem' - action :remove - end - end - end - end - end -end diff --git a/cookbooks/mysql2_chef_gem/libraries/provider_mysql2_chef_gem_mysql.rb b/cookbooks/mysql2_chef_gem/libraries/provider_mysql2_chef_gem_mysql.rb deleted file mode 100644 index cc1bace..0000000 --- a/cookbooks/mysql2_chef_gem/libraries/provider_mysql2_chef_gem_mysql.rb +++ /dev/null @@ -1,37 +0,0 @@ -class Chef - class Provider - class Mysql2ChefGem - class Mysql < Chef::Provider::LWRPBase - include Chef::DSL::IncludeRecipe - use_inline_resources if defined?(use_inline_resources) - - def whyrun_supported? - true - end - - action :install do - include_recipe 'build-essential::default' - - # As a resource: can pass version from calling recipe - mysql_client 'default' do - version new_resource.client_version - action :create - end - - gem_package 'mysql2' do - gem_binary RbConfig::CONFIG['bindir'] + '/gem' - version new_resource.gem_version - action :install - end - end - - action :remove do - gem_package 'mysql2' do - gem_binary RbConfig::CONFIG['bindir'] + '/gem' - action :remove - end - end - end - end - end -end diff --git a/cookbooks/mysql2_chef_gem/libraries/resource_mysql2_chef_gem.rb b/cookbooks/mysql2_chef_gem/libraries/resource_mysql2_chef_gem.rb deleted file mode 100644 index 92ba02f..0000000 --- a/cookbooks/mysql2_chef_gem/libraries/resource_mysql2_chef_gem.rb +++ /dev/null @@ -1,15 +0,0 @@ -require 'chef/resource/lwrp_base' - -class Chef - class Resource - class Mysql2ChefGem < Chef::Resource::LWRPBase - self.resource_name = :mysql2_chef_gem - actions :install, :remove - default_action :install - - attribute :mysql2_chef_gem_name, kind_of: String, name_attribute: true, required: true - attribute :gem_version, kind_of: String, default: '0.3.17' - attribute :client_version, kind_of: String, default: nil - end - end -end diff --git a/cookbooks/mysql2_chef_gem/libraries/z_provider_mapping.rb b/cookbooks/mysql2_chef_gem/libraries/z_provider_mapping.rb deleted file mode 100644 index bf0d7aa..0000000 --- a/cookbooks/mysql2_chef_gem/libraries/z_provider_mapping.rb +++ /dev/null @@ -1,17 +0,0 @@ -######### -# mysql2_chef_gem -######### -Chef::Platform.set platform: :amazon, resource: :mysql2_chef_gem, provider: Chef::Provider::Mysql2ChefGem::Mysql -Chef::Platform.set platform: :centos, version: '< 7.0', resource: :mysql2_chef_gem, provider: Chef::Provider::Mysql2ChefGem::Mysql -Chef::Platform.set platform: :centos, version: '>= 7.0', resource: :mysql2_chef_gem, provider: Chef::Provider::Mysql2ChefGem::Mysql -Chef::Platform.set platform: :debian, resource: :mysql2_chef_gem, provider: Chef::Provider::Mysql2ChefGem::Mysql -Chef::Platform.set platform: :fedora, version: '< 19', resource: :mysql2_chef_gem, provider: Chef::Provider::Mysql2ChefGem::Mysql -Chef::Platform.set platform: :fedora, version: '>= 19', resource: :mysql2_chef_gem, provider: Chef::Provider::Mysql2ChefGem::Mysql -Chef::Platform.set platform: :omnios, resource: :mysql2_chef_gem, provider: Chef::Provider::Mysql2ChefGem::Mysql -Chef::Platform.set platform: :redhat, version: '< 7.0', resource: :mysql2_chef_gem, provider: Chef::Provider::Mysql2ChefGem::Mysql -Chef::Platform.set platform: :redhat, version: '>= 7.0', resource: :mysql2_chef_gem, provider: Chef::Provider::Mysql2ChefGem::Mysql -Chef::Platform.set platform: :scientific, version: '< 7.0', resource: :mysql2_chef_gem, provider: Chef::Provider::Mysql2ChefGem::Mysql -Chef::Platform.set platform: :scientific, version: '>= 7.0', resource: :mysql2_chef_gem, provider: Chef::Provider::Mysql2ChefGem::Mysql -Chef::Platform.set platform: :smartos, resource: :mysql2_chef_gem, provider: Chef::Provider::Mysql2ChefGem::Mysql -Chef::Platform.set platform: :suse, resource: :mysql2_chef_gem, provider: Chef::Provider::Mysql2ChefGem::Mysql -Chef::Platform.set platform: :ubuntu, resource: :mysql2_chef_gem, provider: Chef::Provider::Mysql2ChefGem::Mysql diff --git a/cookbooks/mysql2_chef_gem/metadata.json b/cookbooks/mysql2_chef_gem/metadata.json index 5021c36..8144cd2 100644 --- a/cookbooks/mysql2_chef_gem/metadata.json +++ b/cookbooks/mysql2_chef_gem/metadata.json @@ -1 +1 @@ -{"name":"mysql2_chef_gem","version":"1.0.2","description":"Provides the mysql2_chef_gem resource","long_description":"","maintainer":"Nicolas Blanc","maintainer_email":"sinfomicien@gmail.com","license":"Apache 2.0","platforms":{"amazon":">= 0.0.0","redhat":">= 0.0.0","centos":">= 0.0.0","scientific":">= 0.0.0","fedora":">= 0.0.0","debian":">= 0.0.0","ubuntu":">= 0.0.0"},"dependencies":{"build-essential":">= 0.0.0","mysql":"~> 6.0","mariadb":">= 0.0.0"},"recommendations":{},"suggestions":{},"conflicting":{},"providing":{},"replacing":{},"attributes":{},"groupings":{},"recipes":{}} \ No newline at end of file +{"name":"mysql2_chef_gem","version":"2.0.1","description":"Provides the mysql2_chef_gem resource","long_description":"# Mysql2 Chef Gem Installer Cookbook\n\n[![Build Status](https://travis-ci.org/sinfomicien/mysql2_chef_gem.svg)](https://travis-ci.org/sinfomicien/mysql2_chef_gem) [![Cookbook Version](http://img.shields.io/cookbook/v/mysql2_chef_gem.svg)](https://supermarket.chef.io/cookbooks/mysql2_chef_gem)\n\nmysql2_chef_gem is a library cookbook that provides a resource for installing the mysql2 gem against either mysql or mariadb depending on usage.\n\n## Scope\n\nThis cookbook is concerned with the installation of the `mysql2` Rubygem into Chef's gem path. Installation into other Ruby environments, or installation of related gems such as `mysql` are outside the scope of this cookbook.\n\n## Requirements\n\n- Chef 12.5+\n\n## Platform Support\n\nThe following platforms have been tested with Test Kitchen and are known to work.\n\n```\n|---------------------------------------+-----+-----+-----+-----+-----|\n| | 5.0 | 5.1 | 5.5 | 5.6 | 5.7 |\n|---------------------------------------+-----+-----+-----+-----+-----|\n| Mysql2ChefGem::Mysql / centos-5 | X | | | X | X |\n|---------------------------------------+-----+-----+-----+-----+-----|\n| Mysql2ChefGem::Mysql / centos-6 | | X | X | X | X |\n|---------------------------------------+-----+-----+-----+-----+-----|\n| Mysql2ChefGem::Mysql / centos-7 | | | X | X | X |\n|---------------------------------------+-----+-----+-----+-----+-----|\n| Mysql2ChefGem::Mysql / fedora | | | X | X | X |\n|---------------------------------------+-----+-----+-----+-----+-----|\n| Mysql2ChefGem::Mysql / debian-7 | | | X | | |\n|---------------------------------------+-----+-----+-----+-----+-----|\n| Mysql2ChefGem::Mysql / ubuntu-14.04 | | | X | X | |\n|---------------------------------------+-----+-----+-----+-----+-----|\n| Mysql2ChefGem::Mariadb / fedora | | | X | | |\n|---------------------------------------+-----+-----+-----+-----+-----|\n| Mysql2ChefGem::Mariadb / ubuntu-14.04 | | | X | | |\n|---------------------------------------+-----+-----+-----+-----+-----|\n```\n\n## Usage\n\nPlace a dependency on the mysql cookbook in your cookbook's metadata.rb\n\n```ruby\ndepends 'mysql2_chef_gem'\n```\n\nThen, in a recipe:\n\n```ruby\nmysql2_chef_gem 'default' do\n action :install\nend\n```\n\n### 2.0 Compatibility\n\nIn order to ensure compatibility with Chef 13, the 2.0 release of this cookbook changed the method used to specify installation against mariadb. Instead of specifying the underlying provider, you instead reference the mariadb specific resource. See the example below for the new syntax.\n\n## Resources Overview\n\n### mysql2_chef_gem\n\nThe `mysql2_chef_gem` resource installs mysql client development dependencies and installs the `mysql2` rubygem into Chef's Ruby environment.\n\n#### Example\n\n```ruby\nmysql2_chef_gem 'default' do\n gem_version '0.4.5'\n action :install\nend\n```\n\n#### Properties\n\n- `gem_version` - The version of the `mysql` Rubygem to install into the Chef environment. Defaults to '0.4.5' connector libraries\n- `package_version` - The version of the mysql client libraries to install and link against\n\n#### Actions\n\n- `:install` - Build and install the gem into the Chef environment\n- `:remove` - Delete the gem from the Chef environment\n\n### mysql2_chef_gem_mariadb\n\nTo install the mysql2 gem against an installation of mariadb reference the `mysql2_chef_gem_mariadb` resource directly. This resource includes all the same properties of the standard `mysql2_chef_gem` resource.\n\n```ruby\nmysql2_chef_gem_mariadb 'default' do\n action :install\nend\n```\n\n## License & Authors\n\n- Author:: Sean OMeara ([someara@sean.io](mailto:someara@sean.io))\n- Author:: Tim Smith ([tsmith@chef.io](mailto:tsmith@chef.io))\n- Author:: Nicolas Blanc([sinfomicien@gmail.com](mailto:sinfomicien@gmail.com))\n\n```\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n```\n","maintainer":"Nicolas Blanc","maintainer_email":"sinfomicien@gmail.com","license":"Apache 2.0","platforms":{"centos":">= 0.0.0","redhat":">= 0.0.0","scientific":">= 0.0.0","oracle":">= 0.0.0","fedora":">= 0.0.0","debian":">= 0.0.0","ubuntu":">= 0.0.0"},"dependencies":{"build-essential":">= 2.4.0","mysql":">= 8.2.0","mariadb":">= 0.0.0"},"recommendations":{},"suggestions":{},"conflicting":{},"providing":{},"replacing":{},"attributes":{},"groupings":{},"recipes":{},"source_url":"https://github.com/sinfomicien/mysql2_chef_gem","issues_url":"https://github.com/sinfomicien/mysql2_chef_gem/issues","chef_version":">= 12.5","ohai_version":{}} \ No newline at end of file diff --git a/cookbooks/mysql2_chef_gem/resources/mysql2_chef_gem_mariadb.rb b/cookbooks/mysql2_chef_gem/resources/mysql2_chef_gem_mariadb.rb new file mode 100644 index 0000000..60ab5b2 --- /dev/null +++ b/cookbooks/mysql2_chef_gem/resources/mysql2_chef_gem_mariadb.rb @@ -0,0 +1,29 @@ +property :mysql2_chef_gem_name, String, name_attribute: true, required: true +property :gem_version, String, default: '0.4.5' +property :package_version, String + +provides :mysql2_chef_gem_mariadb + +action :install do + recipe_eval do + run_context.include_recipe 'build-essential::default' + end + + # As a recipe: must rely on global node attributes + recipe_eval do + run_context.include_recipe 'mariadb::client' + end + + gem_package 'mysql2' do + gem_binary RbConfig::CONFIG['bindir'] + '/gem' + version new_resource.gem_version + action :install + end +end + +action :remove do + gem_package 'mysql2' do + gem_binary RbConfig::CONFIG['bindir'] + '/gem' + action :remove + end +end diff --git a/cookbooks/mysql2_chef_gem/resources/mysql2_chef_gem_mysql.rb b/cookbooks/mysql2_chef_gem/resources/mysql2_chef_gem_mysql.rb new file mode 100644 index 0000000..28dd390 --- /dev/null +++ b/cookbooks/mysql2_chef_gem/resources/mysql2_chef_gem_mysql.rb @@ -0,0 +1,29 @@ +property :mysql2_chef_gem_name, String, name_attribute: true, required: true +property :gem_version, String, default: '0.4.5' +property :package_version, String + +provides :mysql2_chef_gem +provides :mysql2_chef_gem_mysql + +action :install do + include_recipe 'build-essential::default' + + # As a resource: can pass version from calling recipe + mysql_client 'default' do + version new_resource.package_version if new_resource.package_version + action :create + end + + gem_package 'mysql2' do + gem_binary RbConfig::CONFIG['bindir'] + '/gem' + version new_resource.gem_version + action :install + end +end + +action :remove do + gem_package 'mysql2' do + gem_binary RbConfig::CONFIG['bindir'] + '/gem' + action :remove + end +end diff --git a/cookbooks/php-fpm/.kitchen.yml b/cookbooks/php-fpm/.kitchen.yml deleted file mode 100644 index 07393c6..0000000 --- a/cookbooks/php-fpm/.kitchen.yml +++ /dev/null @@ -1,21 +0,0 @@ ---- -driver: - name: vagrant - -provisioner: - name: chef_solo - -platforms: - - name: ubuntu-12.04 - - name: centos-6.4 - - name: fedora-21 - -suites: - - name: default - run_list: - - recipe[php-fpm::default] - attributes: - php-fpm: - pools: - - name: web - listen: '127.0.0.1:9081' diff --git a/cookbooks/php-fpm/.ruby-version b/cookbooks/php-fpm/.ruby-version deleted file mode 100644 index 0ca8caf..0000000 --- a/cookbooks/php-fpm/.ruby-version +++ /dev/null @@ -1 +0,0 @@ -1.9.3-p327 diff --git a/cookbooks/php-fpm/Berksfile b/cookbooks/php-fpm/Berksfile deleted file mode 100644 index 0ac9b78..0000000 --- a/cookbooks/php-fpm/Berksfile +++ /dev/null @@ -1,3 +0,0 @@ -source "https://supermarket.getchef.com" - -metadata diff --git a/cookbooks/php-fpm/Gemfile b/cookbooks/php-fpm/Gemfile deleted file mode 100644 index eca2238..0000000 --- a/cookbooks/php-fpm/Gemfile +++ /dev/null @@ -1,20 +0,0 @@ -source 'https://rubygems.org' - -gem 'berkshelf' - -# Uncomment these lines if you want to live on the Edge: -# -# group :development do -# gem "berkshelf", github: "berkshelf/berkshelf" -# gem "vagrant", github: "mitchellh/vagrant", tag: "v1.6.3" -# end -# -# group :plugins do -# gem "vagrant-berkshelf", github: "berkshelf/vagrant-berkshelf" -# gem "vagrant-omnibus", github: "schisamo/vagrant-omnibus" -# end - -gem 'test-kitchen' -gem 'kitchen-vagrant' -gem 'stove' -gem 'serverspec' diff --git a/cookbooks/php-fpm/Gemfile.lock b/cookbooks/php-fpm/Gemfile.lock deleted file mode 100644 index cc6cb33..0000000 --- a/cookbooks/php-fpm/Gemfile.lock +++ /dev/null @@ -1,179 +0,0 @@ -GEM - remote: https://rubygems.org/ - specs: - activesupport (3.2.19) - i18n (~> 0.6, >= 0.6.4) - multi_json (~> 1.0) - addressable (2.3.6) - akami (1.2.2) - gyoku (>= 0.4.0) - nokogiri - berkshelf (2.0.18) - activesupport (~> 3.2.0) - addressable (~> 2.3.4) - buff-shell_out (~> 0.1) - chozo (>= 0.6.1) - faraday (~> 0.8.5) - hashie (~> 2.0) - minitar (~> 0.5.4) - rbzip2 (~> 0.2.0) - retryable (~> 1.3.3) - ridley (~> 1.7.0) - solve (~> 0.8.2) - thor (~> 0.18.0) - buff-config (0.4.0) - buff-extensions (~> 0.3) - varia_model (~> 0.1) - buff-extensions (0.5.0) - buff-ignore (1.1.1) - buff-ruby_engine (0.1.0) - buff-shell_out (0.2.0) - buff-ruby_engine (~> 0.1.0) - builder (3.2.2) - celluloid (0.16.0) - timers (~> 4.0.0) - celluloid-io (0.16.1) - celluloid (>= 0.16.0) - nio4r (>= 1.0.0) - chef-api (0.5.0) - logify (~> 0.1) - mime-types - chozo (0.6.1) - activesupport (>= 3.2.0) - hashie (>= 2.0.2) - multi_json (>= 1.3.0) - diff-lcs (1.2.5) - erubis (2.7.0) - faraday (0.8.9) - multipart-post (~> 1.2.0) - ffi (1.9.6) - gssapi (1.0.3) - ffi (>= 1.0.1) - gyoku (1.2.2) - builder (>= 2.1.2) - hashie (2.1.2) - hitimes (1.2.2) - httpclient (2.5.1) - httpi (0.9.7) - rack - i18n (0.6.11) - json (1.8.1) - kitchen-vagrant (0.15.0) - test-kitchen (~> 1.0) - little-plugger (1.1.3) - logging (1.8.2) - little-plugger (>= 1.1.3) - multi_json (>= 1.8.4) - logify (0.2.0) - mime-types (2.4.2) - mini_portile (0.6.0) - minitar (0.5.4) - mixlib-authentication (1.3.0) - mixlib-log - mixlib-log (1.6.0) - mixlib-shellout (1.6.1) - multi_json (1.10.1) - multipart-post (1.2.0) - net-http-persistent (2.9.4) - net-scp (1.2.1) - net-ssh (>= 2.6.5) - net-ssh (2.9.1) - nio4r (1.0.1) - nokogiri (1.6.3.1) - mini_portile (= 0.6.0) - nori (1.1.5) - rack (1.5.2) - rbzip2 (0.2.0) - retryable (1.3.6) - ridley (1.7.1) - addressable - buff-config (~> 0.2) - buff-extensions (~> 0.3) - buff-ignore (~> 1.1) - buff-shell_out (~> 0.1) - celluloid (~> 0.15) - celluloid-io (~> 0.15) - erubis - faraday (>= 0.8.4) - hashie (>= 2.0.2) - json (>= 1.7.7) - mixlib-authentication (>= 1.3.0) - net-http-persistent (>= 2.8) - net-ssh - retryable - solve (>= 0.4.4) - varia_model (~> 0.1) - winrm (~> 1.1.0) - rspec (3.1.0) - rspec-core (~> 3.1.0) - rspec-expectations (~> 3.1.0) - rspec-mocks (~> 3.1.0) - rspec-core (3.1.7) - rspec-support (~> 3.1.0) - rspec-expectations (3.1.2) - diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.1.0) - rspec-its (1.0.1) - rspec-core (>= 2.99.0.beta1) - rspec-expectations (>= 2.99.0.beta1) - rspec-mocks (3.1.3) - rspec-support (~> 3.1.0) - rspec-support (3.1.2) - rubyntlm (0.1.1) - safe_yaml (1.0.4) - savon (0.9.5) - akami (~> 1.0) - builder (>= 2.1.2) - gyoku (>= 0.4.0) - httpi (~> 0.9) - nokogiri (>= 1.4.0) - nori (~> 1.0) - wasabi (~> 1.0) - serverspec (2.3.1) - multi_json - rspec (~> 3.0) - rspec-its - specinfra (~> 2.3) - solve (0.8.2) - specinfra (2.3.0) - net-scp - net-ssh - stove (3.2.3) - chef-api (~> 0.5) - logify (~> 0.2) - test-kitchen (1.2.1) - mixlib-shellout (~> 1.2) - net-scp (~> 1.1) - net-ssh (~> 2.7) - safe_yaml (~> 1.0) - thor (~> 0.18) - thor (0.18.1) - timers (4.0.1) - hitimes - uuidtools (2.1.5) - varia_model (0.3.2) - buff-extensions (~> 0.2) - hashie (>= 2.0.2) - wasabi (1.0.0) - nokogiri (>= 1.4.0) - winrm (1.1.3) - gssapi (~> 1.0.0) - httpclient (~> 2.2, >= 2.2.0.2) - logging (~> 1.6, >= 1.6.1) - nokogiri (~> 1.5) - rubyntlm (~> 0.1.1) - savon (= 0.9.5) - uuidtools (~> 2.1.2) - -PLATFORMS - ruby - -DEPENDENCIES - berkshelf - kitchen-vagrant - serverspec - stove - test-kitchen - -BUNDLED WITH - 1.10.3 diff --git a/cookbooks/php-fpm/README.md b/cookbooks/php-fpm/README.md index 4a11ecc..90cf378 100644 --- a/cookbooks/php-fpm/README.md +++ b/cookbooks/php-fpm/README.md @@ -77,6 +77,57 @@ php_fpm_pool "www" do end ``` +Development +=========== + +### Requirements + +* [Docker](https://www.docker.com/) + +### Setup + +To get all dependencies: + +``` +bundle install +``` + +### Test + +To see available platforms: + +``` +bundle exec rake -T +``` + +To test particular platform: + +``` +bundle exec rake kitchen:default-ubuntu-1604 +``` + +To test all platforms: + +``` +bundle exec rake kitchen:all +``` + +### Publishing (maintainers only!) + +Bump version in metadata.rb, commit and push to master! + +``` +bundle exec rake publish +``` + +as a result new tag will be created and pushed to github as well as new version +will be published on https://supermarket.chef.io + +Contributing +=========== + +Please do not bump version when proposing a change, no other rules ;) + License and Author ================== diff --git a/cookbooks/php-fpm/Rakefile b/cookbooks/php-fpm/Rakefile deleted file mode 100644 index c13c98f..0000000 --- a/cookbooks/php-fpm/Rakefile +++ /dev/null @@ -1,13 +0,0 @@ -begin - require 'kitchen/rake_tasks' - Kitchen::RakeTasks.new -rescue LoadError - puts ">>>>> Kitchen gem not loaded, omitting tasks" unless ENV['CI'] -end - -begin - require 'stove/rake_task' - Stove::RakeTask.new -rescue LoadErro - pust ">>>>> Stove gem not loaded, omitting tasks" unless ENV['CI'] -end diff --git a/cookbooks/php-fpm/Thorfile b/cookbooks/php-fpm/Thorfile deleted file mode 100644 index b23ee16..0000000 --- a/cookbooks/php-fpm/Thorfile +++ /dev/null @@ -1,12 +0,0 @@ -# encoding: utf-8 - -require 'bundler' -require 'bundler/setup' -require 'berkshelf/thor' - -begin - require 'kitchen/thor_tasks' - Kitchen::ThorTasks.new -rescue LoadError - puts ">>>>> Kitchen gem not loaded, omitting tasks" unless ENV['CI'] -end diff --git a/cookbooks/php-fpm/Vagrantfile b/cookbooks/php-fpm/Vagrantfile deleted file mode 100644 index 370049d..0000000 --- a/cookbooks/php-fpm/Vagrantfile +++ /dev/null @@ -1,90 +0,0 @@ -# -*- mode: ruby -*- -# vi: set ft=ruby : - -# Vagrantfile API/syntax version. Don't touch unless you know what you're doing! -VAGRANTFILE_API_VERSION = "2" - -Vagrant.require_version ">= 1.5.0" - -Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| - # All Vagrant configuration is done here. The most common configuration - # options are documented and commented below. For a complete reference, - # please see the online documentation at vagrantup.com. - - config.vm.hostname = "php-fpm-berkshelf" - - # Set the version of chef to install using the vagrant-omnibus plugin - config.omnibus.chef_version = :latest - - # Every Vagrant virtual environment requires a box to build off of. - # If this value is a shorthand to a box in Vagrant Cloud then - # config.vm.box_url doesn't need to be specified. - # config.vm.box = "chef/ubuntu-14.04" - case ENV['VMBOX'] - when 'centos65' - config.vm.box = "opscode-centos-6.5" - config.vm.box_url = "http://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_centos-6.5_chef-provisionerless.box" - else - config.vm.box = "opscode-ubuntu-12.04" - config.vm.box_url = "http://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_ubuntu-12.04_chef-provisionerless.box" - end - - # The url from where the 'config.vm.box' box will be fetched if it - # is not a Vagrant Cloud box and if it doesn't already exist on the - # user's system. - # config.vm.box_url = "https://vagrantcloud.com/chef/ubuntu-14.04/version/1/provider/virtualbox.box" - - # Assign this VM to a host-only network IP, allowing you to access it - # via the IP. Host-only networks can talk to the host machine as well as - # any other machines on the same network, but cannot be accessed (through this - # network interface) by any external networks. - # config.vm.network :private_network, type: "dhcp" - config.vm.network :private_network, ip: "33.33.33.10" - - # Create a forwarded port mapping which allows access to a specific port - # within the machine from a port on the host machine. In the example below, - # accessing "localhost:8080" will access port 80 on the guest machine. - - # Share an additional folder to the guest VM. The first argument is - # the path on the host to the actual folder. The second argument is - # the path on the guest to mount the folder. And the optional third - # argument is a set of non-required options. - # config.vm.synced_folder "../data", "/vagrant_data" - - # Provider-specific configuration so you can fine-tune various - # backing providers for Vagrant. These expose provider-specific options. - # Example for VirtualBox: - # - # config.vm.provider :virtualbox do |vb| - # # Don't boot with headless mode - # vb.gui = true - # - # # Use VBoxManage to customize the VM. For example to change memory: - # vb.customize ["modifyvm", :id, "--memory", "1024"] - # end - # - # View the documentation for the provider you're using for more - # information on available options. - - # The path to the Berksfile to use with Vagrant Berkshelf - # config.berkshelf.berksfile_path = "./Berksfile" - - # Enabling the Berkshelf plugin. To enable this globally, add this configuration - # option to your ~/.vagrant.d/Vagrantfile file - config.berkshelf.enabled = true - - # An array of symbols representing groups of cookbook described in the Vagrantfile - # to exclusively install and copy to Vagrant's shelf. - # config.berkshelf.only = [] - - # An array of symbols representing groups of cookbook described in the Vagrantfile - # to skip installing and copying to Vagrant's shelf. - # config.berkshelf.except = [] - - config.vm.provision :chef_solo do |chef| - chef.run_list = [ - "recipe[apt]", - "recipe[php-fpm::default]" - ] - end -end diff --git a/cookbooks/php-fpm/attributes/default.rb b/cookbooks/php-fpm/attributes/default.rb index c5ad1c4..da97d91 100644 --- a/cookbooks/php-fpm/attributes/default.rb +++ b/cookbooks/php-fpm/attributes/default.rb @@ -10,15 +10,22 @@ when "rhel", "fedora" else user = "www-data" group = "www-data" - conf_dir = "/etc/php5/fpm/conf.d" - pool_conf_dir = "/etc/php5/fpm/pool.d" - if node.platform == "ubuntu" and node.platform_version.to_f <= 10.04 - conf_file = "/etc/php5/fpm/php5-fpm.conf" + if platform?('ubuntu') and node.platform_version.to_f >= 16.04 + php_conf_dir = "/etc/php/7.0" + php_fpm_name = "php7.0-fpm" else - conf_file = "/etc/php5/fpm/php-fpm.conf" + php_conf_dir = "/etc/php5" + php_fpm_name = "php5-fpm" end - error_log = "/var/log/php5-fpm.log" - pid ="/var/run/php5-fpm.pid" + conf_dir = "#{php_conf_dir}/fpm/conf.d" + pool_conf_dir = "#{php_conf_dir}/fpm/pool.d" + if node.platform == "ubuntu" and node.platform_version.to_f <= 10.04 + conf_file = "#{php_conf_dir}/fpm/php5-fpm.conf" + else + conf_file = "#{php_conf_dir}/fpm/php-fpm.conf" + end + error_log = "/var/log/#{php_fpm_name}.log" + pid = "/var/run/#{php_fpm_name}.pid" end default['php-fpm']['user'] = user @@ -28,11 +35,23 @@ default['php-fpm']['pool_conf_dir'] = pool_conf_dir default['php-fpm']['conf_file'] = conf_file default['php-fpm']['pid'] = pid default['php-fpm']['log_dir'] = '/var/log/php-fpm' -default['php-fpm']['error_log'] = error_log +default['php-fpm']['error_log'] = error_log default['php-fpm']['log_level'] = "notice" default['php-fpm']['emergency_restart_threshold'] = 0 default['php-fpm']['emergency_restart_interval'] = 0 default['php-fpm']['process_control_timeout'] = 0 +default['php-fpm']['process_manager'] = 'ondemand' +default['php-fpm']['max_children'] = 50 +default['php-fpm']['start_servers'] = 5 +default['php-fpm']['min_spare_servers'] = 5 +default['php-fpm']['max_spare_servers'] = 35 +default['php-fpm']['max_requests'] = 0 +default['php-fpm']['request_terminate_timeout'] = 0 +default['php-fpm']['catch_workers_output'] = 'no' +default['php-fpm']['security_limit_extensions'] = '.php' +default['php-fpm']['listen_mode'] = '0660' +default['php-fpm']['listen'] = "/var/run/php-fpm-%{pool_name}.sock" + default['php-fpm']['pools'] = { "www" => { :enable => true diff --git a/cookbooks/php-fpm/chefignore b/cookbooks/php-fpm/chefignore deleted file mode 100644 index c37aacd..0000000 --- a/cookbooks/php-fpm/chefignore +++ /dev/null @@ -1,101 +0,0 @@ -# Put files/directories that should be ignored in this file when uploading -# or sharing to the community site. -# Lines that start with '# ' are comments. - -# OS generated files # -###################### -.DS_Store -Icon? -nohup.out -ehthumbs.db -Thumbs.db - -# SASS # -######## -.sass-cache - -# EDITORS # -########### -\#* -.#* -*~ -*.sw[a-z] -*.bak -REVISION -TAGS* -tmtags -*_flymake.* -*_flymake -*.tmproj -.project -.settings -mkmf.log - -## COMPILED ## -############## -a.out -*.o -*.pyc -*.so -*.com -*.class -*.dll -*.exe -*/rdoc/ - -# Testing # -########### -.watchr -.rspec -spec/* -spec/fixtures/* -test/* -features/* -Guardfile -Procfile - -# SCM # -####### -.git -*/.git -.gitignore -.gitmodules -.gitconfig -.gitattributes -.svn -*/.bzr/* -*/.hg/* -*/.svn/* - -# Berkshelf # -############# -Berksfile -Berksfile.lock -cookbooks/* -tmp - -# Cookbooks # -############# -CONTRIBUTING -CHANGELOG* - -# Strainer # -############ -Colanderfile -Strainerfile -.colander -.strainer - -# Vagrant # -########### -.vagrant -Vagrantfile - -# Travis # -########## -.travis.yml - -# Other # -########## -.sandbox -.bundle diff --git a/cookbooks/php-fpm/definitions/php_fpm_pool.rb b/cookbooks/php-fpm/definitions/php_fpm_pool.rb index ae7c2b6..edd1b0e 100644 --- a/cookbooks/php-fpm/definitions/php_fpm_pool.rb +++ b/cookbooks/php-fpm/definitions/php_fpm_pool.rb @@ -33,24 +33,26 @@ define :php_fpm_pool, :template => "pool.conf.erb", :enable => true do cookbook params[:cookbook] || "php-fpm" variables( :pool_name => pool_name, - :listen => params[:listen], + :listen => params[:listen] || node['php-fpm']['listen'].gsub(%r[%{pool_name}], pool_name), :listen_owner => params[:listen_owner] || node['php-fpm']['listen_owner'] || node['php-fpm']['user'], :listen_group => params[:listen_group] || node['php-fpm']['listen_group'] || node['php-fpm']['group'], :listen_mode => params[:listen_mode] || node['php-fpm']['listen_mode'], :allowed_clients => params[:allowed_clients], - :user => params[:user], - :group => params[:group], - :process_manager => params[:process_manager], - :max_children => params[:max_children], - :start_servers => params[:start_servers], - :min_spare_servers => params[:min_spare_servers], - :max_spare_servers => params[:max_spare_servers], - :max_requests => params[:max_requests], - :catch_workers_output => params[:catch_workers_output], + :user => params[:user] || node['php-fpm']['user'], + :group => params[:group] || node['php-fpm']['group'], + :process_manager => params[:process_manager] || node['php-fpm']['process_manager'], + :max_children => params[:max_children] || node['php-fpm']['max_children'], + :start_servers => params[:start_servers] || node['php-fpm']['start_servers'], + :min_spare_servers => params[:min_spare_servers] || node['php-fpm']['min_spare_servers'], + :max_spare_servers => params[:max_spare_servers] || node['php-fpm']['max_spare_servers'], + :max_requests => params[:max_requests] || node['php-fpm']['max_requests'], + :catch_workers_output => params[:catch_workers_output] || node['php-fpm']['catch_workers_output'], :security_limit_extensions => params[:security_limit_extensions] || node['php-fpm']['security_limit_extensions'], :access_log => params[:access_log] || false, + :slowlog => params[:slowlog] || false, + :request_slowlog_timeout => params[:request_slowlog_timeout] || false, :php_options => params[:php_options] || {}, - :request_terminate_timeout => params[:request_terminate_timeout], + :request_terminate_timeout => params[:request_terminate_timeout] || node['php-fpm']['request_terminate_timeout'], :params => params ) notifies :restart, "service[php-fpm]" diff --git a/cookbooks/php-fpm/metadata.json b/cookbooks/php-fpm/metadata.json new file mode 100644 index 0000000..7a31308 --- /dev/null +++ b/cookbooks/php-fpm/metadata.json @@ -0,0 +1,37 @@ +{ + "name": "php-fpm", + "version": "0.7.8", + "description": "Installs/Configures php-fpm", + "long_description": "Description\n===========\n\nInstalls and configures PHP-FPM (FastCGI Process Manager), an alternative PHP FastCGI implementation with some additional features useful for sites of any size, especially busier sites. It's like the `unicorn` of the PHP world dawg.\n\nRequirements\n============\n\nPlatform\n--------\n\n* Debian, Ubuntu\n* CentOS, Red Hat, Fedora\n* Amazon Linux\n\nCookbooks\n---------\n\n* apt (leverages apt_repository LWRP)\n* yum (leverages yum_repository LWRP)\n\nThe `apt_repository` and `yum_repository` LWRPs are used from these cookbooks to create the proper repository entries so the php-fpm package downloaded and installed.\n\nDescription\n==========\n\nCreates a PHP-FPM configuration file at the path specified. Meant to be deployed with a service init scheme/supervisor such as runit. Please see the `application::php-fpm` recipe for a complete working example. In depth information about PHP-FPM's configuration values can be [found in the PHP-FPM documentation](http://php.net/manual/en/install.fpm.configuration.php).\n\nUsage\n=====\nSimply include the recipe where you want PHP-FPM installed. Default pool __www__ will be created. To disable pool creation set default['php-fpm']['pools'] to false.\n\nTo customize settings and pools you can override default attributes.\n\n### Usage in roles:\n```ruby\nname \"php-fpm\"\ndescription \"php fpm role\"\nrun_list \"recipe[php-fpm]\"\noverride_attributes \"php-fpm\" => {\n\t\"pools\" => {\n\t\t\"default\" => {\n\t\t\t:enable => true\n\t\t},\n\t\t\"www\" => {\n\t\t\t:enable => \"true\",\n\t\t\t:cookbook => \"another-cookbook\",\n\t\t\t:process_manager => \"dynamic\",\n\t\t\t:max_requests => 5000,\n\t\t\t:php_options => { 'php_admin_flag[log_errors]' => 'on', 'php_admin_value[memory_limit]' => '32M' }\n\t\t}\n\t}\n}\n```\n\nCreating pools in recipes\n=========================\n### Create PHP-FPM pool named 'www' with default settings:\n```ruby\nphp_fpm_pool \"www\"\n```\n\n### Create PHP-FPM pool named 'www' with custom settings:\n```ruby\nphp_fpm_pool \"www\" do\n cookbook \"another-cookbook\" # get template from another cookbook\n process_manager \"dynamic\"\n max_requests 5000\n php_options 'php_admin_flag[log_errors]' => 'on', 'php_admin_value[memory_limit]' => '32M'\nend\n```\n\n### Delete PHP-FPM pool named 'www':\n```ruby\nphp_fpm_pool \"www\" do\n enable false\nend\n```\n\nDevelopment\n===========\n\n### Requirements\n\n* [Docker](https://www.docker.com/)\n\n### Setup\n\nTo get all dependencies:\n\n```\nbundle install\n```\n\n### Test\n\nTo see available platforms:\n\n```\nbundle exec rake -T\n```\n\nTo test particular platform:\n\n```\nbundle exec rake kitchen:default-ubuntu-1604\n```\n\nTo test all platforms:\n\n```\nbundle exec rake kitchen:all\n```\n\n### Publishing (maintainers only!)\n\nBump version in metadata.rb, commit and push to master!\n\n```\nbundle exec rake publish\n```\n\nas a result new tag will be created and pushed to github as well as new version\nwill be published on https://supermarket.chef.io\n\nContributing\n===========\n\nPlease do not bump version when proposing a change, no other rules ;)\n\nLicense and Author\n==================\n\nAuthor:: Seth Chisamore ()\n\nCopyright:: 2011, Opscode, Inc\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n", + "maintainer": "Opscode, Inc.", + "maintainer_email": "cookbooks@opscode.com", + "license": "Apache 2.0", + "platforms": { + "debian": ">= 0.0.0", + "ubuntu": ">= 0.0.0", + "centos": ">= 0.0.0", + "redhat": ">= 0.0.0", + "fedora": ">= 0.0.0", + "amazon": ">= 0.0.0" + }, + "dependencies": { + "apt": ">= 0.0.0", + "yum": ">= 3.0" + }, + "recommendations": { + }, + "suggestions": { + }, + "conflicting": { + }, + "providing": { + }, + "replacing": { + }, + "attributes": { + }, + "groupings": { + }, + "recipes": { + } +} \ No newline at end of file diff --git a/cookbooks/php-fpm/metadata.rb b/cookbooks/php-fpm/metadata.rb deleted file mode 100644 index e5029e0..0000000 --- a/cookbooks/php-fpm/metadata.rb +++ /dev/null @@ -1,14 +0,0 @@ -name "php-fpm" -maintainer "Opscode, Inc." -maintainer_email "cookbooks@opscode.com" -license "Apache 2.0" -description "Installs/Configures php-fpm" -long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) -version "0.7.5" - -depends "apt" -depends "yum", ">= 3.0" - -%w{ debian ubuntu centos redhat fedora amazon }.each do |os| - supports os -end diff --git a/cookbooks/php-fpm/recipes/install.rb b/cookbooks/php-fpm/recipes/install.rb index 981b6e8..922590e 100644 --- a/cookbooks/php-fpm/recipes/install.rb +++ b/cookbooks/php-fpm/recipes/install.rb @@ -24,6 +24,8 @@ include_recipe 'apt::default' if node['platform_family'] == 'debian' if node['php-fpm']['package_name'].nil? if platform_family?("rhel", "fedora") php_fpm_package_name = "php-fpm" + elsif platform?('ubuntu') and node['platform_version'].to_f >= 16.04 + php_fpm_package_name = "php7.0-fpm" else php_fpm_package_name = "php5-fpm" end @@ -42,9 +44,16 @@ else php_fpm_service_name = node['php-fpm']['service_name'] end +service_provider = nil +# this is actually already done in chef, but is kept here for older chef releases +if platform?('ubuntu') and node['platform_version'].to_f.between?(13.10, 14.10) + service_provider = ::Chef::Provider::Service::Upstart +end + directory node['php-fpm']['log_dir'] service "php-fpm" do + provider service_provider if service_provider service_name php_fpm_service_name supports :start => true, :stop => true, :restart => true, :reload => true action [ :enable, :start ] diff --git a/cookbooks/php-fpm/recipes/repository.rb b/cookbooks/php-fpm/recipes/repository.rb index dfabb07..6df2347 100644 --- a/cookbooks/php-fpm/recipes/repository.rb +++ b/cookbooks/php-fpm/recipes/repository.rb @@ -38,10 +38,18 @@ when 'debian' # Configure Dotdeb repos # TODO: move this to it's own 'dotdeb' cookbook? # http://www.dotdeb.org/instructions/ - if node.platform_version.to_f >= 7.0 + if node.platform_version.to_f >= 8.0 apt_repository "dotdeb" do uri node['php-fpm']['dotdeb_repository']['uri'] - distribution "stable" + distribution "jessie" + components ['all'] + key node['php-fpm']['dotdeb_repository']['key'] + action :add + end + elsif node.platform_version.to_f >= 7.0 + apt_repository "dotdeb" do + uri node['php-fpm']['dotdeb_repository']['uri'] + distribution "wheezy" components ['all'] key node['php-fpm']['dotdeb_repository']['key'] action :add diff --git a/cookbooks/php-fpm/recipes/test.rb b/cookbooks/php-fpm/recipes/test.rb new file mode 100644 index 0000000..eff3d5f --- /dev/null +++ b/cookbooks/php-fpm/recipes/test.rb @@ -0,0 +1,3 @@ +include_recipe 'php-fpm::default' + +package 'net-tools' diff --git a/cookbooks/php-fpm/templates/default/pool.conf.erb b/cookbooks/php-fpm/templates/default/pool.conf.erb index 78cafe0..ec4fbf3 100644 --- a/cookbooks/php-fpm/templates/default/pool.conf.erb +++ b/cookbooks/php-fpm/templates/default/pool.conf.erb @@ -19,8 +19,8 @@ ; Unix user/group of processes ; Note: The user is mandatory. If the group is not set, the default user's group ; will be used. -user = <%= @user || node['php-fpm']['user'] %> -group = <%= @group || node['php-fpm']['group'] %> +user = <%= @user %> +group = <%= @group %> ; The address on which to accept FastCGI requests. ; Valid syntaxes are: @@ -30,7 +30,7 @@ group = <%= @group || node['php-fpm']['group'] %> ; specific port; ; '/path/to/unix/socket' - to listen on a unix socket. ; Note: This value is mandatory. -listen = <%= @listen || "/var/run/php-fpm-#{@pool_name}.sock" %> +listen = <%= @listen %> ; Set listen(2) backlog. ; Default Value: 128 (-1 on FreeBSD and OpenBSD) @@ -52,7 +52,7 @@ listen.owner = <%= @listen_owner %> listen.group = <%= @listen_group %> <% end %> -listen.mode = <%= @listen_mode || "0660" %> +listen.mode = <%= @listen_mode %> ; List of ipv4 addresses of FastCGI clients which are allowed to connect. ; Equivalent to the FCGI_WEB_SERVER_ADDRS environment variable in the original @@ -94,7 +94,7 @@ listen.allowed_clients = <%= @allowed_clients ? ([@allowed_clients].flatten.join ; pm.process_idle_timeout - The number of seconds after which ; an idle process will be killed. ; Note: This value is mandatory. -pm = <%= @process_manager || "ondemand" %> +pm = <%= @process_manager %> ; The number of child processes to be created when pm is set to 'static' and the ; maximum number of child processes when pm is set to 'dynamic' or 'ondemand'. @@ -105,7 +105,7 @@ pm = <%= @process_manager || "ondemand" %> ; forget to tweak pm.* to fit your needs. ; Note: Used when pm is set to 'static', 'dynamic' or 'ondemand' ; Note: This value is mandatory. -pm.max_children = <%= @max_children || 50 %> +pm.max_children = <%= @max_children %> <% if @process_manager == "dynamic" %> ; The number of child processes created on startup. @@ -118,12 +118,12 @@ pm.start_servers = <%= @start_servers %> ; The desired minimum number of idle server processes. ; Note: Used only when pm is set to 'dynamic' ; Note: Mandatory when pm is set to 'dynamic' -pm.min_spare_servers = <%= @min_spare_servers || 5 %> +pm.min_spare_servers = <%= @min_spare_servers %> ; The desired maximum number of idle server processes. ; Note: Used only when pm is set to 'dynamic' ; Note: Mandatory when pm is set to 'dynamic' -pm.max_spare_servers = <%= @max_spare_servers || 35 %> +pm.max_spare_servers = <%= @max_spare_servers %> <% end %> <% if @process_manager == "ondemand" %> @@ -137,7 +137,7 @@ pm.max_spare_servers = <%= @max_spare_servers || 35 %> ; This can be useful to work around memory leaks in 3rd party libraries. For ; endless request processing specify '0'. Equivalent to PHP_FCGI_MAX_REQUESTS. ; Default Value: 0 -pm.max_requests = <%= @max_requests || 500 %> +pm.max_requests = <%= @max_requests %> ; The URI to view the FPM status page. If this value is not set, no URI will be ; recognized as a status page. It shows the following informations: @@ -319,20 +319,28 @@ access.log = <%= node['php-fpm']['log_dir'] %>/$pool.access.log ; The log file for slow requests ; Default Value: not set ; Note: slowlog is mandatory if request_slowlog_timeout is set +<% if @slowlog %> +slowlog = <%= @slowlog %> +<% else %> ;slowlog = log/$pool.log.slow +<% end %> ; The timeout for serving a single request after which a PHP backtrace will be ; dumped to the 'slowlog' file. A value of '0s' means 'off'. ; Available units: s(econds)(default), m(inutes), h(ours), or d(ays) ; Default Value: 0 +<% if @request_slowlog_timeout %> +request_slowlog_timeout = <%=@request_slowlog_timeout %> +<% else %> ;request_slowlog_timeout = 0 +<% end %> ; The timeout for serving a single request after which the worker process will ; be killed. This option should be used when the 'max_execution_time' ini option ; does not stop script execution for some reason. A value of '0' means 'off'. ; Available units: s(econds)(default), m(inutes), h(ours), or d(ays) ; Default Value: 0 -request_terminate_timeout = <%=@request_terminate_timeout || 0 %> +request_terminate_timeout = <%=@request_terminate_timeout %> ; Set open file descriptor rlimit. ; Default Value: system defined value @@ -364,7 +372,7 @@ request_terminate_timeout = <%=@request_terminate_timeout || 0 %> ; Note: on highloaded environement, this can cause some delay in the page ; process time (several ms). ; Default Value: no -catch_workers_output = <%= @catch_workers_output || "no" %> +catch_workers_output = <%= @catch_workers_output %> <% if node['platform'] != 'ubuntu' && node['platform_version'] != '10.04' %> ; Limits the extensions of the main script FPM will allow to parse. This can @@ -374,7 +382,7 @@ catch_workers_output = <%= @catch_workers_output || "no" %> ; Note: set an empty value to allow all extensions. ; Default Value: .php ;security.limit_extensions = .php .php3 .php4 .php5 -security.limit_extensions = <%=@security_limit_extensions || ".php" %> +security.limit_extensions = <%=@security_limit_extensions %> <% end %> ; Pass environment variables like LD_LIBRARY_PATH. All $VARIABLEs are taken from diff --git a/cookbooks/php-fpm/test/integration/default/serverspec/pools_spec.rb b/cookbooks/php-fpm/test/integration/default/serverspec/pools_spec.rb deleted file mode 100644 index 2abb44d..0000000 --- a/cookbooks/php-fpm/test/integration/default/serverspec/pools_spec.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'serverspec' - -set :backend, :exec - -describe port(9081) do - it { should be_listening } -end diff --git a/cookbooks/php/CHANGELOG.md b/cookbooks/php/CHANGELOG.md index b56c711..64e1e44 100644 --- a/cookbooks/php/CHANGELOG.md +++ b/cookbooks/php/CHANGELOG.md @@ -1,25 +1,102 @@ -php Cookbook CHANGELOG -====================== +# php Cookbook CHANGELOG + This file is used to list changes made in each version of the php cookbook. -v1.7.2 (2015-8-24) ------------------- +## 3.0.0 (2017-03-27) +- Converted pear_channel LWRP into custom resource +- Removed use of pear node attribute from pear_channel resource +- Fix cookstyle issue with missing line on metadata.rb +- Clean up kitchen.dokken.yml file to eliminate duplication of testing suites. +- Eliminate duplicated resource from test cookbook that is in the default recipe. +- Rename php-test to standard cookbook testing cookbook of "test" +- Remove EOL ubuntu platform logic +**NOTE** Windows package installation is currently broken. + +## 2.2.1 (2017-02-21) + +- Fix double definition of ['php']['packages'] for rhel. + +## 2.2.0 (2016-12-12) + +- Use multipackage for installs to speed up chef runs +- Use all CPUs when building from source +- Remove need for apt/yum in testing +- Add opensuse to the metadata +- Migrate to inspec for integration testing + +## 2.1.1 (2016-09-15) + +- Fix recompile un-pack php creates +- Resolve cookstyle warnings + +## 2.1.0 (2016-09-14) + +- Fix source php version check +- Require Chef 12.1 not 12.0 + +## 2.0.0 (2016-09-07) + +- Require Chef 12+ +- Remove the dependency on the Windows cookbook which isn't necessary with Chef 12+ + +## 1.10.1 (2016-08-30) + +- [fix] bug fixes related with Ubuntu 16.04 and PHP 7 support +- adding validator to listen attribute +- Fix node.foo.bar warnings + +## v1.10.0 (2016-07-27) + +- PR #167 Preventing user specified pool of www from being deleted at the end of the chef run on the first install +- PR #122 Add recipe for php module_imap +- PR #172 Fix uninstall action for resource php_fpm_pool + +## v1.9.0 (2016-05-12) + +Special thanks to @ThatGerber for getting the PR for this release together + +- Added support for Ubuntu 16.04 and PHP 7 +- Added support for different listen user/groups with FPM +- Cleaned up resource notification in the pear_channel provider to simplify code +- Fixed Ubuntu 14.04+ not being able to find the GMP library + +## v1.8.0 (2016-02-25) + +- Bumped the source install default version from 5.5.9 to 5.6.13 +- Added a chefignore file to limit the files uploaded to the Chef server +- Added source_url and issues_url to the metadata.rb +- Added additional Chefspec matchers +- Added a Chef standard rubocop.yml file and resolved warnings +- Added serverspec for integration testing +- Remove legacy cloud Test Kitchen configs +- Added testing in Travis CI with kitchen-docker +- Added additional test suites to the Test Kitchen config +- Updated contributing and testing documentation +- Updated testing gem dependencies to the latest +- Added maintainers.md and maintainers.toml files +- Remove gitter chat from the readme +- Add cookbook version badge to the readme +- Added Fedora as a supported platform in the readme +- Add missing cookbook dependencies to the readme + +## v1.7.2 (2015-8-24) + - Correct spelling in fpm_pool_start_servers (was servres) -v1.7.1 (2015-8-17) ------------------- +## v1.7.1 (2015-8-17) + - Correct permissions on ext_conf_dir folder (644 -> 755) -v1.7.0 (2015-7-31) ------------------- +## v1.7.0 (2015-7-31) + - NOTICE - This version changes the way the ['php']['directives'] is placed into configuration files. Quotes are no longer automatically placed around these aditional directives. Please take care when rolling out this version. - Allow additional PHP FPM config - Add recipe to recompile PHP from source - Move source dependencies to attributes file - Misc bug fixes -v1.6.0 (2015-7-6) ------------------ +## v1.6.0 (2015-7-6) + - Added ChefSpec matchers - Added basic PHP-FPM Support (Pre-Release) - Added support for FreeBSD @@ -27,138 +104,134 @@ v1.6.0 (2015-7-6) - Update cookbook to use php5enmod on supported platforms - Allow users to override php-mysql package -v1.5.0 (2014-10-06) -------------------- +## v1.5.0 (2014-10-06) + - Adding package_options attribute, utilizing in package resource -v1.4.6 (2014-03-19) -------------------- +## v1.4.6 (2014-03-19) + - [COOK-4436] - Test this cookbook, not yum. Also test Fedora 20. - [COOK-4427] - Add oracle as supported operating system +## v1.4.4 (2014-03-12) -v1.4.4 (2014-03-12) -------------------- - [COOK-4393] - Fix convergence bug in source install +## v1.4.2 (2014-02-27) -v1.4.2 (2014-02-27) -------------------- [COOK-4300] - Simplified and fixed pear/pecl logic. [Fixes #56 / #57] +## v1.4.0 (2014-02-27) -v1.4.0 (2014-02-27) -------------------- [COOK-3639] - Allow users to specify php.ini source template +## v1.3.14 (2014-02-21) -v1.3.14 (2014-02-21) --------------------- ### Bug + - **[COOK-4186](https://tickets.opscode.com/browse/COOK-4186)** - Upgrade_package concatenates an empty version string when version is not set or is empty. +## v1.3.12 (2014-01-28) -v1.3.12 (2014-01-28) --------------------- Fix github issue 'Cannot find a resource for preferred_state' +## v1.3.10 -v1.3.10 -------- Fixing my stove +## v1.3.8 -v1.3.8 ------- Version bump to ensure artifact sanity +## v1.3.6 -v1.3.6 ------- Version bump for toolchain +## v1.3.4 -v1.3.4 ------- Adding platform_family check to include_recipe in source.rb +## v1.3.2 -v1.3.2 ------- Fixing style cops. Updating test harness +## v1.3.0 -v1.3.0 ------- ### Bug + - **[COOK-3479](https://tickets.opscode.com/browse/COOK-3479)** - Added Windows support to PHP - **[COOK-2909](https://tickets.opscode.com/browse/COOK-2909)** - Warnings about Chef::Exceptions::ShellCommandFailed is deprecated +## v1.2.6 -v1.2.6 ------- ### Bug + - **[COOK-3628](https://tickets.opscode.com/browse/COOK-3628)** - Fix PHP download URL - **[COOK-3568](https://tickets.opscode.com/browse/COOK-3568)** - Fix Test Kitchen tests - **[COOK-3402](https://tickets.opscode.com/browse/COOK-3402)** - When the `ext_dir` setting is present, configure php properly for the source recipe - **[COOK-2926](https://tickets.opscode.com/browse/COOK-2926)** - Fix pear package detection when installing specific version +## v1.2.4 -v1.2.4 ------- ### Improvement + - **[COOK-3047](https://tickets.opscode.com/browse/COOK-3047)** - Sort directives in `php.ini` - **[COOK-2928](https://tickets.opscode.com/browse/COOK-2928)** - Abstract `php.ini` directives into variables ### Bug + - **[COOK-2378](https://tickets.opscode.com/browse/COOK-2378)** - Fix `php_pear` for libevent -v1.2.2 ------- +## v1.2.2 + ### Bug + - [COOK-3050]: `lib_dir` declared in wrong place for redhat - [COOK-3102]: remove fileinfo recipe from php cookbook ### Improvement + - [COOK-3101]: use a method to abstract range of "el 5" versions in php recipes -v1.2.0 ------- +## v1.2.0 + ### Improvement + - [COOK-2516]: Better support for SUSE distribution for php cookbook - [COOK-3035]: update php::source to install 5.4.15 by default ### Bug + - [COOK-2463]: PHP PEAR Provider Installs Most Recent Version, Without Respect to Preferred State - [COOK-2514]: php_pear: does not handle more exotic version strings -v1.1.8 ------- +## v1.1.8 + - [COOK-1998] - Enable override of PHP packages in attributes -v1.1.6 ------- +## v1.1.6 + - [COOK-2324] - adds Oracle linux support -v1.1.4 ------- +## v1.1.4 + - [COOK-2106] - `php_pear` cannot find available packages -v1.1.2 ------- +## v1.1.2 + - [COOK-1803] - use better regexp to match package name - [COOK-1926] - support Amazon linux -v1.1.0 ------- +## v1.1.0 + - [COOK-543] - php.ini template should be configurable - [COOK-1067] - support for PECL zend extensions - [COOK-1193] - update package names for EPEL 6 - [COOK-1348] - rescue Mixlib::ShellOut::ShellCommandFailed (chef 0.10.10) - [COOK-1465] - fix pear extension template -v1.0.2 ------- +## v1.0.2 + - [COOK-993] Add mhash-devel to centos php source libs - [COOK-989] - bump version of php to 5.3.10 - Also download the .tar.gz instead of .tar.bz2 as bzip2 may not be in the base OS (e.g., CentOS 6 minimal) diff --git a/cookbooks/compat_resource/CONTRIBUTING.md b/cookbooks/php/CONTRIBUTING.md similarity index 100% rename from cookbooks/compat_resource/CONTRIBUTING.md rename to cookbooks/php/CONTRIBUTING.md diff --git a/cookbooks/compat_resource/MAINTAINERS.md b/cookbooks/php/MAINTAINERS.md similarity index 87% rename from cookbooks/compat_resource/MAINTAINERS.md rename to cookbooks/php/MAINTAINERS.md index 5ae0806..645ed14 100644 --- a/cookbooks/compat_resource/MAINTAINERS.md +++ b/cookbooks/php/MAINTAINERS.md @@ -7,10 +7,9 @@ This file lists how this cookbook project is maintained. When making changes to Check out [How Cookbooks are Maintained](https://github.com/chef-cookbooks/community_cookbook_documentation/blob/master/CONTRIBUTING.MD) for details on the process and how to become a maintainer or the project lead. # Project Maintainer -* [Lamont Granquist](https://github.com/lamont-granquist) +* [Tim Smith](https://github.com/tas50) # Maintainers * [Jennifer Davis](https://github.com/sigje) * [Tim Smith](https://github.com/tas50) * [Thom May](https://github.com/thommay) -* [Lamont Granquist](https://github.com/lamont-granquist) diff --git a/cookbooks/php/README.md b/cookbooks/php/README.md index cdd1195..3967465 100644 --- a/cookbooks/php/README.md +++ b/cookbooks/php/README.md @@ -1,47 +1,40 @@ -php Cookbook -============ +# php Cookbook +[![Build Status](https://travis-ci.org/chef-cookbooks/php.svg?branch=master)](http://travis-ci.org/chef-cookbooks/php) [![Cookbook Version](https://img.shields.io/cookbook/v/php.svg)](https://supermarket.chef.io/cookbooks/php) -[![Join the chat at https://gitter.im/opscode-cookbooks/php](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/opscode-cookbooks/php?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) -[![Cookbook Version](https://img.shields.io/cookbook/v/php.svg)](https://supermarket.chef.io/cookbooks/php) -[![Build Status](https://travis-ci.org/opscode-cookbooks/php.svg?branch=master)](https://travis-ci.org/opscode-cookbooks/php) +It installs and configures PHP and the PEAR package management system. Also includes resources for managing PEAR (and PECL) packages, PECL channels, and PHP-FPM pools. -Installs and configures PHP 5.3 and the PEAR package management system. Also includes LWRPs for managing PEAR (and PECL) packages, PECL channels, and PHP-FPM pools. - -Requirements ------------- +## Requirements ### Platforms - Debian, Ubuntu -- CentOS, Red Hat, Fedora, Amazon Linux -- Microsoft Windows +- CentOS, Red Hat, Oracle, Scientific, Amazon Linux +- Fedora +- Microsoft Windows + +### Chef +- Chef 12.1+ ### Cookbooks - build-essential - xml - mysql +- iis +- windows -These cookbooks are only used when building PHP from source. - - -Attributes ----------- +## Attributes - `node['php']['install_method']` = method to install php with, default `package`. - `node['php']['directives']` = Hash of directives and values to append to `php.ini`, default `{}`. The file also contains the following attribute types: +- platform specific locations and settings. +- source installation settings -* platform specific locations and settings. -* source installation settings - - -Resource/Provider ------------------ +## Resource/Provider This cookbook includes LWRPs for managing: - - PEAR channels - PEAR/PECL packages ### `php_pear_channel` -[PEAR Channels](http://pear.php.net/manual/en/guide.users.commandline.channels.php) are alternative sources for PEAR packages. This LWRP provides and easy way to manage these channels. +[PEAR Channels](http://pear.php.net/manual/en/guide.users.commandline.channels.php) are alternative sources for PEAR packages. This resource provides and easy way to manage these channels. #### Actions - :discover: Initialize a channel from its server. @@ -52,8 +45,10 @@ This cookbook includes LWRPs for managing: #### Attribute Parameters - channel_name: name attribute. The name of the channel to discover - channel_xml: the channel.xml file of the channel you are adding +- pear: pear binary, default: pear #### Examples + ```ruby # discover the horde channel php_pear_channel "pear.horde.org" do @@ -85,20 +80,21 @@ end [PEAR](http://pear.php.net/) is a framework and distribution system for reusable PHP components. [PECL](http://pecl.php.net/) is a repository for PHP Extensions. PECL contains C extensions for compiling into PHP. As C programs, PECL extensions run more efficiently than PEAR packages. PEARs and PECLs use the same packaging and distribution system. As such this LWRP is clever enough to abstract away the small differences and can be used for managing either. This LWRP also creates the proper module .ini file for each PECL extension at the correct location for each supported platform. #### Actions -- :install: Install a pear package - if version is provided, install that specific version -- :upgrade: Upgrade a pear package - if version is provided, upgrade to that specific version -- :remove: Remove a pear package -- :purge: Purge a pear package (this usually entails removing configuration files as well as the package itself). With pear packages this behaves the same as `:remove` +- `:install`: Install a pear package - if version is provided, install that specific version +- `:upgrade`: Upgrade a pear package - if version is provided, upgrade to that specific version +- `:remove`: Remove a pear package +- `:purge`: Purge a pear package (this usually entails removing configuration files as well as the package itself). With pear packages this behaves the same as `:remove` #### Attribute Parameters -- package_name: name attribute. The name of the pear package to install +- `package_name`: name attribute. The name of the pear package to install - version: the version of the pear package to install/upgrade. If no version is given latest is assumed. -- preferred_state: PEAR by default installs stable packages only, this allows you to install pear packages in a devel, alpha or beta state -- directives: extra extension directives (settings) for a pecl. on most platforms these usually get rendered into the extension's .ini file -- zend_extensions: extension filenames which should be loaded with zend_extension. -- options: Add additional options to the underlying pear package command +- `preferred_state`: PEAR by default installs stable packages only, this allows you to install pear packages in a devel, alpha or beta state +- `directives`: extra extension directives (settings) for a pecl. on most platforms these usually get rendered into the extension's .ini file +- `zend_extensions`: extension filenames which should be loaded with zend_extension. +- o`ptions`: Add additional options to the underlying pear package command #### Examples + ```ruby # upgrade a pear php_pear "XML_RPC" do @@ -156,35 +152,31 @@ end ``` ### `php_fpm_pool` -Installs the `php-fpm` package appropriate for your distro (if using packages) -and configures a FPM pool for you. Currently only supported in Debian-family -operating systems and CentOS 7 (or at least tested with such, YMMV if you are -using source). +Installs the `php-fpm` package appropriate for your distro (if using packages) and configures a FPM pool for you. Currently only supported in Debian-family operating systems and CentOS 7 (or at least tested with such, YMMV if you are using source). Please consider FPM functionally pre-release, and test it thoroughly in your environment before using it in production -More info: http://php.net/manual/en/install.fpm.php +More info: [http://php.net/manual/en/install.fpm.php](http://php.net/manual/en/install.fpm.php) #### Actions -- :install: Installs the FPM pool (default). -- :uninstall: Removes the FPM pool. +- `:install`: Installs the FPM pool (default). +- `:uninstall`: Removes the FPM pool. #### Attribute Parameters -- pool_name: name attribute. The name of the FPM pool. -- listen: The listen address. Default: `/var/run/php5-fpm.sock` -- user: The user to run the FPM under. Default should be the webserver user for - your distro. -- group: The group to run the FPM under. Default should be the webserver group - for your distro. -- process_manager: Process manager to use - see - http://php.net/manual/en/install.fpm.configuration.php. Default: `dynamic` -- max_children: Max children to scale to. Default: 5 -- start_servers: Number of servers to start the pool with. Default: 2 -- min_spare_servers: Minimum number of servers to have as spares. Default: 1 -- max_spare_servers: Maximum number of servers to have as spares. Default: 3 -- chdir: The startup working directory of the pool. Default: `/` +- `pool_name`: name attribute. The name of the FPM pool. +- `listen`: The listen address. Default: `/var/run/php5-fpm.sock` +- `user`: The user to run the FPM under. Default should be the webserver user for your distro. +- `group`: The group to run the FPM under. Default should be the webserver group for your distro. +- `process_manager`: Process manager to use - see [http://php.net/manual/en/install.fpm.configuration.php](http://php.net/manual/en/install.fpm.configuration.php). Default: `dynamic` +- `max_children`: Max children to scale to. Default: 5 +- `start_servers`: Number of servers to start the pool with. Default: 2 +- `min_spare_servers`: Minimum number of servers to have as spares. Default: 1 +- `max_spare_servers`: Maximum number of servers to have as spares. Default: 3 +- `chdir`: The startup working directory of the pool. Default: `/` +- `additional_config`: Additional parameters in JSON. Default: {} #### Examples + ```ruby # Install a FPM pool named "default" php_fpm_pool "default" do @@ -192,8 +184,7 @@ php_fpm_pool "default" do end ``` -Recipes -------- +## Recipes ### default Include the default recipe in a run list, to get `php`. By default `php` is installed from packages but this can be changed by using the `install_method` attribute. @@ -203,16 +194,15 @@ This recipe installs PHP from packages. ### source This recipe installs PHP from source. - -Deprecated Recipes ------------------- +## Deprecated Recipes The following recipes are deprecated and will be removed from a future version of this cookbook. - - `module_apc` +- `module_apcu` - `module_curl` - `module_fileinfo` - `module_fpdf` - `module_gd` +- `module_imap` - `module_ldap` - `module_memcache` - `module_mysql` @@ -233,10 +223,10 @@ php_pear "memcache" do end ``` +## Usage +Simply include the `php` recipe where ever you would like php installed. To install from source override the `node['php']['install_method']` attribute with in a role or wrapper cookbook: -Usage ------ -Simply include the `php` recipe where ever you would like php installed. To install from source override the `node['php']['install_method']` attribute with in a role: +####Role example: ```ruby name "php" @@ -251,47 +241,12 @@ run_list( ) ``` +## License & Authors +**Author:** Cookbook Engineering Team ([cookbooks@chef.io](mailto:cookbooks@chef.io)) -Development ------------ -This section details "quick development" steps. For a detailed explanation, see [[Contributing.md]]. - -1. Clone this repository from GitHub: - - $ git clone git@github.com:opscode-cookbooks/php.git - -2. Create a git branch - - $ git checkout -b my_bug_fix - -3. Install dependencies: - - $ bundle install - -4. Make your changes/patches/fixes, committing appropiately -5. **Write tests** -6. Run the tests: - - `bundle exec foodcritic -f any .` - - `bundle exec rspec` - - `bundle exec rubocop` - - `bundle exec kitchen test` - - In detail: - - Foodcritic will catch any Chef-specific style errors - - RSpec will run the unit tests - - Rubocop will check for Ruby-specific style errors - - Test Kitchen will run and converge the recipes - - -License & Authors ------------------ -- Author:: Seth Chisamore () -- Author:: Joshua Timberman () -- Author:: Julian C. Dunn () - -```text -Copyright:: 2013-2014, Chef Software, Inc. +**Copyright:** 2008-2017, Chef Software, Inc. +``` Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at @@ -305,9 +260,7 @@ See the License for the specific language governing permissions and limitations under the License. ``` -Note: This cookbook contains a modified copy of `go-phar.pear` for use on the -Microsoft Windows platform only to correct an (upstream bug)[http://pear.php.net/bugs/bug.php?id=16644]. The original -`go-pear.phar` is licensed under the (PHP License version 2.02)[http://www.php.net/license/2_02.txt]: +Note: This cookbook contains a modified copy of `go-phar.pear` for use on the Microsoft Windows platform only to correct an (upstream bug)[[http://pear.php.net/bugs/bug.php?id=16644](http://pear.php.net/bugs/bug.php?id=16644)]. The original `go-pear.phar` is licensed under the (PHP License version 2.02)[[http://www.php.net/license/2_02.txt](http://www.php.net/license/2_02.txt)]: ``` -------------------------------------------------------------------- diff --git a/cookbooks/php/attributes/default.rb b/cookbooks/php/attributes/default.rb index 233322d..3110f4a 100644 --- a/cookbooks/php/attributes/default.rb +++ b/cookbooks/php/attributes/default.rb @@ -1,9 +1,8 @@ # -# Author:: Seth Chisamore () -# Cookbook Name:: php -# Attribute:: default +# Cookbook:: php +# Attributes:: default # -# Copyright 2011-2014, Chef Software, Inc. +# Copyright:: 2011-2016, Chef Software, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -26,6 +25,26 @@ default['php']['bin'] = 'php' default['php']['pear'] = 'pear' default['php']['pecl'] = 'pecl' +default['php']['version'] = '5.6.13' + +default['php']['url'] = 'http://us1.php.net/get' +default['php']['checksum'] = '92acc6c067f5e015a6881b4119eafec10eca11722e810f2c2083f72e17119bcf' +default['php']['prefix_dir'] = '/usr/local' +default['php']['enable_mod'] = '/usr/sbin/php5enmod' +default['php']['disable_mod'] = '/usr/sbin/php5dismod' + +default['php']['ini']['template'] = 'php.ini.erb' +default['php']['ini']['cookbook'] = 'php' + +default['php']['fpm_socket'] = '/var/run/php5-fpm.sock' +default['php']['curl']['package'] = 'php5-curl' +default['php']['apc']['package'] = 'php5-apc' +default['php']['apcu']['package'] = 'php5-apcu' +default['php']['gd']['package'] = 'php5-gd' +default['php']['ldap']['package'] = 'php5-ldap' +default['php']['pgsql']['package'] = 'php5-pgsql' +default['php']['sqlite']['package'] = 'php5-sqlite3' + case node['platform_family'] when 'rhel', 'fedora' lib_dir = node['kernel']['machine'] =~ /x86_64/ ? 'lib64' : 'lib' @@ -33,35 +52,34 @@ when 'rhel', 'fedora' default['php']['ext_conf_dir'] = '/etc/php.d' default['php']['fpm_user'] = 'nobody' default['php']['fpm_group'] = 'nobody' + default['php']['fpm_listen_user'] = 'nobody' + default['php']['fpm_listen_group'] = 'nobody' default['php']['ext_dir'] = "/usr/#{lib_dir}/php/modules" default['php']['src_deps'] = %w(bzip2-devel libc-client-devel curl-devel freetype-devel gmp-devel libjpeg-devel krb5-devel libmcrypt-devel libpng-devel openssl-devel t1lib-devel mhash-devel) if node['platform_version'].to_f < 6 default['php']['packages'] = %w(php53 php53-devel php53-cli php-pear) default['php']['mysql']['package'] = 'php53-mysql' - else - default['php']['packages'] = %w(php php-devel php-cli php-pear) + else # set fpm attributes as we're on a modern PHP release + default['php']['packages'] = if node['platform'] == 'amazon' # amazon names their packages with versions + %w(php56 php56-devel php-pear) + else # redhat does not name their packages with version on RHEL 6+ + %w(php php-devel php-cli php-pear) + end default['php']['mysql']['package'] = 'php-mysql' default['php']['fpm_package'] = 'php-fpm' default['php']['fpm_pooldir'] = '/etc/php-fpm.d' - default['php']['fpm_default_conf'] = '/etc/php-fpm.d/www.conf' - default['php']['fpm_service'] = 'php-fpm' + default['php']['fpm_default_conf'] = '/etc/php-fpm.d/www.conf' + default['php']['fpm_service'] = 'php-fpm' if node['php']['install_method'] == 'package' default['php']['fpm_user'] = 'apache' default['php']['fpm_group'] = 'apache' + default['php']['fpm_listen_user'] = 'apache' + default['php']['fpm_listen_group'] = 'apache' end end when 'debian' - default['php']['conf_dir'] = '/etc/php5/cli' - case node['platform'] - when 'ubuntu' - if node['platform_version'].to_f >= 12.10 - default['php']['ext_conf_dir'] = '/etc/php5/mods-available' - else - default['php']['ext_conf_dir'] = '/etc/php5/conf.d' - end - else - default['php']['ext_conf_dir'] = '/etc/php5/conf.d' - end + default['php']['conf_dir'] = '/etc/php5/cli' + default['php']['ext_conf_dir'] = '/etc/php5/conf.d' default['php']['src_deps'] = %w(libbz2-dev libc-client2007e-dev libcurl4-gnutls-dev libfreetype6-dev libgmp3-dev libjpeg62-dev libkrb5-dev libmcrypt-dev libpng12-dev libssl-dev libt1-dev) default['php']['packages'] = %w(php5-cgi php5 php5-dev php5-cli php-pear) default['php']['mysql']['package'] = 'php5-mysql' @@ -69,20 +87,58 @@ when 'debian' default['php']['fpm_pooldir'] = '/etc/php5/fpm/pool.d' default['php']['fpm_user'] = 'www-data' default['php']['fpm_group'] = 'www-data' - default['php']['fpm_service'] = 'php5-fpm' - default['php']['fpm_default_conf'] = '/etc/php5/fpm/pool.d/www.conf' + default['php']['fpm_listen_user'] = 'www-data' + default['php']['fpm_listen_group'] = 'www-data' + default['php']['fpm_service'] = 'php5-fpm' + default['php']['fpm_default_conf'] = '/etc/php5/fpm/pool.d/www.conf' + case node['platform'] + when 'ubuntu' + case node['platform_version'].to_f + when 16.04 + default['php']['version'] = '7.0.4' + default['php']['checksum'] = 'f6cdac2fd37da0ac0bbcee0187d74b3719c2f83973dfe883d5cde81c356fe0a8' + default['php']['conf_dir'] = '/etc/php/7.0/cli' + default['php']['src_deps'] = %w(libbz2-dev libc-client2007e-dev libcurl4-gnutls-dev libfreetype6-dev libgmp3-dev libjpeg62-dev libkrb5-dev libmcrypt-dev libpng12-dev libssl-dev pkg-config) + default['php']['packages'] = %w(php7.0-cgi php7.0 php7.0-dev php7.0-cli php-pear) + default['php']['mysql']['package'] = 'php7.0-mysql' + default['php']['curl']['package'] = 'php7.0-curl' + default['php']['apc']['package'] = 'php-apc' + default['php']['apcu']['package'] = 'php-apcu' + default['php']['gd']['package'] = 'php7.0-gd' + default['php']['ldap']['package'] = 'php7.0-ldap' + default['php']['pgsql']['package'] = 'php7.0-pgsql' + default['php']['sqlite']['package'] = 'php7.0-sqlite3' + default['php']['fpm_package'] = 'php7.0-fpm' + default['php']['fpm_pooldir'] = '/etc/php/7.0/fpm/pool.d' + default['php']['fpm_service'] = 'php7.0-fpm' + default['php']['fpm_socket'] = '/var/run/php/php7.0-fpm.sock' + default['php']['fpm_default_conf'] = '/etc/php/7.0/fpm/pool.d/www.conf' + default['php']['enable_mod'] = '/usr/sbin/phpenmod' + default['php']['disable_mod'] = '/usr/sbin/phpdismod' + default['php']['ext_conf_dir'] = '/etc/php/7.0/mods-available' + when 13.04..15.10 + default['php']['ext_conf_dir'] = '/etc/php5/mods-available' + end + when 'debian' + case node['platform_version'].to_i + when 8 + default['php']['ext_conf_dir'] = '/etc/php5/mods-available' + end + end when 'suse' default['php']['conf_dir'] = '/etc/php5/cli' default['php']['ext_conf_dir'] = '/etc/php5/conf.d' default['php']['src_deps'] = %w(libbz2-dev libc-client2007e-dev libcurl4-gnutls-dev libfreetype6-dev libgmp3-dev libjpeg62-dev libkrb5-dev libmcrypt-dev libpng12-dev libssl-dev libt1-dev) default['php']['fpm_user'] = 'wwwrun' default['php']['fpm_group'] = 'www' - default['php']['packages'] = %w(apache2-mod_php5 php5-pear) + default['php']['fpm_listen_user'] = 'wwwrun' + default['php']['fpm_listen_group'] = 'www' + default['php']['packages'] = %w(apache2-mod_php5 php5-pear) default['php']['mysql']['package'] = 'php5-mysql' lib_dir = node['kernel']['machine'] =~ /x86_64/ ? 'lib64' : 'lib' when 'windows' - default['php']['windows']['msi_name'] = 'PHP 5.3.28' - default['php']['windows']['msi_source'] = 'http://windows.php.net/downloads/releases/php-5.3.28-nts-Win32-VC9-x86.msi' + default['php']['windows']['msi_name'] = 'PHP 5.6.30' + default['php']['windows']['msi_source'] = 'http://windows.php.net/downloads/releases/php-5.6.30-nts-Win32-VC11-x86.msi' default['php']['bin'] = 'php.exe' default['php']['conf_dir'] = 'C:\Program Files (x86)\PHP' default['php']['ext_conf_dir'] = node['php']['conf_dir'] @@ -105,7 +161,9 @@ when 'freebsd' default['php']['src_deps'] = %w(libbz2-dev libc-client2007e-dev libcurl4-gnutls-dev libfreetype6-dev libgmp3-dev libjpeg62-dev libkrb5-dev libmcrypt-dev libpng12-dev libssl-dev libt1-dev) default['php']['fpm_user'] = 'www' default['php']['fpm_group'] = 'www' - default['php']['packages'] = %w( php56 pear ) + default['php']['fpm_listen_user'] = 'www' + default['php']['fpm_listen_group'] = 'www' + default['php']['packages'] = %w( php56 pear ) default['php']['mysql']['package'] = 'php56-mysqli' else default['php']['conf_dir'] = '/etc/php5/cli' @@ -117,19 +175,14 @@ else default['php']['mysql']['package'] = 'php5-mysql' end -default['php']['url'] = 'http://us1.php.net/get' -default['php']['version'] = '5.5.9' -default['php']['checksum'] = '378de162efdaeeb725ed38d7fe956c9f0b9084ff' -default['php']['prefix_dir'] = '/usr/local' - -default['php']['configure_options'] = %W(--prefix=#{php['prefix_dir']} +default['php']['configure_options'] = %W(--prefix=#{node['php']['prefix_dir']} --with-libdir=#{lib_dir} - --with-config-file-path=#{php['conf_dir']} - --with-config-file-scan-dir=#{php['ext_conf_dir']} + --with-config-file-path=#{node['php']['conf_dir']} + --with-config-file-scan-dir=#{node['php']['ext_conf_dir']} --with-pear --enable-fpm - --with-fpm-user=#{php['fpm_user']} - --with-fpm-group=#{php['fpm_group']} + --with-fpm-user=#{node['php']['fpm_user']} + --with-fpm-group=#{node['php']['fpm_group']} --with-zlib --with-openssl --with-kerberos @@ -159,6 +212,3 @@ default['php']['configure_options'] = %W(--prefix=#{php['prefix_dir']} --with-sqlite3 --with-pdo-mysql --with-pdo-sqlite) - -default['php']['ini']['template'] = 'php.ini.erb' -default['php']['ini']['cookbook'] = 'php' diff --git a/cookbooks/php/libraries/helpers.rb b/cookbooks/php/libraries/helpers.rb index 24d9fcb..8da3d9e 100644 --- a/cookbooks/php/libraries/helpers.rb +++ b/cookbooks/php/libraries/helpers.rb @@ -1,9 +1,9 @@ # -# Author:: Joshua Timberman () -# Cookbook Name:: php +# Author:: Joshua Timberman () +# Cookbook:: php # Libraries:: helpers # -# Copyright 2013, Opscode, Inc. +# Copyright:: 2013-2016, Chef Software, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/cookbooks/php/libraries/matchers.rb b/cookbooks/php/libraries/matchers.rb index 3546e5f..f79863c 100644 --- a/cookbooks/php/libraries/matchers.rb +++ b/cookbooks/php/libraries/matchers.rb @@ -16,6 +16,10 @@ if defined?(ChefSpec) ChefSpec::Matchers::ResourceMatcher.new(:php_pear, :purge, resource_name) end + def purge_php_pear(resource_name) + ChefSpec::Matchers::ResourceMatcher.new(:php_pear, :option, resource_name) + end + ChefSpec.define_matcher :php_pear_channel def discover_php_pear_channel(resource_name) ChefSpec::Matchers::ResourceMatcher.new(:php_pear_channel, :discover, resource_name) @@ -32,4 +36,13 @@ if defined?(ChefSpec) def add_php_pear_channel(resource_name) ChefSpec::Matchers::ResourceMatcher.new(:php_pear_channel, :add, resource_name) end + + ChefSpec.define_matcher :php_fpm_pool + def install_php_fpm_pool(resource_name) + ChefSpec::Matchers::ResourceMatcher.new(:php_fpm_pool, :install, resource_name) + end + + def uninstall_php_fpm_pool(resource_name) + ChefSpec::Matchers::ResourceMatcher.new(:php_fpm_pool, :uninstall, resource_name) + end end diff --git a/cookbooks/php/metadata.json b/cookbooks/php/metadata.json index 0f77757..643f9ca 100644 --- a/cookbooks/php/metadata.json +++ b/cookbooks/php/metadata.json @@ -1 +1 @@ -{"name":"php","version":"1.7.2","description":"Installs and maintains php and php modules","long_description":"","maintainer":"Chef Software, Inc.","maintainer_email":"cookbooks@getchef.com","license":"Apache 2.0","platforms":{"debian":">= 0.0.0","ubuntu":">= 0.0.0","centos":">= 0.0.0","redhat":">= 0.0.0","fedora":">= 0.0.0","scientific":">= 0.0.0","amazon":">= 0.0.0","windows":">= 0.0.0","oracle":">= 0.0.0"},"dependencies":{"build-essential":">= 0.0.0","xml":">= 0.0.0","mysql":">= 6.0.0","yum-epel":">= 0.0.0","windows":">= 0.0.0","iis":">= 0.0.0"},"recommendations":{},"suggestions":{},"conflicting":{},"providing":{},"replacing":{},"attributes":{},"groupings":{},"recipes":{"php":"Installs php","php::package":"Installs php using packages.","php::source":"Installs php from source.","php::module_apc":"Install the php5-apc package","php::module_curl":"Install the php5-curl package","php::module_fileinfo":"Install the php5-fileinfo package","php::module_fpdf":"Install the php-fpdf package","php::module_gd":"Install the php5-gd package","php::module_ldap":"Install the php5-ldap package","php::module_memcache":"Install the php5-memcache package","php::module_mysql":"Install the php5-mysql package","php::module_pgsql":"Install the php5-pgsql packag","php::module_sqlite3":"Install the php5-sqlite3 package"}} \ No newline at end of file +{"name":"php","version":"3.0.0","description":"Installs and maintains php and php modules","long_description":"# php Cookbook\n[![Build Status](https://travis-ci.org/chef-cookbooks/php.svg?branch=master)](http://travis-ci.org/chef-cookbooks/php) [![Cookbook Version](https://img.shields.io/cookbook/v/php.svg)](https://supermarket.chef.io/cookbooks/php)\n\nIt installs and configures PHP and the PEAR package management system. Also includes resources for managing PEAR (and PECL) packages, PECL channels, and PHP-FPM pools.\n\n## Requirements\n### Platforms\n- Debian, Ubuntu\n- CentOS, Red Hat, Oracle, Scientific, Amazon Linux\n- Fedora\n- Microsoft Windows \n\n### Chef\n- Chef 12.1+\n\n### Cookbooks\n- build-essential\n- xml\n- mysql\n- iis\n- windows\n\n## Attributes\n- `node['php']['install_method']` = method to install php with, default `package`.\n- `node['php']['directives']` = Hash of directives and values to append to `php.ini`, default `{}`.\n\nThe file also contains the following attribute types:\n- platform specific locations and settings.\n- source installation settings\n\n## Resource/Provider\nThis cookbook includes LWRPs for managing:\n- PEAR channels\n- PEAR/PECL packages\n\n### `php_pear_channel`\n[PEAR Channels](http://pear.php.net/manual/en/guide.users.commandline.channels.php) are alternative sources for PEAR packages. This resource provides and easy way to manage these channels.\n\n#### Actions\n- :discover: Initialize a channel from its server.\n- :add: Add a channel to the channel list, usually only used to add private channels. Public channels are usually added using the `:discover` action\n- :update: Update an existing channel\n- :remove: Remove a channel from the List\n\n#### Attribute Parameters\n- channel_name: name attribute. The name of the channel to discover\n- channel_xml: the channel.xml file of the channel you are adding\n- pear: pear binary, default: pear\n\n#### Examples\n\n```ruby\n# discover the horde channel\nphp_pear_channel \"pear.horde.org\" do\n action :discover\nend\n\n# download xml then add the symfony channel\nremote_file \"#{Chef::Config[:file_cache_path]}/symfony-channel.xml\" do\n source \"http://pear.symfony-project.com/channel.xml\"\n mode 0644\nend\nphp_pear_channel \"symfony\" do\n channel_xml \"#{Chef::Config[:file_cache_path]}/symfony-channel.xml\"\n action :add\nend\n\n# update the main pear channel\nphp_pear_channel 'pear.php.net' do\n action :update\nend\n\n# update the main pecl channel\nphp_pear_channel 'pecl.php.net' do\n action :update\nend\n```\n\n### `php_pear`\n[PEAR](http://pear.php.net/) is a framework and distribution system for reusable PHP components. [PECL](http://pecl.php.net/) is a repository for PHP Extensions. PECL contains C extensions for compiling into PHP. As C programs, PECL extensions run more efficiently than PEAR packages. PEARs and PECLs use the same packaging and distribution system. As such this LWRP is clever enough to abstract away the small differences and can be used for managing either. This LWRP also creates the proper module .ini file for each PECL extension at the correct location for each supported platform.\n\n#### Actions\n- `:install`: Install a pear package - if version is provided, install that specific version\n- `:upgrade`: Upgrade a pear package - if version is provided, upgrade to that specific version\n- `:remove`: Remove a pear package\n- `:purge`: Purge a pear package (this usually entails removing configuration files as well as the package itself). With pear packages this behaves the same as `:remove`\n\n#### Attribute Parameters\n- `package_name`: name attribute. The name of the pear package to install\n- version: the version of the pear package to install/upgrade. If no version is given latest is assumed.\n- `preferred_state`: PEAR by default installs stable packages only, this allows you to install pear packages in a devel, alpha or beta state\n- `directives`: extra extension directives (settings) for a pecl. on most platforms these usually get rendered into the extension's .ini file\n- `zend_extensions`: extension filenames which should be loaded with zend_extension.\n- o`ptions`: Add additional options to the underlying pear package command\n\n#### Examples\n\n```ruby\n# upgrade a pear\nphp_pear \"XML_RPC\" do\n action :upgrade\nend\n\n\n# install a specific version\nphp_pear \"XML_RPC\" do\n version \"1.5.4\"\n action :install\nend\n\n\n# install the mongodb pecl\nphp_pear \"mongo\" do\n action :install\nend\n\n# install the xdebug pecl\nphp_pear \"xdebug\" do\n # Specify that xdebug.so must be loaded as a zend extension\n zend_extensions ['xdebug.so']\n action :install\nend\n\n\n# install apc pecl with directives\nphp_pear \"apc\" do\n action :install\n directives(:shm_size => 128, :enable_cli => 1)\nend\n\n\n# install the beta version of Horde_Url\n# from the horde channel\nhc = php_pear_channel \"pear.horde.org\" do\n action :discover\nend\nphp_pear \"Horde_Url\" do\n preferred_state \"beta\"\n channel hc.channel_name\n action :install\nend\n\n\n# install the YAML pear from the symfony project\nsc = php_pear_channel \"pear.symfony-project.com\" do\n action :discover\nend\nphp_pear \"YAML\" do\n channel sc.channel_name\n action :install\nend\n```\n\n### `php_fpm_pool`\nInstalls the `php-fpm` package appropriate for your distro (if using packages) and configures a FPM pool for you. Currently only supported in Debian-family operating systems and CentOS 7 (or at least tested with such, YMMV if you are using source).\n\nPlease consider FPM functionally pre-release, and test it thoroughly in your environment before using it in production\n\nMore info: [http://php.net/manual/en/install.fpm.php](http://php.net/manual/en/install.fpm.php)\n\n#### Actions\n- `:install`: Installs the FPM pool (default).\n- `:uninstall`: Removes the FPM pool.\n\n#### Attribute Parameters\n- `pool_name`: name attribute. The name of the FPM pool.\n- `listen`: The listen address. Default: `/var/run/php5-fpm.sock`\n- `user`: The user to run the FPM under. Default should be the webserver user for your distro.\n- `group`: The group to run the FPM under. Default should be the webserver group for your distro.\n- `process_manager`: Process manager to use - see [http://php.net/manual/en/install.fpm.configuration.php](http://php.net/manual/en/install.fpm.configuration.php). Default: `dynamic`\n- `max_children`: Max children to scale to. Default: 5\n- `start_servers`: Number of servers to start the pool with. Default: 2\n- `min_spare_servers`: Minimum number of servers to have as spares. Default: 1\n- `max_spare_servers`: Maximum number of servers to have as spares. Default: 3\n- `chdir`: The startup working directory of the pool. Default: `/`\n- `additional_config`: Additional parameters in JSON. Default: {}\n\n#### Examples\n\n```ruby\n# Install a FPM pool named \"default\"\nphp_fpm_pool \"default\" do\n action :install\nend\n```\n\n## Recipes\n### default\nInclude the default recipe in a run list, to get `php`. By default `php` is installed from packages but this can be changed by using the `install_method` attribute.\n\n### package\nThis recipe installs PHP from packages.\n\n### source\nThis recipe installs PHP from source.\n\n## Deprecated Recipes\nThe following recipes are deprecated and will be removed from a future version of this cookbook.\n- `module_apc`\n- `module_apcu`\n- `module_curl`\n- `module_fileinfo`\n- `module_fpdf`\n- `module_gd`\n- `module_imap`\n- `module_ldap`\n- `module_memcache`\n- `module_mysql`\n- `module_pgsql`\n- `module_sqlite3`\n\nThe installation of the php modules in these recipes can now be accomplished by installing from a native package or via the new php_pear LWRP. For example, the functionality of the `module_memcache` recipe can be enabled in the following ways:\n\n```ruby\n# using apt\npackage \"php5-memcache\" do\n action :install\nend\n\n# using pear LWRP\nphp_pear \"memcache\" do\n action :install\nend\n```\n\n## Usage\nSimply include the `php` recipe where ever you would like php installed. To install from source override the `node['php']['install_method']` attribute with in a role or wrapper cookbook:\n\n####Role example:\n\n```ruby\nname \"php\"\ndescription \"Install php from source\"\noverride_attributes(\n \"php\" => {\n \"install_method\" => \"source\"\n }\n)\nrun_list(\n \"recipe[php]\"\n)\n```\n\n## License & Authors\n**Author:** Cookbook Engineering Team ([cookbooks@chef.io](mailto:cookbooks@chef.io))\n\n**Copyright:** 2008-2017, Chef Software, Inc.\n\n```\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n```\n\nNote: This cookbook contains a modified copy of `go-phar.pear` for use on the Microsoft Windows platform only to correct an (upstream bug)[[http://pear.php.net/bugs/bug.php?id=16644](http://pear.php.net/bugs/bug.php?id=16644)]. The original `go-pear.phar` is licensed under the (PHP License version 2.02)[[http://www.php.net/license/2_02.txt](http://www.php.net/license/2_02.txt)]:\n\n```\n--------------------------------------------------------------------\n The PHP License, version 2.02\nCopyright (c) 1999 - 2002 The PHP Group. All rights reserved.\n--------------------------------------------------------------------\n\nRedistribution and use in source and binary forms, with or without\nmodification, is permitted provided that the following conditions\nare met:\n\n 1. Redistributions of source code must retain the above copyright\n notice, this list of conditions and the following disclaimer.\n\n 2. Redistributions in binary form must reproduce the above\n copyright notice, this list of conditions and the following\n disclaimer in the documentation and/or other materials provided\n with the distribution.\n\n 3. The name \"PHP\" must not be used to endorse or promote products\n derived from this software without prior permission from the\n PHP Group. This does not apply to add-on libraries or tools\n that work in conjunction with PHP. In such a case the PHP\n name may be used to indicate that the product supports PHP.\n\n 4. The PHP Group may publish revised and/or new versions of the\n license from time to time. Each version will be given a\n distinguishing version number.\n Once covered code has been published under a particular version\n of the license, you may always continue to use it under the\n terms of that version. You may also choose to use such covered\n code under the terms of any subsequent version of the license\n published by the PHP Group. No one other than the PHP Group has\n the right to modify the terms applicable to covered code created\n under this License.\n\n 5. Redistributions of any form whatsoever must retain the following\n acknowledgment:\n \"This product includes PHP, freely available from\n http://www.php.net/\".\n\n 6. The software incorporates the Zend Engine, a product of Zend\n Technologies, Ltd. (\"Zend\"). The Zend Engine is licensed to the\n PHP Association (pursuant to a grant from Zend that can be\n found at http://www.php.net/license/ZendGrant/) for\n distribution to you under this license agreement, only as a\n part of PHP. In the event that you separate the Zend Engine\n (or any portion thereof) from the rest of the software, or\n modify the Zend Engine, or any portion thereof, your use of the\n separated or modified Zend Engine software shall not be governed\n by this license, and instead shall be governed by the license\n set forth at http://www.zend.com/license/ZendLicense/.\n\n\n\nTHIS SOFTWARE IS PROVIDED BY THE PHP DEVELOPMENT TEAM ``AS IS'' AND\nANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,\nTHE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A\nPARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PHP\nDEVELOPMENT TEAM OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\nINDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\n(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\nSERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\nHOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\nSTRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\nARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\nOF THE POSSIBILITY OF SUCH DAMAGE.\n\n--------------------------------------------------------------------\n\nThis software consists of voluntary contributions made by many\nindividuals on behalf of the PHP Group.\n\nThe PHP Group can be contacted via Email at group@php.net.\n\nFor more information on the PHP Group and the PHP project,\nplease see .\n```\n","maintainer":"Chef Software, Inc.","maintainer_email":"cookbooks@chef.io","license":"Apache 2.0","platforms":{"amazon":">= 0.0.0","centos":">= 0.0.0","debian":">= 0.0.0","fedora":">= 0.0.0","oracle":">= 0.0.0","redhat":">= 0.0.0","scientific":">= 0.0.0","suse":">= 0.0.0","opensuse":">= 0.0.0","opensuseleap":">= 0.0.0","ubuntu":">= 0.0.0","windows":">= 0.0.0"},"dependencies":{"build-essential":">= 0.0.0","xml":">= 0.0.0","mysql":">= 6.0.0","yum-epel":">= 0.0.0","iis":">= 0.0.0","windows":">= 0.0.0"},"recommendations":{},"suggestions":{},"conflicting":{},"providing":{},"replacing":{},"attributes":{},"groupings":{},"recipes":{"php":"Installs php","php::package":"Installs php using packages.","php::source":"Installs php from source.","php::module_apc":"Install the php5-apc package","php::module_curl":"Install the php5-curl package","php::module_fileinfo":"Install the php5-fileinfo package","php::module_fpdf":"Install the php-fpdf package","php::module_gd":"Install the php5-gd package","php::module_imap":"Install the php5-imap package","php::module_ldap":"Install the php5-ldap package","php::module_memcache":"Install the php5-memcache package","php::module_mysql":"Install the php5-mysql package","php::module_pgsql":"Install the php5-pgsql packag","php::module_sqlite3":"Install the php5-sqlite3 package"},"source_url":"https://github.com/chef-cookbooks/php","issues_url":"https://github.com/chef-cookbooks/php/issues","chef_version":">= 12.7","ohai_version":{}} \ No newline at end of file diff --git a/cookbooks/php/providers/fpm_pool.rb b/cookbooks/php/providers/fpm_pool.rb index c44df54..5ab202f 100644 --- a/cookbooks/php/providers/fpm_pool.rb +++ b/cookbooks/php/providers/fpm_pool.rb @@ -1,9 +1,9 @@ # # Author:: Chris Marchesi -# Cookbook Name:: php +# Cookbook:: php # Provider:: fpm_pool # -# Copyright:: 2015, Opscode, Inc +# Copyright:: 2015-2016, Chef Software, Inc # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,6 +18,8 @@ # limitations under the License. # +use_inline_resources + def whyrun_supported? true end @@ -28,16 +30,15 @@ def install_fpm_package # also, this is skipped for source return if node['php']['install_method'] == 'source' - if node['php']['fpm_package'].nil? - raise 'PHP-FPM package not found (you probably have an unsupported distro)' - else - file node['php']['fpm_default_conf'] do - action :nothing - end - package node['php']['fpm_package'] do - action :install - notifies :delete, "file[#{node['php']['fpm_default_conf']}]" - end + raise 'PHP-FPM package not found (you probably have an unsupported distro)' if node['php']['fpm_package'].nil? + + file node['php']['fpm_default_conf'] do + action :nothing + end + + package node['php']['fpm_package'] do + action :install + notifies :delete, "file[#{node['php']['fpm_default_conf']}]", :immediately end end @@ -57,20 +58,22 @@ action :install do source 'fpm-pool.conf.erb' action :create cookbook 'php' - variables ({ - :fpm_pool_name => new_resource.pool_name, - :fpm_pool_user => new_resource.user, - :fpm_pool_group => new_resource.group, - :fpm_pool_listen => new_resource.listen, - :fpm_pool_manager => new_resource.process_manager, - :fpm_pool_max_children => new_resource.max_children, - :fpm_pool_start_servers => new_resource.start_servers, - :fpm_pool_min_spare_servers => new_resource.min_spare_servers, - :fpm_pool_max_spare_servers => new_resource.max_spare_servers, - :fpm_pool_chdir => new_resource.chdir, - :fpm_pool_additional_config => new_resource.additional_config - }) - notifies :restart, "service[#{node['php']['fpm_package']}]" + variables( + fpm_pool_name: new_resource.pool_name, + fpm_pool_user: new_resource.user, + fpm_pool_group: new_resource.group, + fpm_pool_listen: new_resource.listen, + fpm_pool_listen_user: new_resource.listen_user, + fpm_pool_listen_group: new_resource.listen_group, + fpm_pool_manager: new_resource.process_manager, + fpm_pool_max_children: new_resource.max_children, + fpm_pool_start_servers: new_resource.start_servers, + fpm_pool_min_spare_servers: new_resource.min_spare_servers, + fpm_pool_max_spare_servers: new_resource.max_spare_servers, + fpm_pool_chdir: new_resource.chdir, + fpm_pool_additional_config: new_resource.additional_config + ) + notifies :restart, "service[#{node['php']['fpm_service']}]" end new_resource.updated_by_last_action(t.updated_by_last_action?) end @@ -79,7 +82,7 @@ action :uninstall do # Ensure the FPM pacakge is installed, and the service is registered register_fpm_service # Delete the FPM pool. - f = file "#{node['php']['fpm_pooldir']}/#{new_resource.pool_name}" do + f = file "#{node['php']['fpm_pooldir']}/#{new_resource.pool_name}.conf" do action :delete end new_resource.updated_by_last_action(f.updated_by_last_action?) diff --git a/cookbooks/php/providers/pear.rb b/cookbooks/php/providers/pear.rb index a21715b..a6185d9 100644 --- a/cookbooks/php/providers/pear.rb +++ b/cookbooks/php/providers/pear.rb @@ -1,9 +1,9 @@ # -# Author:: Seth Chisamore -# Cookbook Name:: php +# Author:: Seth Chisamore +# Cookbook:: php # Provider:: pear_package # -# Copyright:: 2011, Opscode, Inc +# Copyright:: 2011-2016, Chef Software, Inc # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,6 +18,8 @@ # limitations under the License. # +use_inline_resources + require 'chef/mixin/shell_out' require 'chef/mixin/language' include Chef::Mixin::ShellOut @@ -26,6 +28,8 @@ include Chef::Mixin::ShellOut # the Chef::Provider::Package which will make # refactoring into core chef easy +use_inline_resources + def whyrun_supported? true end @@ -41,7 +45,7 @@ action :install do info_output = "Installing #{@new_resource}" info_output << " version #{install_version}" if install_version && !install_version.empty? Chef::Log.info(info_output) - status = install_package(@new_resource.package_name, install_version) + install_package(@new_resource.package_name, install_version) end end end @@ -52,7 +56,7 @@ action :upgrade do description = "upgrade package #{@new_resource} version from #{orig_version} to #{candidate_version}" converge_by(description) do Chef::Log.info("Upgrading #{@new_resource} version from #{orig_version} to #{candidate_version}") - status = upgrade_package(@new_resource.package_name, candidate_version) + upgrade_package(@new_resource.package_name, candidate_version) end end end @@ -172,14 +176,14 @@ def remove_package(name, version) end def enable_package(name) - execute "/usr/sbin/php5enmod #{name}" do - only_if { platform?('ubuntu') && node['platform_version'].to_f >= 12.04 && ::File.exist?('/usr/sbin/php5enmod') } + execute "#{node['php']['enable_mod']} #{name}" do + only_if { platform?('ubuntu') && node['platform_version'].to_f >= 12.04 && ::File.exist?(node['php']['enable_mod']) } end end def disable_package(name) - execute "/usr/sbin/php5dismod #{name}" do - only_if { platform?('ubuntu') && node['platform_version'].to_f >= 12.04 && ::File.exist?('/usr/sbin/php5dismod') } + execute "#{node['php']['disable_mod']} #{name}" do + only_if { platform?('ubuntu') && node['platform_version'].to_f >= 12.04 && ::File.exist?(node['php']['disable_mod']) } end end @@ -202,7 +206,7 @@ def prefix_channel(channel) channel ? "#{channel}/" : '' end -def get_extension_dir +def extension_dir @extension_dir ||= begin # Consider using "pecl config-get ext_dir". It is more cross-platform. # p = shell_out("php-config --extension-dir") @@ -223,7 +227,7 @@ def get_extension_files(name) end def manage_pecl_ini(name, action, directives, zend_extensions) - ext_prefix = get_extension_dir + ext_prefix = extension_dir ext_prefix << ::File::SEPARATOR if ext_prefix[-1].chr != ::File::SEPARATOR files = get_extension_files(name) @@ -237,7 +241,7 @@ def manage_pecl_ini(name, action, directives, zend_extensions) end ] - directory "#{node['php']['ext_conf_dir']}" do + directory node['php']['ext_conf_dir'] do owner 'root' group 'root' mode '0755' @@ -250,7 +254,7 @@ def manage_pecl_ini(name, action, directives, zend_extensions) owner 'root' group 'root' mode '0644' - variables(:name => name, :extensions => extensions, :directives => directives) + variables(name: name, extensions: extensions, directives: directives) action action end end @@ -264,13 +268,13 @@ def grep_for_version(stdout, package) # Horde_Url -n/a-/(1.0.0beta1 beta) Horde Url class # Horde_Url 1.0.0beta1 (beta) 1.0.0beta1 Horde Url class v = m.split(/\s+/)[1].strip - if v.split(/\//)[0] =~ /.\./ - # 1.1.4/(1.1.4 stable) - v = v.split(/\//)[0] - else - # -n/a-/(1.0.0beta1 beta) - v = v.split(/(.*)\/\((.*)/).last.split(/\s/)[0] - end + v = if v.split(%r{/\//})[0] =~ /.\./ + # 1.1.4/(1.1.4 stable) + v.split(%r{/\//})[0] + else + # -n/a-/(1.0.0beta1 beta) + v.split(%r{/(.*)\/\((.*)/}).last.split(/\s/)[0] + end end v end @@ -288,7 +292,7 @@ def pecl? elsif grep_for_version(shell_out(node['php']['pecl'] + search_args).stdout, @new_resource.package_name) true else - fail "Package #{@new_resource.package_name} not found in either PEAR or PECL." + raise "Package #{@new_resource.package_name} not found in either PEAR or PECL." end end end diff --git a/cookbooks/php/providers/pear_channel.rb b/cookbooks/php/providers/pear_channel.rb deleted file mode 100644 index daa4f48..0000000 --- a/cookbooks/php/providers/pear_channel.rb +++ /dev/null @@ -1,91 +0,0 @@ -# -# Author:: Seth Chisamore -# Cookbook Name:: php -# Provider:: pear_channel -# -# Copyright:: 2011, Opscode, Inc -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -# http://pear.php.net/manual/en/guide.users.commandline.channels.php - -require 'chef/mixin/shell_out' -require 'chef/mixin/language' -include Chef::Mixin::ShellOut - -def whyrun_supported? - true -end - -action :discover do - unless exists? - Chef::Log.info("Discovering pear channel #{@new_resource}") - execute "#{node['php']['pear']} channel-discover #{@new_resource.channel_name}" do - action :run - end - end -end - -action :add do - unless exists? - Chef::Log.info("Adding pear channel #{@new_resource} from #{@new_resource.channel_xml}") - execute "#{node['php']['pear']} channel-add #{@new_resource.channel_xml}" do - action :run - end - end -end - -action :update do - if exists? - update_needed = false - begin - updated_needed = true if shell_out("#{node['php']['pear']} search -c #{@new_resource.channel_name} NNNNNN").stdout =~ /channel-update/ - rescue Chef::Exceptions::CommandTimeout - # CentOS can hang on 'pear search' if a channel needs updating - Chef::Log.info("Timed out checking if channel-update needed...forcing update of pear channel #{@new_resource}") - update_needed = true - end - if update_needed - description = "update pear channel #{@new_resource}" - converge_by(description) do - Chef::Log.info("Updating pear channel #{@new_resource}") - shell_out!("#{node['php']['pear']} channel-update #{@new_resource.channel_name}") - end - end - end -end - -action :remove do - if exists? - Chef::Log.info("Deleting pear channel #{@new_resource}") - execute "#{node['php']['pear']} channel-delete #{@new_resource.channel_name}" do - action :run - end - end -end - -def load_current_resource - @current_resource = Chef::Resource::PhpPearChannel.new(@new_resource.name) - @current_resource.channel_name(@new_resource.channel_name) - @current_resource -end - -private - -def exists? - shell_out!("#{node['php']['pear']} channel-info #{@current_resource.channel_name}") - true -rescue Mixlib::ShellOut::ShellCommandFailed - false -end diff --git a/cookbooks/php/recipes/default.rb b/cookbooks/php/recipes/default.rb index e94b6c4..3f5e091 100644 --- a/cookbooks/php/recipes/default.rb +++ b/cookbooks/php/recipes/default.rb @@ -1,10 +1,10 @@ # -# Author:: Joshua Timberman () -# Author:: Seth Chisamore () -# Cookbook Name:: php +# Author:: Joshua Timberman () +# Author:: Seth Chisamore () +# Cookbook:: php # Recipe:: default # -# Copyright 2009-2014, Chef Software, Inc. +# Copyright:: 2009-2016, Chef Software, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/cookbooks/php/recipes/ini.rb b/cookbooks/php/recipes/ini.rb index ee0f15e..681a370 100644 --- a/cookbooks/php/recipes/ini.rb +++ b/cookbooks/php/recipes/ini.rb @@ -1,9 +1,9 @@ # # Author:: Christo De Lange () -# Cookbook Name:: php +# Cookbook:: php # Recipe:: ini # -# Copyright 2011-2014, Chef Software, Inc. +# Copyright:: 2011-2016, Chef Software, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -26,5 +26,5 @@ template "#{node['php']['conf_dir']}/php.ini" do group node['root_group'] mode '0644' end - variables(:directives => node['php']['directives']) + variables(directives: node['php']['directives']) end diff --git a/cookbooks/php/recipes/module_apc.rb b/cookbooks/php/recipes/module_apc.rb index a3b69ab..6837f70 100644 --- a/cookbooks/php/recipes/module_apc.rb +++ b/cookbooks/php/recipes/module_apc.rb @@ -1,10 +1,10 @@ # -# Author:: Joshua Timberman () -# Author:: Seth Chisamore () -# Cookbook Name:: php +# Author:: Joshua Timberman () +# Author:: Seth Chisamore () +# Cookbook:: php # Recipe:: module_apc # -# Copyright 2009-2014, Chef Software, Inc. +# Copyright:: 2009-2016, Chef Software, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -21,17 +21,12 @@ case node['platform_family'] when 'rhel', 'fedora' - %w(httpd-devel pcre pcre-devel).each do |pkg| - package pkg do - action :install - end - end + package %w(httpd-devel pcre pcre-devel) + php_pear 'APC' do action :install - directives(:shm_size => '128M', :enable_cli => 0) + directives(shm_size: '128M', enable_cli: 0) end when 'debian' - package 'php-apc' do - action :install - end + package node['php']['apc']['package'] end diff --git a/cookbooks/php/recipes/module_apcu.rb b/cookbooks/php/recipes/module_apcu.rb new file mode 100644 index 0000000..a3dd985 --- /dev/null +++ b/cookbooks/php/recipes/module_apcu.rb @@ -0,0 +1,32 @@ +# +# Author:: Joshua Timberman () +# Author:: Seth Chisamore () +# Cookbook:: php +# Recipe:: module_apc +# +# Copyright:: 2009-2016, Chef Software, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +case node['platform_family'] +when 'rhel', 'fedora' + package %w(httpd-devel pcre pcre-devel) + + php_pear 'APCu' do + action :install + directives(shm_size: '128M', enable_cli: 0) + end +when 'debian' + package node['php']['apcu']['package'] +end diff --git a/cookbooks/php/recipes/module_curl.rb b/cookbooks/php/recipes/module_curl.rb index 7fa7abd..9f539e9 100644 --- a/cookbooks/php/recipes/module_curl.rb +++ b/cookbooks/php/recipes/module_curl.rb @@ -1,10 +1,10 @@ # -# Author:: Joshua Timberman () -# Author:: Seth Chisamore () -# Cookbook Name:: php +# Author:: Joshua Timberman () +# Author:: Seth Chisamore () +# Cookbook:: php # Recipe:: module_curl # -# Copyright 2009-2014, Chef Software, Inc. +# Copyright:: 2009-2016, Chef Software, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -19,11 +19,7 @@ # limitations under the License. # -case node['platform_family'] -when 'rhel', 'fedora' - # centos php compiled with curl -when 'debian' - package 'php5-curl' do - action :upgrade - end +package node['php']['curl']['package'] do + action :install + only_if { platform_family?('debian') } # centos php compiled with curl end diff --git a/cookbooks/php/recipes/module_fpdf.rb b/cookbooks/php/recipes/module_fpdf.rb index 673de15..33fe2ed 100644 --- a/cookbooks/php/recipes/module_fpdf.rb +++ b/cookbooks/php/recipes/module_fpdf.rb @@ -1,10 +1,10 @@ # -# Author:: Joshua Timberman () -# Author:: Seth Chisamore () -# Cookbook Name:: php +# Author:: Joshua Timberman () +# Author:: Seth Chisamore () +# Cookbook:: php # Recipe:: module_fpdf # -# Copyright 2009-2014, Chef Software, Inc. +# Copyright:: 2009-2016, Chef Software, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/cookbooks/php/recipes/module_gd.rb b/cookbooks/php/recipes/module_gd.rb index 4236389..2bc2924 100644 --- a/cookbooks/php/recipes/module_gd.rb +++ b/cookbooks/php/recipes/module_gd.rb @@ -1,10 +1,10 @@ # -# Author:: Joshua Timberman () -# Author:: Seth Chisamore () -# Cookbook Name:: php +# Author:: Joshua Timberman () +# Author:: Seth Chisamore () +# Cookbook:: php # Recipe:: module_gd # -# Copyright 2009-2014, Chef Software, Inc. +# Copyright:: 2009-2016, Chef Software, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -22,12 +22,12 @@ pkg = value_for_platform( %w(centos redhat scientific fedora amazon oracle) => { el5_range => 'php53-gd', - 'default' => 'php-gd' + 'default' => 'php-gd', }, 'freebsd' => { - 'default' => 'php56-gd' + 'default' => 'php56-gd', }, - 'default' => 'php5-gd' + 'default' => node['php']['gd']['package'] ) package pkg do diff --git a/cookbooks/php/recipes/module_imap.rb b/cookbooks/php/recipes/module_imap.rb new file mode 100644 index 0000000..de06c20 --- /dev/null +++ b/cookbooks/php/recipes/module_imap.rb @@ -0,0 +1,29 @@ +# +# Author:: Artur Melo () +# Cookbook:: php +# Recipe:: module_imap +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +pkg = value_for_platform( + %w(centos redhat scientific fedora amazon oracle) => { + el5_range => 'php53-imap', + 'default' => 'php-imap', + }, + 'default' => 'php5-imap' +) + +package pkg do + action :install +end diff --git a/cookbooks/php/recipes/module_ldap.rb b/cookbooks/php/recipes/module_ldap.rb index 0b8e8bf..21daed7 100644 --- a/cookbooks/php/recipes/module_ldap.rb +++ b/cookbooks/php/recipes/module_ldap.rb @@ -1,10 +1,10 @@ # -# Author:: Joshua Timberman () -# Author:: Seth Chisamore () -# Cookbook Name:: php +# Author:: Joshua Timberman () +# Author:: Seth Chisamore () +# Cookbook:: php # Recipe:: module_ldap # -# Copyright 2009-2014, Chef Software, Inc. +# Copyright:: 2009-2016, Chef Software, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -22,9 +22,9 @@ pkg = value_for_platform( %w(centos redhat scientific fedora amazon oracle) => { el5_range => 'php53-ldap', - 'default' => 'php-ldap' + 'default' => 'php-ldap', }, - 'default' => 'php5-ldap' + 'default' => node['php']['ldap']['package'] ) package pkg do diff --git a/cookbooks/php/recipes/module_memcache.rb b/cookbooks/php/recipes/module_memcache.rb index 4c05266..0ffd131 100644 --- a/cookbooks/php/recipes/module_memcache.rb +++ b/cookbooks/php/recipes/module_memcache.rb @@ -1,10 +1,10 @@ # -# Author:: Joshua Timberman () -# Author:: Seth Chisamore () -# Cookbook Name:: php +# Author:: Joshua Timberman () +# Author:: Seth Chisamore () +# Cookbook:: php # Recipe:: module_memcache # -# Copyright 2009-2014, Chef Software, Inc. +# Copyright:: 2009-2016, Chef Software, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -21,17 +21,11 @@ case node['platform_family'] when 'rhel', 'fedora' - %w(zlib-devel).each do |pkg| - package pkg do - action :install - end - end + package 'zlib-devel' + php_pear 'memcache' do action :install - # directives(:shm_size => "128M", :enable_cli => 0) end when 'debian' - package 'php5-memcache' do - action :install - end + package 'php5-memcache' end diff --git a/cookbooks/php/recipes/module_mysql.rb b/cookbooks/php/recipes/module_mysql.rb index 7b7d2ab..94dbcc3 100644 --- a/cookbooks/php/recipes/module_mysql.rb +++ b/cookbooks/php/recipes/module_mysql.rb @@ -1,10 +1,10 @@ # -# Author:: Joshua Timberman () -# Author:: Seth Chisamore () -# Cookbook Name:: php +# Author:: Joshua Timberman () +# Author:: Seth Chisamore () +# Cookbook:: php # Recipe:: module_mysql # -# Copyright 2009-2014, Chef Software, Inc. +# Copyright:: 2009-2016, Chef Software, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/cookbooks/php/recipes/module_pgsql.rb b/cookbooks/php/recipes/module_pgsql.rb index f7837d8..e555708 100644 --- a/cookbooks/php/recipes/module_pgsql.rb +++ b/cookbooks/php/recipes/module_pgsql.rb @@ -1,10 +1,10 @@ # -# Author:: Joshua Timberman () -# Author:: Seth Chisamore () -# Cookbook Name:: php +# Author:: Joshua Timberman () +# Author:: Seth Chisamore () +# Cookbook:: php # Recipe:: module_pgsql # -# Copyright 2009-2014, Chef Software, Inc. +# Copyright:: 2009-2016, Chef Software, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -22,9 +22,9 @@ pkg = value_for_platform( %w(centos redhat scientific fedora amazon oracle) => { el5_range => 'php53-pgsql', - 'default' => 'php-pgsql' + 'default' => 'php-pgsql', }, - 'default' => 'php5-pgsql' + 'default' => node['php']['pgsql']['package'] ) package pkg do diff --git a/cookbooks/php/recipes/module_sqlite3.rb b/cookbooks/php/recipes/module_sqlite3.rb index 5d887c1..0ffaefb 100644 --- a/cookbooks/php/recipes/module_sqlite3.rb +++ b/cookbooks/php/recipes/module_sqlite3.rb @@ -1,10 +1,10 @@ # -# Author:: Joshua Timberman () -# Author:: Seth Chisamore () -# Cookbook Name:: php +# Author:: Joshua Timberman () +# Author:: Seth Chisamore () +# Cookbook:: php # Recipe:: module_sqlite3 # -# Copyright 2009-2014, Chef Software, Inc. +# Copyright:: 2009-2016, Chef Software, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -19,11 +19,7 @@ # limitations under the License. # -case node['platform_family'] -when 'rhel', 'fedora' - # already there in centos, --with-pdo-sqlite=shared -when 'debian' - package 'php5-sqlite' do - action :install - end +package node['php']['sqlite']['package'] do + action :install + only_if { platform_family?('debian') } # already there in centos, --with-pdo-sqlite=shared end diff --git a/cookbooks/php/recipes/package.rb b/cookbooks/php/recipes/package.rb index 06799ef..3b96d45 100644 --- a/cookbooks/php/recipes/package.rb +++ b/cookbooks/php/recipes/package.rb @@ -1,10 +1,10 @@ # -# Author:: Seth Chisamore () -# Author:: Lucas Hansen () -# Cookbook Name:: php +# Author:: Seth Chisamore () +# Author:: Lucas Hansen () +# Cookbook:: php # Recipe:: package # -# Copyright 2013-2014, Chef Software, Inc. +# Copyright:: 2013-2016, Chef Software, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -23,7 +23,7 @@ if platform?('windows') include_recipe 'iis::mod_cgi' - install_dir = File.expand_path(node['php']['conf_dir']).gsub('/', '\\') + install_dir = File.expand_path(node['php']['conf_dir']).tr('/', '\\') windows_package node['php']['windows']['msi_name'] do source node['php']['windows']['msi_source'] installer_type :msi diff --git a/cookbooks/php/recipes/recompile.rb b/cookbooks/php/recipes/recompile.rb index 1a090cd..5113f2a 100644 --- a/cookbooks/php/recipes/recompile.rb +++ b/cookbooks/php/recipes/recompile.rb @@ -1,9 +1,9 @@ # # Author:: David Kinzer () -# Cookbook Name:: php +# Cookbook:: php # Recipe:: recompile # -# Copyright 2014, David Kinzer +# Copyright:: 2014-2016, David Kinzer # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -38,7 +38,7 @@ end bash 'un-pack php' do cwd Chef::Config[:file_cache_path] code "tar -zxf php-#{version}.tar.gz" - creates "#{node['php']['url']}/php-#{version}" + creates "#{Chef::Config[:file_cache_path]}/php-#{version}" end bash 're-build php' do @@ -46,6 +46,6 @@ bash 're-build php' do code <<-EOF (make clean) (#{ext_dir_prefix} ./configure #{configure_options}) - (make && make install) + (make -j #{node['cpu']['total']} && make install) EOF end diff --git a/cookbooks/php/recipes/source.rb b/cookbooks/php/recipes/source.rb index 9825911..6223c91 100644 --- a/cookbooks/php/recipes/source.rb +++ b/cookbooks/php/recipes/source.rb @@ -1,9 +1,9 @@ # -# Author:: Seth Chisamore () -# Cookbook Name:: php -# Recipe:: package +# Author:: Seth Chisamore () +# Cookbook:: php +# Recipe:: source # -# Copyright 2011-2014, Chef Software, Inc. +# Copyright:: 2011-2016, Chef Software, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -29,11 +29,7 @@ mysql_client 'default' do only_if { configure_options =~ /mysql/ } end -node['php']['src_deps'].each do |pkg| - package pkg do - action :install - end -end +package node['php']['src_deps'] version = node['php']['version'] @@ -41,7 +37,7 @@ remote_file "#{Chef::Config[:file_cache_path]}/php-#{version}.tar.gz" do source "#{node['php']['url']}/php-#{version}.tar.gz/from/this/mirror" checksum node['php']['checksum'] mode '0644' - not_if "which #{node['php']['bin']}" + not_if "$(which #{node['php']['bin']}) --version | grep #{version}" end if node['php']['ext_dir'] @@ -56,14 +52,21 @@ else ext_dir_prefix = '' end +# PHP is unable to find the GMP library in 16.04. The symlink brings the file +# inside of the include libraries. +link '/usr/include/gmp.h' do + to '/usr/include/x86_64-linux-gnu/gmp.h' + only_if { node['platform_family'] == 'debian' && node['platform_version'].to_f >= 14.04 } +end + bash 'build php' do cwd Chef::Config[:file_cache_path] code <<-EOF tar -zxf php-#{version}.tar.gz (cd php-#{version} && #{ext_dir_prefix} ./configure #{configure_options}) - (cd php-#{version} && make && make install) + (cd php-#{version} && make -j #{node['cpu']['total']} && make install) EOF - not_if "which #{node['php']['bin']}" + not_if "$(which #{node['php']['bin']}) --version | grep #{version}" end directory node['php']['conf_dir'] do diff --git a/cookbooks/php/resources/fpm_pool.rb b/cookbooks/php/resources/fpm_pool.rb index 0a6c6ab..a65edec 100644 --- a/cookbooks/php/resources/fpm_pool.rb +++ b/cookbooks/php/resources/fpm_pool.rb @@ -1,9 +1,9 @@ # # Author:: Chris Marchesi -# Cookbook Name:: php +# Cookbook:: php # Resource:: fpm_pool # -# Copyright:: 2015, Opscode, Inc +# Copyright:: 2015-2016, Chef Software, Inc # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -21,14 +21,16 @@ default_action :install actions :install, :uninstall -attribute :pool_name, :kind_of => String, :name_attribute => true -attribute :listen, :default => '/var/run/php5-fpm.sock' -attribute :user, :kind_of => String, :default => node['php']['fpm_user'] -attribute :group, :kind_of => String, :default => node['php']['fpm_user'] -attribute :process_manager, :kind_of => String, :default => 'dynamic' -attribute :max_children, :kind_of => Integer, :default => 5 -attribute :start_servers, :kind_of => Integer, :default => 2 -attribute :min_spare_servers, :kind_of => Integer, :default => 1 -attribute :max_spare_servers, :kind_of => Integer, :default => 3 -attribute :chdir, :kind_of => String, :default => '/' -attribute :additional_config, :kind_of => Hash, :default => {} +attribute :pool_name, kind_of: String, name_attribute: true +attribute :listen, kind_of: String, default: node['php']['fpm_socket'] +attribute :user, kind_of: String, default: node['php']['fpm_user'] +attribute :group, kind_of: String, default: node['php']['fpm_group'] +attribute :listen_user, kind_of: String, default: node['php']['fpm_listen_user'] +attribute :listen_group, kind_of: String, default: node['php']['fpm_listen_group'] +attribute :process_manager, kind_of: String, default: 'dynamic' +attribute :max_children, kind_of: Integer, default: 5 +attribute :start_servers, kind_of: Integer, default: 2 +attribute :min_spare_servers, kind_of: Integer, default: 1 +attribute :max_spare_servers, kind_of: Integer, default: 3 +attribute :chdir, kind_of: String, default: '/' +attribute :additional_config, kind_of: Hash, default: {} diff --git a/cookbooks/php/resources/pear.rb b/cookbooks/php/resources/pear.rb index 9052393..287489b 100644 --- a/cookbooks/php/resources/pear.rb +++ b/cookbooks/php/resources/pear.rb @@ -1,9 +1,9 @@ # -# Author:: Seth Chisamore -# Cookbook Name:: php +# Author:: Seth Chisamore +# Cookbook:: php # Resource:: pear_package # -# Copyright:: 2011-2014, Chef Software, Inc +# Copyright:: 2011-2016, Chef Software, Inc # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -29,10 +29,10 @@ state_attrs :channel, :version, :zend_extensions -attribute :package_name, :kind_of => String, :name_attribute => true -attribute :version, :default => nil -attribute :channel, :kind_of => String -attribute :options, :kind_of => String -attribute :directives, :kind_of => Hash, :default => {} -attribute :zend_extensions, :kind_of => Array, :default => [] -attribute :preferred_state, :default => 'stable' +attribute :package_name, kind_of: String, name_attribute: true +attribute :version, default: nil +attribute :channel, kind_of: String +attribute :options, kind_of: String +attribute :directives, kind_of: Hash, default: {} +attribute :zend_extensions, kind_of: Array, default: [] +attribute :preferred_state, default: 'stable' diff --git a/cookbooks/php/resources/pear_channel.rb b/cookbooks/php/resources/pear_channel.rb index 33c33f9..067c397 100644 --- a/cookbooks/php/resources/pear_channel.rb +++ b/cookbooks/php/resources/pear_channel.rb @@ -1,9 +1,10 @@ # -# Author:: Seth Chisamore -# Cookbook Name:: php +# Author:: Seth Chisamore +# Author:: Jennifer Davis +# Cookbook:: php # Resource:: pear_channel # -# Copyright:: 2011-2014, Chef Software, Inc +# Copyright:: 2011-2017, Chef Software, Inc # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -19,14 +20,65 @@ # default_action :discover -actions :discover, :add, :update, :remove - -state_attrs :channel_name, - :channel_xml - -attribute :channel_name, :kind_of => String, :name_attribute => true -attribute :channel_xml, :kind_of => String - +property :channel_xml, kind_of: String +property :channel_name, kind_of: String, name_property: true +property :pear, kind_of: String, default: 'pear' # TODO: add authenticated channel support! -# attribute :username, :kind_of => String -# attribute :password, :kind_of => String +# property :username, :kind_of => String +# property :password, :kind_of => String + +action_class do + def exists? + shell_out!("#{@new_resource.pear} channel-info #{@new_resource.channel_name}") + true + rescue Mixlib::ShellOut::ShellCommandFailed + false + end +end + +action :discover do + unless exists? + Chef::Log.info("Discovering pear channel #{@new_resource}") + execute "#{@new_resource.pear} channel-discover #{@new_resource.channel_name}" do + action :run + end + end +end + +action :add do + unless exists? + Chef::Log.info("Adding pear channel #{@new_resource} from #{@new_resource.channel_xml}") + execute "#{@new_resource.pear} channel-add #{@new_resource.channel_xml}" do + action :run + end + end +end + +action :update do + if exists? + update_needed = false + begin + update_needed = true if shell_out("#{@new_resource.pear} search -c #{@new_resource.channel_name} NNNNNN").stdout =~ /channel-update/ + rescue Chef::Exceptions::CommandTimeout + # CentOS can hang on 'pear search' if a channel needs updating + Chef::Log.info("Timed out checking if channel-update needed...forcing update of pear channel #{@new_resource}") + update_needed = true + end + if update_needed + description = "update pear channel #{@new_resource}" + converge_by(description) do + Chef::Log.info("Updating pear channel #{@new_resource}") + shell_out!("#{@new_resource.pear} channel-update #{@new_resource.channel_name}") + end + end + end +end + +action :remove do + if exists? + Chef::Log.info("Deleting pear channel #{@new_resource}") + execute "#{@new_resource.pear} channel-delete #{@new_resource.channel_name}" do + action :run + end + end +end diff --git a/cookbooks/php/templates/default/fpm-pool.conf.erb b/cookbooks/php/templates/default/fpm-pool.conf.erb index aa01b8f..71ad207 100644 --- a/cookbooks/php/templates/default/fpm-pool.conf.erb +++ b/cookbooks/php/templates/default/fpm-pool.conf.erb @@ -2,8 +2,8 @@ user = <%= @fpm_pool_user %> group = <%= @fpm_pool_group %> listen = <%= @fpm_pool_listen %> -listen.owner = <%= @fpm_pool_user %> -listen.group = <%= @fpm_pool_group %> +listen.owner = <%= @fpm_pool_listen_user %> +listen.group = <%= @fpm_pool_listen_group %> pm = <%= @fpm_pool_manager %> pm.max_children = <%= @fpm_pool_max_children %> pm.start_servers = <%= @fpm_pool_start_servers %> diff --git a/cookbooks/rbac/README.md b/cookbooks/rbac/README.md deleted file mode 100644 index e7f3f74..0000000 --- a/cookbooks/rbac/README.md +++ /dev/null @@ -1,82 +0,0 @@ -Role based access control -========================= - -Solaris and Illumos provide sophisticated role-based access control for -delegating authorizations within the system. Using RBAC, users can be -given permissions to manage and update services without sudo. - -This cookbook provides chef with LWRPs to manage RBAC and grant permissions. - -At this time this cookbook ONLY manages SMF-related permissions (ie, ability -of non-priviliged users to start/stop SMF services), but in the future it may -be enhanced to support arbitrary Solaris permissions. - -## Installation - -In order to add the RBAC LWRPs to a chef run, add the following recipe -to the run_list: - - rbac::default - -This will do no work, but will load the providers. - -## LWRPs - -### rbac - -Defines a set of authorizations that can be applied to SMF services and -authorized to users, without actually applying them to users. - -Actions: - * create (default) - -Attributes: - * name - -Example: - -```ruby -rbac "nginx" do - action :create -end -``` - -This will update the authorizations file at `/etc/security/auth_attr` -with the following lines: - -``` -solaris.smf.manage.nginx:::Manage nginx Service States:: -solaris.smf.value.nginx:::Change value of nginx Service:: -``` - -Users who are given these authorizations can change properties of the -service as well as change its state (i.e. `svcadm disable|enable|restart|clear service` - -### rbac_auth - -Adds the rbac definition created by `auth` to the user `name`. - -Actions: - * add (default) - -Attributes: - * name - for descriptive purposes and to ensure that each LWRP call is uniquely - identified in the chef run - * user - * auth - -Example: - -```ruby -rbac_auth "add nginx management permissions to my_user" do - user "my_user" - auth "nginx" -end -``` - -This adds both manage and value auths to user `my_user`. - -## TODO - -* separate manage auth from value auth -* ability to delete all rbac attributes diff --git a/cookbooks/rbac/libraries/rbac.rb b/cookbooks/rbac/libraries/rbac.rb deleted file mode 100644 index 27b29a8..0000000 --- a/cookbooks/rbac/libraries/rbac.rb +++ /dev/null @@ -1,15 +0,0 @@ -# This module is used to retain state during the course of a chef -# run. The LWRPs in the cookbook modify a global hash in this module, -# and at the end of the chef run if user authorizations change they -# are written out into the system. -# -module RBAC - def self.authorizations - @authorizations ||= {} - end - - def self.add_authorization(username, auth) - authorizations[username] ||= [] - authorizations[username] << auth - end -end diff --git a/cookbooks/rbac/metadata.json b/cookbooks/rbac/metadata.json deleted file mode 100644 index 08c1d91..0000000 --- a/cookbooks/rbac/metadata.json +++ /dev/null @@ -1,42 +0,0 @@ -{ - "name": "rbac", - "description": "Allows delegation of service management to users with Solaris Role Based Access Control (RBAC)", - "long_description": "Role based access control\n=========================\n\nSolaris and Illumos provide sophisticated role-based access control for\ndelegating authorizations within the system. Using RBAC, users can be\ngiven permissions to manage and update services without sudo.\n\nThis cookbook provides chef with LWRPs to manage RBAC and grant permissions.\n\nAt this time this cookbook ONLY manages SMF-related permissions (ie, ability\nof non-priviliged users to start/stop SMF services), but in the future it may\nbe enhanced to support arbitrary Solaris permissions.\n\n## Installation\n\nIn order to add the RBAC LWRPs to a chef run, add the following recipe \nto the run_list:\n\n rbac::default\n\nThis will do no work, but will load the providers.\n\n## LWRPs\n\n### rbac\n\nDefines a set of authorizations that can be applied to SMF services and\nauthorized to users, without actually applying them to users.\n\nActions:\n * create (default)\n\nAttributes:\n * name\n\nExample:\n\n```ruby\nrbac \"nginx\" do\n action :create\nend\n```\n\nThis will update the authorizations file at `/etc/security/auth_attr`\nwith the following lines:\n\n```\nsolaris.smf.manage.nginx:::Manage nginx Service States::\nsolaris.smf.value.nginx:::Change value of nginx Service::\n```\n\nUsers who are given these authorizations can change properties of the\nservice as well as change its state (i.e. `svcadm disable|enable|restart|clear service`\n\n### rbac_auth\n\nAdds the rbac definition created by `auth` to the user `name`.\n\nActions:\n * add (default)\n\nAttributes:\n * name - for descriptive purposes and to ensure that each LWRP call is uniquely\n identified in the chef run\n * user\n * auth\n\nExample:\n\n```ruby\nrbac_auth \"add nginx management permissions to my_user\" do\n user \"my_user\"\n auth \"nginx\"\nend\n```\n\nThis adds both manage and value auths to user `my_user`.\n\n## TODO\n\n* separate manage auth from value auth\n* ability to delete all rbac attributes\n", - "maintainer": "Eric Saxby", - "maintainer_email": "sax@livinginthepast.org", - "license": "MIT", - "platforms": { - "solaris2": ">= 0.0.0", - "smartos": ">= 0.0.0" - }, - "dependencies": { - - }, - "recommendations": { - - }, - "suggestions": { - - }, - "conflicting": { - - }, - "providing": { - - }, - "replacing": { - - }, - "attributes": { - - }, - "groupings": { - - }, - "recipes": { - - }, - "version": "1.0.3", - "source_url": "", - "issues_url": "" -} diff --git a/cookbooks/rbac/metadata.rb b/cookbooks/rbac/metadata.rb deleted file mode 100644 index 91c58d2..0000000 --- a/cookbooks/rbac/metadata.rb +++ /dev/null @@ -1,10 +0,0 @@ -name 'rbac' -maintainer 'Eric Saxby' -maintainer_email 'sax@livinginthepast.org' -license 'MIT' -description 'Allows delegation of service management to users with Solaris Role Based Access Control (RBAC)' -long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) -version '1.0.3' - -supports 'solaris2' -supports 'smartos' diff --git a/cookbooks/rbac/providers/auth.rb b/cookbooks/rbac/providers/auth.rb deleted file mode 100644 index d922489..0000000 --- a/cookbooks/rbac/providers/auth.rb +++ /dev/null @@ -1,20 +0,0 @@ -def load_current_resource - @current_resource = Chef::Resource::RbacAuth.new(new_resource.name) - @new_resource.definition = run_context.resource_collection.find(:rbac => @new_resource.auth) - begin - @new_resource.user_definition = run_context.resource_collection.find(:rbac_user => @new_resource.user) - rescue Chef::Exceptions::ResourceNotFound - end -end - -action :add do - unless new_resource.user_definition - new_resource.user_definition = rbac_user new_resource.user - end - - new_resource.add_auth new_resource.user, new_resource.auth - - new_resource.updated_by_last_action(true) - - new_resource.notifies(:apply, new_resource.user_definition, :delayed) -end diff --git a/cookbooks/rbac/providers/default.rb b/cookbooks/rbac/providers/default.rb deleted file mode 100644 index 368de9e..0000000 --- a/cookbooks/rbac/providers/default.rb +++ /dev/null @@ -1,27 +0,0 @@ - -def load_current_resource - @current_resource = Chef::Resource::Rbac.new(@new_resource.name) -end - -action :create do - definition = new_resource.name - - new_resource.updated_by_last_action(false) - - manage_auth = "solaris.smf.manage.#{definition}:::Manage #{definition} Service States::" - manage = execute "add RBAC #{definition} management to /etc/security/auth_attr" do - command "echo \"#{manage_auth}\" >> /etc/security/auth_attr" - not_if "grep \"#{manage_auth}\" /etc/security/auth_attr" - end - - # This additional permission allows the user to call svccfg -s service setprop - # to set dynamic properties without having to re-run chef. This may be - # moved into a separate LWRP in the future. - value_auth = "solaris.smf.value.#{definition}:::Change value of #{definition} Service::" - value = execute "add RBAC #{definition} value to /etc/security/auth_attr" do - command "echo \"#{value_auth}\" >> /etc/security/auth_attr" - not_if "grep \"#{value_auth}\" /etc/security/auth_attr" - end - - new_resource.updated_by_last_action(manage.updated_by_last_action? || value.updated_by_last_action?) -end diff --git a/cookbooks/rbac/providers/user.rb b/cookbooks/rbac/providers/user.rb deleted file mode 100644 index cefb660..0000000 --- a/cookbooks/rbac/providers/user.rb +++ /dev/null @@ -1,22 +0,0 @@ -# The rbac_user LWRP is an internal set of classes used by other LWRPs to -# delay writing of user attributes until the end of the chef run. It should not be -# manually run. - -def load_current_resource - @current_resource = Chef::Resource::Rbac::User.new(@new_resource.user) -end - -action :apply do - username = new_resource.user - - auths = RBAC.authorizations[username] - permissions = auths.inject([]) do |auth, name| - auth + ["solaris.smf.manage.#{name}", "solaris.smf.value.#{name}"] - end.sort.uniq.join(',') - - execute "Apply rbac authorizations to #{username}" do - command "usermod -A #{permissions} #{username}" - action :nothing - not_if "grep #{username} /etc/user_attr | grep 'auths=#{permissions}'" - end.run_action(:run) -end diff --git a/cookbooks/rbac/recipes/default.rb b/cookbooks/rbac/recipes/default.rb deleted file mode 100644 index 3cab4b3..0000000 --- a/cookbooks/rbac/recipes/default.rb +++ /dev/null @@ -1,6 +0,0 @@ -# -# Cookbook Name:: rbac -# Recipe:: default -# -# Copyright 2012, ModCloth, Inc. -# diff --git a/cookbooks/rbac/resources/auth.rb b/cookbooks/rbac/resources/auth.rb deleted file mode 100644 index 4c8bedd..0000000 --- a/cookbooks/rbac/resources/auth.rb +++ /dev/null @@ -1,14 +0,0 @@ - -default_action :add - -actions :add - -attribute :user, :kind_of => String, :required => true -attribute :auth, :kind_of => String, :required => true - -# private, internal attributes -attr_accessor :definition, :user_definition - -def add_auth(user, auth) - RBAC.add_authorization(user, auth) -end diff --git a/cookbooks/rbac/resources/default.rb b/cookbooks/rbac/resources/default.rb deleted file mode 100644 index 8a56e0a..0000000 --- a/cookbooks/rbac/resources/default.rb +++ /dev/null @@ -1,6 +0,0 @@ - -default_action :create - -actions :create - -attribute :name, :kind_of => String, :name_attribute => true, :required => true diff --git a/cookbooks/rbac/resources/user.rb b/cookbooks/rbac/resources/user.rb deleted file mode 100644 index 25fb93c..0000000 --- a/cookbooks/rbac/resources/user.rb +++ /dev/null @@ -1,6 +0,0 @@ - -default_action :nothing - -actions :apply - -attribute :user, :kind_of => String, :name_attribute => true, :required => true diff --git a/cookbooks/smf/README.md b/cookbooks/smf/README.md deleted file mode 100644 index a1dabb0..0000000 --- a/cookbooks/smf/README.md +++ /dev/null @@ -1,370 +0,0 @@ -SMF -=== - -## Description - -Service Management Facility (SMF) is a tool in many Illumos and Solaris-derived operating systems -that treats services as first class objects of the system. It provides an XML syntax for -declaring how the system can interact with and control a service. - -The SMF cookbook contains providers for creating or modifying a service within the SMF framework. - - -## Requirements - -Any operating system that uses SMF, ie Solaris, SmartOS, OpenIndiana etc. - -The `smf` provider depends on the `builder` gem, which can be installed -via the `smf::default` recipe. - -Requires the RBAC cookbook, which can be found at . - -Processes can be run inside a project wrapper. In this case, look to the Resource Control cookbook, -which can be found at . Note that the SMF LWRP -does not create or manage the project. - - -## Basic Usage - -Note that we run the `smf::default` recipe before using LWRPs from this -cookbook. - -```ruby -include_recipe 'smf' - -smf 'my-service' do - user 'non-root-user' - start_command 'my-service start' - start_timeout 10 - stop_command 'pkill my-service' - stop_timeout 5 - restart_command 'my-service restart' - restart_timeout 60 - environment 'PATH' => '/home/non-root-user/bin', - 'RAILS_ENV' => 'staging' - locale 'C' - manifest_type 'application' - service_path '/var/svc/manifest' - notifies :restart, 'service[my-service]' -end - -service 'my-service' do - action :enable -end - -service 'my-service' do - action :restart -end -``` - - -## Attributes - -Ownership: -* `user` - User to run service commands as -* `group` - Group to run service commands as - -RBAC -* `authorization` - What management and value authorizations should be - created for this service. Defaults to the service name. - -Dependency management: -* `include_default_dependencies` - Service should depend on file system - and network services. Defaults to `true`. See [Dependencies](#dependencies) - for more info. -* `dependency` - an optional array of hashes signifying service and path - dependencies for this service to run. See [Dependencies](#dependencies). - -Process management: -* `project` - Name of project to run commands in -* `start_command` -* `start_timeout` -* `stop_command` - defaults to `:kill`, which basically means it will destroy every PID generated from the start command -* `stop_timeout` -* `restart_command` - defaults to `stop_command`, then `start_command` -* `restart_timeout` -* `refresh_command` - by default SMF treats this as `true`. This will be called when the SMF definition changes or - when a `notify :reload, 'service[thing]'` is called. -* `refresh_timeout` -* `duration` - Can be either `contract`, `wait`, `transient` or - `child`, but defaults to `contract`. See the [Duration](#duration) section below. -* `environment` - Hash - Environment variables to set while running commands -* `ignore` - Array - Faults to ignore in subprocesses. For example, - if core dumps in children are handled by a master process and you - don't want SMF thinking the service is exploding, you can ignore - ["core", "signal"]. -* `privileges` - Array - An array of privileges to be allowed for started processes. - Defaults to ['basic', 'net_privaddr'] -* `property_groups` - Hash - This should be in the form `{"group name" => {"type" => "application", "key" => "value", ...}}` -* `working_directory` - PWD that SMF should cd to in order to run commands -* `locale` - Character encoding to use (default "C") - -Manifest/FMRI metadata: -* `service_path` - defaults to `/var/svc/manifest` -* `manifest_type` - defaults to `application` -* `stability` - String - defaults to "Evolving". Valid options are - "Standard", "Stable", "Evolving", "Unstable", "External" and - "Obsolete" - -Deprecated: -* `credentials_user` - deprecated in favor of `user` - - -## Provider Actions - -### :install (default) - -This will drop a manifest XML file into `#{service_path}/#{manifest_type}/#{name}.xml`. If there is already a service -with a name that is matched by `new_resource.name` then the FMRI of our manifest will be set to the FMRI of the -pre-existing service. In this case, our properties will be merged into the properties of the pre-existing service. - -In this way, updates to recipes that use the SMF provider will not delete existing service properties, but will add -or overwrite them. - -Because of this, the SMF provider can be used to update properties for -services that are installed via a package manager. - -### :delete - -Remove an SMF definition. This stops the service if it is running. - -### :add_rbac - -This uses the `rbac` cookbook to define permissions that can then be applied to a user. This can be useful when local -users should manage services that are added via packages. - -```ruby -smf "nginx" do - action :add_rbac -end - -rbac_auth "Allow my user to manage nginx" do - user "my_user" - auth "nginx" -end -``` - - -## Resource Notes - -### `user`, `working_directory` and `environment` - -SMF does a remarkably good job running services as delegated users, and removes a lot of pain if you configure a -service correctly. There are many examples online (blogs, etc) of users wrapping their services in shell scripts with -`start`, `stop`, `restart` arguments. In general it seems as if the intention of these scripts is to take care of the -problem of setting environment variables and shelling out as another user. - -The use of init scripts to wrap executables can be unnecessary with SMF, as it provides hooks for all of these use cases. -When using `user`, SMF will assume that the `working_directory` is the user's home directory. This can be -easily overwritten (to `/home/user/app/current` for a Rails application, for example). One thing to be careful of is -that shell profile files will not be loaded. For this reason, if environment variables (such as PATH) are different -on your system or require additional entries arbitrary key/values may be set using the `environment` attribute. - -All things considered, one should think carefully about the need for an init script when working with SMF. For -well-behaved applications with simple configuration, an init script is overkill. Applications with endless command-line -options or that need a real login shell (for instance ruby applications that use RVM) an init script may make life -easier. - -### Role Based Authorization - -By default the SMF definition creates authorizations based on the -service name. The service user is then granted these authorizations. If -the service is named `asplosions`, then `solaris.smf.manage.asplosions` -and `solaris.smf.value.asplosions` will be created. - -The authorization can be changed by manually setting `authorization` on -the smf block: - -```ruby -smf 'asplosions' do - user 'monkeyking' - start_command 'asplode' - authorization 'booms' -end -``` - -This can be helpful if there are many services configured on a single -host, as multiple services can be collapsed into the same -authorizations. For instance: https://illumos.org/issues/4968 - -### Dependencies - -SMF allows services to explicitly list their dependencies on other -services. Among other things, this ensures that services are enabled in -the proper order on boot, so that a service doesn't fail to start -because another service has not yet been started. - -By default, services created by the SMF LWRP depend on the following other services: -* svc:/milestone/sysconfig -* svc:/system/filesystem/local -* svc:/milestone/name-services -* svc:/milestone/network - -On Solaris11, `svc:/milestone/sysconfig` is replaced with -`svc:/milestone/config`. - -These are configured with the attribute `include_default_dependencies`, -which defaults to `true`. - -Other dependencies can be specified with the `dependencies` attribute, -which takes an array of hashes as follows: - -```ruby -smf 'redis' - -smf 'redis-6999' do - start_command "..." - dependencies [ - {name: 'redis', fmris: ['svc:/application/management/redis'], - grouping: 'require_all', restart_on: 'restart', type: 'service'} - ] -end -``` - -Valid options for grouping: -* require_all - All listed FMRIs must be online -* require_any - Any of the listed FMRIs must be online -* exclude_all - None of the listed FMRIs can be online -* optional_all - FMRIs are either online or unable to come online - -Valid options for restart_on: -* error - Hardware fault -* restart - Restarts service if the depedency is restarted -* refresh - Restarted if the dependency is restarted or refreshed for - any reason -* none - Don't do anything - -Valid options for type: -* service - expects dependency FMRIs to be other services ie: svc:/type/of/service:instance -* path - expects FMRIs to be paths, ie file://localhost/etc/redis/redis.conf - -Note: the provider currently does not do any validation of these values. Also, type:path has not been extensively -tested. Use this at your own risk, or improve the provider's compatibility with type:path and submit a pull request! - -### Duration - -There are several different ways that SMF can track your service. By default it uses `contract`. -Basically, this means that it will keep track of the PIDs of all daemonized processes generated from `start_command`. -If SMF sees that processes are cycling, it may try to restart the service. If things get too hectic, it -may think that your service is flailing and put it into maintenance mode. If this is normal for your service, -for instance if you have a master that occasionally reaps processes, you may want to specify additional -configuration options. - -If you have a job that you want managed by SMF, but which is not daemonized, another duration option is -`transient`. In this mode, SMF will not watch any processes, but will expect that the main process exits cleanly. -This can be used, for instance, for a script that must be run at boot time, or for a script that you want to delegate -to particular users with Role Based Access Control. In this case, the script can be registered with SMF to run as root, -but with the start_command delegated to your user. - -A third option is `wait`. This covers non-daemonized processes. - -A fourth option is `child`. - -### Ignore - -Sometimes you have a case where your service behaves poorly. The Ruby server Unicorn, for example, has a master -process that likes to kill its children. This causes core dumps that SMF will interpret to be a failing service. -Instead you can `ignore ["core", "signal"]` and SMF will stop caring about core dumps. - -### Privileges - -Some system calls require privileges generally only granted to superusers or particular roles. In Solaris, an -SMF definition can also set specific privileges for contracted processes. - -By default the SMF provider will grant 'basic' and 'net_privaddr' permissions, but this can be set as follows: - -```ruby -smf 'elasticsearch' do - start_command 'elasticsearch' - privileges ['basic', 'proc_lock_memory'] -end -``` - -See the (privileges man page)[https://www.illumos.org/man/5/privileges] for more information. - -### Property Groups - -Property Groups are where you can store extra information for SMF to use later. They should be used in the -following format: - -```ruby -smf "my-service" do - start_command "do-something" - property_groups({ - "config" => { - "type" => "application", - "my-property" => "property value" - } - }) -end -``` - -`type` will default to `application`, and is used in the manifest XML to declare how the property group will be -used. For this reason, `type` can not be used as a property name (ie variable). - -One way to use property groups is to pass variables on to commands, as follows: - -```ruby -rails_env = node["from-chef-environment"]["rails-env"] - -smf "unicorn" do - start_command "bundle exec unicorn_rails -c /home/app_user/app/current/config/%{config/rails_env} -E %{config/rails_env} -D" - start_timeout 300 - restart_command ":kill -SIGUSR2" - restart_timeout 300 - working_directory "/home/app_user/app/current" - property_groups({ - "config" => { - "rails_env" => rails_env - } - }) -end -``` - -This is especially handy if you have a case where your commands may come from role attributes, but can -only work if they have access to variables set in an environment or computed in a recipe. - -### Stability - -This is for reference more than anything, so that administrators of a service know what to expect of possible changes to -the service definition. - -See: - - -## Working Examples - -Please see the [examples](https://github.com/livinginthepast/smf/blob/master/EXAMPLES.md) page for -example usages. - - -## Cookbook upgrades, possible side effects - -Changes to this cookbook may change the way that its internal checksums are generated for a service. -If you `notify :restart` any service from within the `smf` block or include a `refresh_command`, please -be aware that upgrading this cookbook may trigger a refresh or a registered notification on the first -subsequent chef run. - -## Contributing - -* fork -* file an issue to track updates/communication -* add tests -* rebase master into your branch -* issue a pull request - -Please do not increment the cookbook version in a fork. Version updates -will be done on the master branch after any pull requests are merged. - -When upstream changes are added to the master branch while you are -working on a contribution, please rebase master into your branch and -force push. A pull request should be able to be merged through a -fast-forward, without a merge commit. - -## Testing - -```bash -bundle -vagrant plugin install vagrant-smartos-zones -bundle exec strainer test -``` diff --git a/cookbooks/smf/libraries/helper.rb b/cookbooks/smf/libraries/helper.rb deleted file mode 100644 index ab2b0c6..0000000 --- a/cookbooks/smf/libraries/helper.rb +++ /dev/null @@ -1,9 +0,0 @@ -unless defined?(SMFManifest::Helper) - module SMFManifest - # Generic helper that other helpers can inherit from. - # Takes the current node object, as well as an optional - # resource. - class Helper < Struct.new(:node, :resource) - end - end -end diff --git a/cookbooks/smf/libraries/matchers.rb b/cookbooks/smf/libraries/matchers.rb deleted file mode 100644 index e0242e3..0000000 --- a/cookbooks/smf/libraries/matchers.rb +++ /dev/null @@ -1,9 +0,0 @@ -if defined?(ChefSpec) - def install_smf(name) - ChefSpec::Matchers::ResourceMatcher.new(:smf, :install, name) - end - - def delete_smf(name) - ChefSpec::Matchers::ResourceMatcher.new(:smf, :delete, name) - end -end diff --git a/cookbooks/smf/libraries/rbac_helper.rb b/cookbooks/smf/libraries/rbac_helper.rb deleted file mode 100644 index 6461afe..0000000 --- a/cookbooks/smf/libraries/rbac_helper.rb +++ /dev/null @@ -1,31 +0,0 @@ -module SMFManifest - # Helper methods for determining whether work needs to be done - # with respect to assigning RBAC values to a service. - class RBACHelper < SMFManifest::Helper - include Chef::Mixin::ShellOut - - def authorization_set? - current_authorization == authorization - end - - def value_authorization_set? - current_value_authorization == value_authorization - end - - def current_authorization - shell_out("svcprop -p general/action_authorization #{resource.name}").stdout.chomp - end - - def current_value_authorization - shell_out("svcprop -p general/value_authorization #{resource.name}").stdout.chomp - end - - def authorization - "solaris.smf.manage.#{resource.authorization_name}" - end - - def value_authorization - "solaris.smf.value.#{resource.authorization_name}" - end - end -end diff --git a/cookbooks/smf/libraries/xml_builder.rb b/cookbooks/smf/libraries/xml_builder.rb deleted file mode 100644 index a9b7f7f..0000000 --- a/cookbooks/smf/libraries/xml_builder.rb +++ /dev/null @@ -1,209 +0,0 @@ -## This is kind of a hack, to ensure that the cookbook can be -# loaded. On first load, nokogiri may not be present. It is -# installed at load time by recipes/default.rb, so that at run -# time nokogiri will be present. -# -require 'forwardable' - -# rubocop:disable Metrics/ClassLength -module SMFManifest - # XMLBuilder manages the translation of the SMF Chef resource attributes into - # XML that can be parsed by `svccfg import`. - # - # SMFManifest::XMLBuilder.new(resource, node).to_xml - # - class XMLBuilder - # allow delegation - extend Forwardable - - attr_reader :resource, :node - - # delegate methods to :resource - def_delegators :resource, :name, :authorization_name, :dependencies, :duration, :environment, :group, :ignore, - :include_default_dependencies, :locale, :manifest_type, :project, :property_groups, - :service_path, :stability, :working_directory - - public - - def initialize(smf_resource, node) - @resource = smf_resource - @node = node - end - - def to_xml - @xml_output ||= xml_output - end - - protected - - ## methods that need to be called from within the context - # of the Nokogiri builder block need to be protected, rather - # than private. - - def commands - @commands ||= { - 'start' => resource.start_command, - 'stop' => resource.stop_command, - 'restart' => resource.restart_command, - 'refresh' => resource.refresh_command - } - end - - def timeout - @timeouts ||= { - 'start' => resource.start_timeout, - 'stop' => resource.stop_timeout, - 'restart' => resource.restart_timeout, - 'refresh' => resource.refresh_timeout - } - end - - def default_dependencies - if node.platform == 'solaris2' && node.platform_version == '5.11' - [ - { 'name' => 'milestone', 'value' => '/milestone/config' }, - { 'name' => 'fs-local', 'value' => '/system/filesystem/local' }, - { 'name' => 'name-services', 'value' => '/milestone/name-services' }, - { 'name' => 'network', 'value' => '/milestone/network' } - ] - else - [ - { 'name' => 'milestone', 'value' => '/milestone/sysconfig' }, - { 'name' => 'fs-local', 'value' => '/system/filesystem/local' }, - { 'name' => 'name-services', 'value' => '/milestone/name-services' }, - { 'name' => 'network', 'value' => '/milestone/network' } - ] - end - end - - private - - def xml_output - xml_builder = ::Builder::XmlMarkup.new(indent: 2) - xml_builder.instruct! - xml_builder.declare! :DOCTYPE, :service_bundle, :SYSTEM, '/usr/share/lib/xml/dtd/service_bundle.dtd.1' - xml_builder.service_bundle('name' => name, 'type' => 'manifest') do |xml| - xml.service('name' => service_fmri, 'type' => 'service', 'version' => '1') do |service| - service.create_default_instance('enabled' => 'false') - service.single_instance - - if include_default_dependencies - default_dependencies.each do |dependency| - service.dependency('name' => dependency['name'], - 'grouping' => 'require_all', - 'restart_on' => 'none', - 'type' => 'service') do |dep| - dep.service_fmri('value' => "svc:#{dependency['value']}") - end - end - end - - dependencies.each do |dependency| - service.dependency('name' => dependency['name'], - 'grouping' => dependency['grouping'], - 'restart_on' => dependency['restart_on'], - 'type' => dependency['type']) do |dep| - dependency['fmris'].each do |service_fmri| - dep.service_fmri('value' => service_fmri) - end - end - end - - service.method_context(exec_context) do |context| - context.method_credential(credentials) if user != 'root' - - if environment - context.method_environment do |env| - environment.each_pair do |var, value| - env.envvar('name' => var, 'value' => value) - end - end - end - end - - commands.each_pair do |type, command| - if command - service.exec_method('type' => 'method', 'name' => type, 'exec' => command, 'timeout_seconds' => timeout[type]) - end - end - - service.property_group('name' => 'general', 'type' => 'framework') do |group| - group.propval('name' => 'action_authorization', - 'type' => 'astring', - 'value' => "solaris.smf.manage.#{authorization_name}") - group.propval('name' => 'value_authorization', - 'type' => 'astring', - 'value' => "solaris.smf.value.#{authorization_name}") - end - - if sets_duration? || ignores_faults? - service.property_group('name' => 'startd', 'type' => 'framework') do |group| - group.propval('name' => 'duration', 'type' => 'astring', 'value' => duration) if sets_duration? - group.propval('name' => 'ignore_error', 'type' => 'astring', 'value' => ignore.join(',')) if ignores_faults? - end - end - - property_groups.each_pair do |name, properties| - service.property_group('name' => name, 'type' => properties.delete('type') { |_type| 'application' }) do |group| - properties.each_pair do |key, value| - group.propval('name' => key, 'value' => value, 'type' => check_type(value)) - end - end - end - - service.stability('value' => stability) - - service.template do |template| - template.common_name do |common_name| - common_name.loctext(name, 'xml:lang' => locale) - end - end - end - end - - xml_builder.target! - end - - def credentials - creds = { 'user' => user, 'privileges' => resource.privilege_list } - creds.merge!('group' => group) unless group.nil? - creds - end - - def user - resource.user || resource.credentials_user || 'root' - end - - def exec_context - context = {} - context['working_directory'] = working_directory unless working_directory.nil? - context['project'] = project unless project.nil? - context - end - - def check_type(value) - if value == value.to_i - 'integer' - else - 'astring' - end - end - - def ignores_faults? - !ignore.nil? - end - - def sets_duration? - duration != 'contract' - end - - # resource.fmri is set in the SMF :install action of the default provider. - # If there is already a service with a name that is matched by our resource.name - # then we grab the FMRI (fault management resource identifier) from the system. - # If a service is not found, we set this to our own FMRI. - def service_fmri - resource.fmri.nil? || resource.fmri.empty? ? "#{manifest_type}/management/#{name}" : resource.fmri.gsub(/^\//, '') - end - end -end -# rubocop:enable Metrics/ClassLength diff --git a/cookbooks/smf/metadata.json b/cookbooks/smf/metadata.json deleted file mode 100644 index d5aba81..0000000 --- a/cookbooks/smf/metadata.json +++ /dev/null @@ -1,48 +0,0 @@ -{ - "name": "smf", - "description": "A light weight resource provider (LWRP) for SMF (Service Management Facility)", - "long_description": "SMF\n===\n\n## Description\n\nService Management Facility (SMF) is a tool in many Illumos and Solaris-derived operating systems\nthat treats services as first class objects of the system. It provides an XML syntax for \ndeclaring how the system can interact with and control a service.\n\nThe SMF cookbook contains providers for creating or modifying a service within the SMF framework.\n\n\n## Requirements\n\nAny operating system that uses SMF, ie Solaris, SmartOS, OpenIndiana etc.\n\nThe `smf` provider depends on the `builder` gem, which can be installed\nvia the `smf::default` recipe.\n\nRequires the RBAC cookbook, which can be found at .\n\nProcesses can be run inside a project wrapper. In this case, look to the Resource Control cookbook,\nwhich can be found at . Note that the SMF LWRP\ndoes not create or manage the project.\n\n\n## Basic Usage\n\nNote that we run the `smf::default` recipe before using LWRPs from this\ncookbook.\n\n```ruby\ninclude_recipe 'smf'\n\nsmf 'my-service' do\n user 'non-root-user'\n start_command 'my-service start'\n start_timeout 10\n stop_command 'pkill my-service'\n stop_timeout 5\n restart_command 'my-service restart'\n restart_timeout 60\n environment 'PATH' => '/home/non-root-user/bin',\n 'RAILS_ENV' => 'staging'\n locale 'C'\n manifest_type 'application'\n service_path '/var/svc/manifest'\n notifies :restart, 'service[my-service]'\nend\n\nservice 'my-service' do\n action :enable\nend\n\nservice 'my-service' do\n action :restart\nend\n```\n\n\n## Attributes\n\nOwnership:\n* `user` - User to run service commands as\n* `group` - Group to run service commands as\n\nRBAC\n* `authorization` - What management and value authorizations should be\n created for this service. Defaults to the service name.\n\nDependency management:\n* `include_default_dependencies` - Service should depend on file system\n and network services. Defaults to `true`. See [Dependencies](#dependencies)\n for more info.\n* `dependency` - an optional array of hashes signifying service and path\n dependencies for this service to run. See [Dependencies](#dependencies).\n\nProcess management:\n* `project` - Name of project to run commands in\n* `start_command`\n* `start_timeout`\n* `stop_command` - defaults to `:kill`, which basically means it will destroy every PID generated from the start command\n* `stop_timeout`\n* `restart_command` - defaults to `stop_command`, then `start_command`\n* `restart_timeout`\n* `refresh_command` - by default SMF treats this as `true`. This will be called when the SMF definition changes or\n when a `notify :reload, 'service[thing]'` is called.\n* `refresh_timeout`\n* `duration` - Can be either `contract`, `wait`, `transient` or\n `child`, but defaults to `contract`. See the [Duration](#duration) section below.\n* `environment` - Hash - Environment variables to set while running commands\n* `ignore` - Array - Faults to ignore in subprocesses. For example, \n if core dumps in children are handled by a master process and you \n don't want SMF thinking the service is exploding, you can ignore \n [\"core\", \"signal\"].\n* `privileges` - Array - An array of privileges to be allowed for started processes.\n Defaults to ['basic', 'net_privaddr']\n* `property_groups` - Hash - This should be in the form `{\"group name\" => {\"type\" => \"application\", \"key\" => \"value\", ...}}`\n* `working_directory` - PWD that SMF should cd to in order to run commands\n* `locale` - Character encoding to use (default \"C\")\n\nManifest/FMRI metadata:\n* `service_path` - defaults to `/var/svc/manifest`\n* `manifest_type` - defaults to `application`\n* `stability` - String - defaults to \"Evolving\". Valid options are\n \"Standard\", \"Stable\", \"Evolving\", \"Unstable\", \"External\" and\n \"Obsolete\"\n\nDeprecated:\n* `credentials_user` - deprecated in favor of `user`\n\n\n## Provider Actions\n\n### :install (default)\n\nThis will drop a manifest XML file into `#{service_path}/#{manifest_type}/#{name}.xml`. If there is already a service\nwith a name that is matched by `new_resource.name` then the FMRI of our manifest will be set to the FMRI of the \npre-existing service. In this case, our properties will be merged into the properties of the pre-existing service.\n\nIn this way, updates to recipes that use the SMF provider will not delete existing service properties, but will add \nor overwrite them.\n\nBecause of this, the SMF provider can be used to update properties for\nservices that are installed via a package manager.\n\n### :delete\n\nRemove an SMF definition. This stops the service if it is running.\n\n### :add_rbac\n\nThis uses the `rbac` cookbook to define permissions that can then be applied to a user. This can be useful when local\nusers should manage services that are added via packages.\n\n```ruby\nsmf \"nginx\" do\n action :add_rbac\nend\n\nrbac_auth \"Allow my user to manage nginx\" do\n user \"my_user\"\n auth \"nginx\"\nend\n```\n\n\n## Resource Notes\n\n### `user`, `working_directory` and `environment`\n\nSMF does a remarkably good job running services as delegated users, and removes a lot of pain if you configure a \nservice correctly. There are many examples online (blogs, etc) of users wrapping their services in shell scripts with \n`start`, `stop`, `restart` arguments. In general it seems as if the intention of these scripts is to take care of the\nproblem of setting environment variables and shelling out as another user.\n\nThe use of init scripts to wrap executables can be unnecessary with SMF, as it provides hooks for all of these use cases. \nWhen using `user`, SMF will assume that the `working_directory` is the user's home directory. This can be\neasily overwritten (to `/home/user/app/current` for a Rails application, for example). One thing to be careful of is \nthat shell profile files will not be loaded. For this reason, if environment variables (such as PATH) are different \non your system or require additional entries arbitrary key/values may be set using the `environment` attribute.\n\nAll things considered, one should think carefully about the need for an init script when working with SMF. For \nwell-behaved applications with simple configuration, an init script is overkill. Applications with endless command-line \noptions or that need a real login shell (for instance ruby applications that use RVM) an init script may make life\neasier.\n\n### Role Based Authorization\n\nBy default the SMF definition creates authorizations based on the\nservice name. The service user is then granted these authorizations. If\nthe service is named `asplosions`, then `solaris.smf.manage.asplosions`\nand `solaris.smf.value.asplosions` will be created.\n\nThe authorization can be changed by manually setting `authorization` on\nthe smf block:\n\n```ruby\nsmf 'asplosions' do\n user 'monkeyking'\n start_command 'asplode'\n authorization 'booms'\nend\n```\n\nThis can be helpful if there are many services configured on a single\nhost, as multiple services can be collapsed into the same\nauthorizations. For instance: https://illumos.org/issues/4968 \n\n### Dependencies\n\nSMF allows services to explicitly list their dependencies on other\nservices. Among other things, this ensures that services are enabled in\nthe proper order on boot, so that a service doesn't fail to start\nbecause another service has not yet been started.\n\nBy default, services created by the SMF LWRP depend on the following other services:\n* svc:/milestone/sysconfig\n* svc:/system/filesystem/local\n* svc:/milestone/name-services\n* svc:/milestone/network\n\nOn Solaris11, `svc:/milestone/sysconfig` is replaced with\n`svc:/milestone/config`.\n\nThese are configured with the attribute `include_default_dependencies`,\nwhich defaults to `true`.\n\nOther dependencies can be specified with the `dependencies` attribute,\nwhich takes an array of hashes as follows:\n\n```ruby\nsmf 'redis'\n\nsmf 'redis-6999' do\n start_command \"...\"\n dependencies [\n {name: 'redis', fmris: ['svc:/application/management/redis'],\n grouping: 'require_all', restart_on: 'restart', type: 'service'}\n ]\nend\n```\n\nValid options for grouping:\n* require_all - All listed FMRIs must be online\n* require_any - Any of the listed FMRIs must be online\n* exclude_all - None of the listed FMRIs can be online\n* optional_all - FMRIs are either online or unable to come online\n\nValid options for restart_on:\n* error - Hardware fault\n* restart - Restarts service if the depedency is restarted\n* refresh - Restarted if the dependency is restarted or refreshed for\n any reason\n* none - Don't do anything\n\nValid options for type:\n* service - expects dependency FMRIs to be other services ie: svc:/type/of/service:instance\n* path - expects FMRIs to be paths, ie file://localhost/etc/redis/redis.conf\n\nNote: the provider currently does not do any validation of these values. Also, type:path has not been extensively\ntested. Use this at your own risk, or improve the provider's compatibility with type:path and submit a pull request!\n\n### Duration\n\nThere are several different ways that SMF can track your service. By default it uses `contract`. \nBasically, this means that it will keep track of the PIDs of all daemonized processes generated from `start_command`.\nIf SMF sees that processes are cycling, it may try to restart the service. If things get too hectic, it\nmay think that your service is flailing and put it into maintenance mode. If this is normal for your service,\nfor instance if you have a master that occasionally reaps processes, you may want to specify additional\nconfiguration options.\n\nIf you have a job that you want managed by SMF, but which is not daemonized, another duration option is\n`transient`. In this mode, SMF will not watch any processes, but will expect that the main process exits cleanly.\nThis can be used, for instance, for a script that must be run at boot time, or for a script that you want to delegate\nto particular users with Role Based Access Control. In this case, the script can be registered with SMF to run as root,\nbut with the start_command delegated to your user.\n\nA third option is `wait`. This covers non-daemonized processes.\n\nA fourth option is `child`.\n\n### Ignore\n\nSometimes you have a case where your service behaves poorly. The Ruby server Unicorn, for example, has a master \nprocess that likes to kill its children. This causes core dumps that SMF will interpret to be a failing service.\nInstead you can `ignore [\"core\", \"signal\"]` and SMF will stop caring about core dumps.\n\n### Privileges\n\nSome system calls require privileges generally only granted to superusers or particular roles. In Solaris, an\nSMF definition can also set specific privileges for contracted processes.\n\nBy default the SMF provider will grant 'basic' and 'net_privaddr' permissions, but this can be set as follows:\n\n```ruby\nsmf 'elasticsearch' do\n start_command 'elasticsearch'\n privileges ['basic', 'proc_lock_memory']\nend\n```\n\nSee the (privileges man page)[https://www.illumos.org/man/5/privileges] for more information.\n\n### Property Groups\n\nProperty Groups are where you can store extra information for SMF to use later. They should be used in the\nfollowing format:\n\n```ruby\nsmf \"my-service\" do\n start_command \"do-something\"\n property_groups({\n \"config\" => {\n \"type\" => \"application\",\n \"my-property\" => \"property value\"\n }\n })\nend\n```\n\n`type` will default to `application`, and is used in the manifest XML to declare how the property group will be\nused. For this reason, `type` can not be used as a property name (ie variable).\n\nOne way to use property groups is to pass variables on to commands, as follows:\n\n```ruby\nrails_env = node[\"from-chef-environment\"][\"rails-env\"]\n\nsmf \"unicorn\" do\n start_command \"bundle exec unicorn_rails -c /home/app_user/app/current/config/%{config/rails_env} -E %{config/rails_env} -D\"\n start_timeout 300\n restart_command \":kill -SIGUSR2\"\n restart_timeout 300\n working_directory \"/home/app_user/app/current\"\n property_groups({\n \"config\" => {\n \"rails_env\" => rails_env\n }\n })\nend\n```\n\nThis is especially handy if you have a case where your commands may come from role attributes, but can\nonly work if they have access to variables set in an environment or computed in a recipe.\n\n### Stability\n\nThis is for reference more than anything, so that administrators of a service know what to expect of possible changes to \nthe service definition.\n\nSee: \n\n\n## Working Examples\n\nPlease see the [examples](https://github.com/livinginthepast/smf/blob/master/EXAMPLES.md) page for\nexample usages.\n\n\n## Cookbook upgrades, possible side effects\n\nChanges to this cookbook may change the way that its internal checksums are generated for a service.\nIf you `notify :restart` any service from within the `smf` block or include a `refresh_command`, please\nbe aware that upgrading this cookbook may trigger a refresh or a registered notification on the first\nsubsequent chef run.\n\n## Contributing\n\n* fork\n* file an issue to track updates/communication\n* add tests\n* rebase master into your branch\n* issue a pull request\n\nPlease do not increment the cookbook version in a fork. Version updates\nwill be done on the master branch after any pull requests are merged.\n\nWhen upstream changes are added to the master branch while you are\nworking on a contribution, please rebase master into your branch and\nforce push. A pull request should be able to be merged through a\nfast-forward, without a merge commit.\n\n## Testing\n\n```bash\nbundle\nvagrant plugin install vagrant-smartos-zones\nbundle exec strainer test\n```\n", - "maintainer": "Eric Saxby", - "maintainer_email": "sax@livinginthepast.org", - "license": "MIT", - "platforms": { - "smartos": ">= 0.0.0" - }, - "dependencies": { - "rbac": ">= 1.0.1" - }, - "recommendations": { - - }, - "suggestions": { - "resource-control": ">= 0.0.0" - }, - "conflicting": { - - }, - "providing": { - - }, - "replacing": { - - }, - "attributes": { - - }, - "groupings": { - - }, - "recipes": { - - }, - "version": "2.2.8", - "source_url": "", - "issues_url": "", - "privacy": false, - "chef_versions": [ - - ], - "ohai_versions": [ - - ] -} diff --git a/cookbooks/smf/metadata.rb b/cookbooks/smf/metadata.rb deleted file mode 100644 index 94a4751..0000000 --- a/cookbooks/smf/metadata.rb +++ /dev/null @@ -1,13 +0,0 @@ -name 'smf' -maintainer 'Eric Saxby' -maintainer_email 'sax@livinginthepast.org' -license 'MIT' -description 'A light weight resource provider (LWRP) for SMF (Service Management Facility)' -long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) -version '2.2.8' - -supports 'smartos' - -depends 'rbac', '>= 1.0.1' - -suggests 'resource-control' # For managing Solaris projects, when setting project on a manifest diff --git a/cookbooks/smf/providers/default.rb b/cookbooks/smf/providers/default.rb deleted file mode 100644 index 76670e1..0000000 --- a/cookbooks/smf/providers/default.rb +++ /dev/null @@ -1,143 +0,0 @@ - -require 'chef/mixin/shell_out' -require 'fileutils' -include Chef::Mixin::ShellOut - -def load_current_resource - find_fmri unless new_resource.fmri - - @current_resource = Chef::Resource::Smf.new(new_resource.name) - @current_resource.fmri(new_resource.fmri) - @current_resource.load -end - -action :install do - create_directories - write_manifest - create_rbac_definitions - import_manifest - deduplicate_manifest - add_rbac_permissions - - new_resource.updated_by_last_action(smf_changed?) - new_resource.save_checksum if smf_changed? -end - -action :add_rbac do - create_rbac_definitions - service new_resource.name - - manage = execute "add SMF authorization to allow RBAC for #{new_resource.name}" do - command "svccfg -s #{new_resource.name} " \ - 'setprop general/action_authorization=astring:' \ - "'solaris.smf.manage.#{new_resource.authorization_name}'" - not_if { SMFManifest::RBACHelper.new(node, new_resource).authorization_set? } - notifies :reload, "service[#{new_resource.name}]" - end - - value = execute "add SMF value to allow RBAC for #{new_resource.name}" do - command "svccfg -s #{new_resource.name} " \ - 'setprop general/value_authorization=astring: ' \ - 'solaris.smf.value.#{new_resource.authorization_name}' - not_if { SMFManifest::RBACHelper.new(node, new_resource).value_authorization_set? } - notifies :reload, "service[#{new_resource.name}]" - end - - new_resource.updated_by_last_action(manage.updated_by_last_action? || value.updated_by_last_action?) -end - -action :delete do - new_resource.updated_by_last_action(false) - - if @current_resource.smf_exists? - service new_resource.name do - action [:stop, :disable] - end - - execute "remove service #{new_resource.name} from SMF" do - command "svccfg delete #{new_resource.name}" - end - - delete_manifest - new_resource.remove_checksum - - new_resource.updated_by_last_action(true) - end -end - -private - -def smf_changed? - @current_resource.checksum != new_resource.checksum || !@current_resource.smf_exists? -end - -def find_fmri - fmri_check = shell_out(%(svcs -H -o FMRI #{new_resource.name})) - if fmri_check.exitstatus == 0 - new_resource.fmri fmri_check.stdout.chomp.split(':')[1] - else - new_resource.fmri "/#{new_resource.manifest_type}/management/#{new_resource.name}" - end -end - -def create_directories - Chef::Log.debug "Creating manifest directory at #{new_resource.xml_path}" - FileUtils.mkdir_p new_resource.xml_path -end - -def write_manifest - return unless smf_changed? - - Chef::Log.debug "Writing SMF manifest for #{new_resource.name}" - ::File.open(new_resource.xml_file, 'w') do |file| - file.puts SMFManifest::XMLBuilder.new(new_resource, node).to_xml - end -end - -def delete_manifest - return unless ::File.exist?(new_resource.xml_file) - - Chef::Log.debug "Removing SMF manifest for #{new_resource.name}" - ::File.delete(new_resource.xml_file) -end - -def create_rbac_definitions - rbac new_resource.authorization_name do - action :create - end -end - -def add_rbac_permissions - user = new_resource.user || new_resource.credentials_user || 'root' - - rbac_auth "Add RBAC for #{new_resource.name} to #{user}" do - user user - auth new_resource.authorization_name - not_if { user == 'root' } - end -end - -def import_manifest - return unless smf_changed? - - Chef::Log.debug("importing SMF manifest #{new_resource.xml_file}") - shell_out!("svccfg import #{new_resource.xml_file}") -end - -def deduplicate_manifest - # If we are overwriting properties from an old SMF definition (from pkgsrc, etc) - # there may be redundant XML files that we want to dereference - name = new_resource.name - - duplicate_manifest = shell_out("svcprop #{name} | grep -c manifestfiles").stdout.strip.to_i > 1 - return unless duplicate_manifest - - Chef::Log.debug "Removing duplicate SMF manifest reference from #{name}" - shell_out! "svccfg -s #{name} delprop " \ - "`svcprop #{name} | grep manifestfiles | grep -v #{new_resource.xml_file} | awk '{ print $1 }'` " \ - "&& svcadm refresh #{name}" -end - -def smf_defined?(fmri) - shell_out("svcs #{fmri}").exitstatus == 0 -end diff --git a/cookbooks/smf/recipes/SMFServicesOK.rb b/cookbooks/smf/recipes/SMFServicesOK.rb deleted file mode 100644 index d3f5c1f..0000000 --- a/cookbooks/smf/recipes/SMFServicesOK.rb +++ /dev/null @@ -1,25 +0,0 @@ -directory '/opt/scripts' do - action :create - mode '0755' - owner 'root' - group 'root' -end - -directory '/opt/local/etc/snmp/conf.d' do - action :create - mode '0755' - owner 'root' - group 'root' -end - -template '/opt/scripts/SMFServicesOK.sh' do - path '/opt/scripts/SMFServicesOK.sh' - source 'SMFServicesOK.sh.erb' - mode '0755' -end - -template 'SMFServicesOK.snmpd.conf' do - path '/opt/local/etc/snmp/conf.d/SMFServicesOK.snmpd.conf' - source 'SMFServicesOK.snmpd.conf.erb' - mode '0644' -end diff --git a/cookbooks/smf/recipes/default.rb b/cookbooks/smf/recipes/default.rb deleted file mode 100644 index 72d8f16..0000000 --- a/cookbooks/smf/recipes/default.rb +++ /dev/null @@ -1,7 +0,0 @@ -## These libraries need to be installed when the cookbook -# is loaded, otherwise they are not available when the -# cookbook runs. - -chef_gem 'builder' - -require 'builder' diff --git a/cookbooks/smf/resources/default.rb b/cookbooks/smf/resources/default.rb deleted file mode 100644 index 6224e19..0000000 --- a/cookbooks/smf/resources/default.rb +++ /dev/null @@ -1,124 +0,0 @@ - -require 'chef/mixin/shell_out' -include Chef::Mixin::ShellOut - -actions :install, :add_rbac, :delete -default_action :install - -attribute :name, kind_of: String, name_attribute: true, required: true -attribute :user, kind_of: [String, NilClass], default: nil -attribute :group, kind_of: [String, NilClass], default: nil -attribute :project, kind_of: [String, NilClass], default: nil - -attribute :authorization, kind_of: [String, NilClass], default: nil - -attribute :start_command, kind_of: [String, NilClass], default: nil -attribute :start_timeout, kind_of: Integer, default: 5 -attribute :stop_command, kind_of: String, default: ':kill' -attribute :stop_timeout, kind_of: Integer, default: 5 -attribute :restart_command, kind_of: [String, NilClass], default: nil -attribute :restart_timeout, kind_of: Integer, default: 5 -attribute :refresh_command, kind_of: [String, NilClass], default: nil -attribute :refresh_timeout, kind_of: Integer, default: 5 - -attribute :include_default_dependencies, kind_of: [TrueClass, FalseClass], default: true -attribute :dependencies, kind_of: [Array], default: [] - -attribute :privileges, kind_of: [Array], default: %w(basic net_privaddr) -attribute :working_directory, kind_of: [String, NilClass], default: nil -attribute :environment, kind_of: [Hash, NilClass], default: nil -attribute :locale, kind_of: String, default: 'C' - -attribute :manifest_type, kind_of: String, default: 'application' -attribute :service_path, kind_of: String, default: '/var/svc/manifest' - -attribute :duration, kind_of: String, default: 'contract', regex: '(contract|wait|transient|child)' -attribute :ignore, kind_of: [Array, NilClass], default: nil -attribute :fmri, kind_of: String, default: nil - -attribute :stability, kind_of: String, equal_to: %w(Standard Stable Evolving Unstable External Obsolete), - default: 'Evolving' - -attribute :property_groups, kind_of: Hash, default: {} - -# Deprecated -attribute :credentials_user, kind_of: [String, NilClass], default: nil - -## internal methods - -def xml_path - "#{service_path}/#{manifest_type}" -end - -def xml_file - "#{xml_path}/#{name}.xml" -end - -require 'fileutils' -require 'digest/md5' - -# Save a checksum out to a file, for future chef runs -# -def save_checksum - Chef::Log.debug("Saving checksum for SMF #{name}: #{checksum}") - ::FileUtils.mkdir_p(Chef::Config.checksum_path) - f = ::File.new(checksum_file, 'w') - f.write checksum -end - -def remove_checksum - return unless ::File.exist?(checksum_file) - - Chef::Log.debug("Removing checksum for SMF #{name}") - ::File.delete(checksum_file) -end - -# Load current resource from checksum file and projects database. -# This should only ever be called on @current_resource, never on new_resource. -# -def load - @checksum ||= ::File.exist?(checksum_file) ? ::File.read(checksum_file) : '' - @smf_exists = shell_out("svcs #{fmri}").exitstatus == 0 - Chef::Log.debug("Loaded checksum for SMF #{name}: #{@checksum}") - Chef::Log.debug("SMF service already exists for #{fmri}? #{@smf_exists.inspect}") -end - -def authorization_name - authorization || name -end - -def checksum - attributes = [ - user, credentials_user, group, - project, start_command, start_timeout, stop_command, - stop_timeout, restart_command, restart_timeout, - refresh_command, refresh_timeout, working_directory, - locale, authorization, manifest_type, service_path, - duration, ignore.to_s, include_default_dependencies, - dependencies, fmri, stability, environment_as_string, - privilege_list, property_groups_as_string, '0' - ] - @checksum ||= Digest::MD5.hexdigest(attributes.join(':')) -end - -def checksum_file - "#{Chef::Config.checksum_path}/smf--#{name}" -end - -def environment_as_string - return nil if environment.nil? - environment.inject('') { |memo, k, v| memo << [k, v].join('|') } -end - -def privilege_list - privileges.join(',') -end - -def property_groups_as_string - return nil if property_groups.empty? - property_groups.inject('') { |memo, k, v| memo << [k, v].join('|') } -end - -def smf_exists? - !!@smf_exists -end diff --git a/cookbooks/smf/templates/default/SMFServicesOK.sh.erb b/cookbooks/smf/templates/default/SMFServicesOK.sh.erb deleted file mode 100644 index b135216..0000000 --- a/cookbooks/smf/templates/default/SMFServicesOK.sh.erb +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash -# if we're on SunOS 5.10+, we should check for beat services. - -if [ "`uname -s`" = "SunOS" ] && [ `uname -r|cut -d. -f1` -ge 5 ] && [ `uname -r|cut -d. -f2` -ge 10 ] -then - B=`svcs -Ha |egrep -v "disabled|online|legacy_run"` - if [ "foo$B" == "foo" ] - then - echo "OK" - else - echo $B - fi -fi diff --git a/cookbooks/smf/templates/default/SMFServicesOK.snmpd.conf.erb b/cookbooks/smf/templates/default/SMFServicesOK.snmpd.conf.erb deleted file mode 100644 index 8d3add8..0000000 --- a/cookbooks/smf/templates/default/SMFServicesOK.snmpd.conf.erb +++ /dev/null @@ -1 +0,0 @@ -extend SMFServicesOK /opt/scripts/SMFServicesOK.sh diff --git a/cookbooks/wordpress/README.md b/cookbooks/wordpress/README.md index 1a99f24..3e42565 100644 --- a/cookbooks/wordpress/README.md +++ b/cookbooks/wordpress/README.md @@ -51,7 +51,6 @@ Attributes * `node['wordpress']['db']['port']` - Port of the WordPress MySQL database. * `node['wordpress']['db']['charset']` - [Character set](http://dev.mysql.com/doc/refman/5.7/en/charset-charsets.html) of the WordPress MySQL database tables. Defaults to 'utf8'. * `node['wordpress']['db']['collate']` - [Collation](http://dev.mysql.com/doc/refman/5.7/en/charset-collation-effect.html) of the WordPress MySQL database tables. -* `node['wordpress']['db']['mysql_version']` - Version of MySQL to install (for supporting community cookbook version 6+) * `node['wordpress']['allow_multisite']` - Enable [multisite](http://codex.wordpress.org/Create_A_Network) features (default: false). * `node['wordpress']['wp_config_options']` - A hash of options to define in wp_config.php, output as key value pairs into a PHP constant e.g. `define( '<%= @key %>', <%= @value %> );`. Note: for values you will need to add single quotes around text but omit them for booleans and numbers. (default: {}). diff --git a/cookbooks/wordpress/attributes/default.rb b/cookbooks/wordpress/attributes/default.rb index 873753d..92d9b86 100644 --- a/cookbooks/wordpress/attributes/default.rb +++ b/cookbooks/wordpress/attributes/default.rb @@ -35,25 +35,6 @@ default['wordpress']['db']['host'] = 'localhost' default['wordpress']['db']['port'] = '3306' # Must be a string default['wordpress']['db']['charset'] = 'utf8' default['wordpress']['db']['collate'] = '' -case node['platform'] -when 'ubuntu' - case node['platform_version'] - when '10.04' - default['wordpress']['db']['mysql_version'] = '5.1' - else - default['wordpress']['db']['mysql_version'] = '5.5' - end -when 'centos', 'redhat', 'amazon', 'scientific' - if node['platform_version'].to_i < 6 - default['wordpress']['db']['mysql_version'] = '5.0' - elsif node['platform_version'].to_i < 7 - default['wordpress']['db']['mysql_version'] = '5.1' - else - default['wordpress']['db']['mysql_version'] = '5.5' - end -else - default['wordpress']['db']['mysql_version'] = '5.5' -end default['wordpress']['allow_multisite'] = false diff --git a/cookbooks/wordpress/metadata.rb b/cookbooks/wordpress/metadata.rb index 344c6c5..e7e8515 100644 --- a/cookbooks/wordpress/metadata.rb +++ b/cookbooks/wordpress/metadata.rb @@ -16,7 +16,7 @@ end depends "apache2", ">= 2.0.0" depends "database", ">= 1.6.0" depends "mysql", ">= 6.0" -depends "mysql2_chef_gem", "~> 1.0.1" +depends "mysql2_chef_gem", ">= 1.0.1" depends "build-essential" depends "iis", ">= 1.6.2" depends "tar", ">= 0.3.1" diff --git a/cookbooks/wordpress/recipes/database.rb b/cookbooks/wordpress/recipes/database.rb index 3f61d78..cdbac48 100644 --- a/cookbooks/wordpress/recipes/database.rb +++ b/cookbooks/wordpress/recipes/database.rb @@ -44,7 +44,6 @@ if is_local_host? db['host'] mysql_service db['instance_name'] do port db['port'] - version db['mysql_version'] initial_root_password db['root_password'] action [:create, :start] end @@ -52,6 +51,11 @@ if is_local_host? db['host'] socket = "/var/run/mysql-#{db['instance_name']}/mysqld.sock" if node['platform_family'] == 'debian' + directory "/var/run/mysqld" do + action :create + owner "mysql" + group "mysql" + end link '/var/run/mysqld/mysqld.sock' do to socket not_if 'test -f /var/run/mysqld/mysqld.sock' diff --git a/cookbooks/yum-epel/CHANGELOG.md b/cookbooks/yum-epel/CHANGELOG.md index d5f01c2..fcf4def 100644 --- a/cookbooks/yum-epel/CHANGELOG.md +++ b/cookbooks/yum-epel/CHANGELOG.md @@ -1,104 +1,42 @@ -# yum-epel Cookbook CHANGELOG - -This file is used to list changes made in each version of the yum-epel cookbook. - -## v0.7.1 (2016-08-19) -- Remove bats testing -- Fix attribute settings -- Cleanup travis file - -## v0.7.0 (2016-04-27) - -- Added support for IBM zlinux platform -- Added back the Test Kitchen support for local vagrant testing -- Added long_description to the metadata -- Loosen the dependency on the yum cookbook - -## v0.6.5 - -- updated to use `make_cache` option that yum cookbook allows for the yum resource to use. - -## v0.6.5 (2015-11-23) - -- Fix setting bool false properties - -## v0.6.4 (2015-10-27) - -- Updating default recipe for Chef 13 deprecation warnings. Not -- passing nil. - -## v0.6.3 (2015-09-22) - -- Added standard Chef gitignore and chefignore files -- Added the standard chef rubocop config -- Update contributing, maintainers, and testing docs -- Update Chefspec config to 4.X format -- Update distro versions in the Kitchen config -- Add Travis CI and cookbook version badges in the readme -- Expand the requirements section in the readme -- Add additional distros to the metadata -- Added source_url and issues_url metadata - -## v0.6.2 (2015-06-21) - -- Depending on yum ~> 3.2 -- Support for the password attribute wasn't added to the -- yum_repository LWRP until yum 3.2.0. - -## v0.6.1 (2015-06-21) - -- Switching to https for URL links -- Using metalink URLs - -## v0.6.0 (2015-01-03) - -- Adding EL7 support - -## v0.5.3 (2014-10-28) - -- Revert Use HTTPS for GPG keys and mirror lists - -## v0.5.2 (2014-10-28) - -- Use HTTPS for GPG keys and mirror lists -- Use local key on Amazon Linux - -## v0.5.0 (2014-09-02) - -- Add all attribute available to LWRP to allow for tuning. - -## v0.4.0 (2014-07-27) - -- [#9] Allowing list of repositories to reference configurable. - -## v0.3.6 (2014-04-09) +yum-epel Cookbook CHANGELOG +====================== +This file is used to list changes made in each version of the yum-centos cookbook. +v0.3.6 (2014-04-09) +------------------- - [COOK-4509] add RHEL7 support to yum-epel cookbook -## v0.3.4 (2014-02-19) +v0.3.4 (2014-02-19) +------------------- COOK-4353 - Fixing typo in readme -## v0.3.2 (2014-02-13) +v0.3.2 (2014-02-13) +------------------- Updating README to explain the 'managed' parameter -## v0.3.0 (2014-02-12) +v0.3.0 (2014-02-12) +------------------- [COOK-4292] - Do not manage secondary repos by default -## v0.2.0 +v0.2.0 +------ Adding Amazon Linux support -## v0.1.6 +v0.1.6 +------ Fixing up attribute values for EL6 -## v0.1.4 +v0.1.4 +------ Adding CHANGELOG.md -## v0.1.0 +v0.1.0 +------ initial release diff --git a/cookbooks/yum-epel/CONTRIBUTING.md b/cookbooks/yum-epel/CONTRIBUTING.md deleted file mode 100644 index ef2f2b8..0000000 --- a/cookbooks/yum-epel/CONTRIBUTING.md +++ /dev/null @@ -1,2 +0,0 @@ -Please refer to -https://github.com/chef-cookbooks/community_cookbook_documentation/blob/master/CONTRIBUTING.MD diff --git a/cookbooks/yum-epel/MAINTAINERS.md b/cookbooks/yum-epel/MAINTAINERS.md deleted file mode 100644 index 2cf4d2f..0000000 --- a/cookbooks/yum-epel/MAINTAINERS.md +++ /dev/null @@ -1,19 +0,0 @@ - - -# Maintainers -This file lists how this cookbook project is maintained. When making changes to the system, this -file tells you who needs to review your patch - you need a simple majority of maintainers -for the relevant subsystems to provide a :+1: on your pull request. Additionally, you need -to not receive a veto from a Lieutenant or the Project Lead. - -Check out [How Cookbooks are Maintained](https://github.com/chef-cookbooks/community_cookbook_documentation/blob/master/CONTRIBUTING.MD) -for details on the process and how to become a maintainer or the project lead. - -# Project Maintainer -* [Jennifer Davis](https://github.com/sigje) - -# Maintainers -* [Jennifer Davis](https://github.com/sigje) -* [Sean OMeara](https://github.com/someara) -* [Tim Smith](https://github.com/tas50) -* [Thom May](https://github.com/thommay) diff --git a/cookbooks/yum-epel/README.md b/cookbooks/yum-epel/README.md index d6f37a1..c4550f3 100644 --- a/cookbooks/yum-epel/README.md +++ b/cookbooks/yum-epel/README.md @@ -1,28 +1,21 @@ -# yum-epel Cookbook -[![Build Status](https://travis-ci.org/chef-cookbooks/yum-epel.svg?branch=master)](http://travis-ci.org/chef-cookbooks/yum-epel) [![Cookbook Version](https://img.shields.io/cookbook/v/yum-epel.svg)](https://supermarket.chef.io/cookbooks/yum-epel) +yum-epel Cookbook +============ -Extra Packages for Enterprise Linux (or EPEL) is a Fedora Special Interest Group that creates, maintains, and manages a high quality set of additional packages for Enterprise Linux, including, but not limited to, Red Hat Enterprise Linux (RHEL), CentOS and Scientific Linux (SL), Oracle Linux (OL). +The yum-epel cookbook takes over management of the default +repositoryids shipped with epel-release. It allows attribute +manipulation of `epel`, `epel-debuginfo`, `epel-source`, `epel-testing`, +`epel-testing-debuginfo`, and `epel-testing-source`. -The yum-epel cookbook takes over management of the default repositoryids shipped with epel-release. It allows attribute manipulation of `epel`, `epel-debuginfo`, `epel-source`, `epel-testing`, `epel-testing-debuginfo`, and `epel-testing-source`. +Requirements +------------ +* Chef 11 or higher +* yum cookbook version 3.0.0 or higher -## Requirements -### Platforms -- RHEL/CentOS and derivatives - -### Chef -- Chef 11+ - -### Cookbooks -- yum version 3.6.3 or higher - -## Attributes +Attributes +---------- The following attributes are set by default -```ruby -default['yum-epel']['repositories'] = %w{epel epel-debuginfo epel-source epel-testing epel-testing-debuginfo epel-testing-source} -``` - -```ruby +``` ruby default['yum']['epel']['repositoryid'] = 'epel' default['yum']['epel']['description'] = 'Extra Packages for Enterprise Linux 6 - $basearch' default['yum']['epel']['mirrorlist'] = 'http://mirrors.fedoraproject.org/mirrorlist?repo=epel-5&arch=$basearch' @@ -33,7 +26,7 @@ default['yum']['epel']['enabled'] = true default['yum']['epel']['managed'] = true ``` -```ruby +``` ruby default['yum']['epel-debuginfo']['repositoryid'] = 'epel-debuginfo' default['yum']['epel-debuginfo']['description'] = 'Extra Packages for Enterprise Linux 6 - $basearch - Debug' default['yum']['epel-debuginfo']['mirrorlist'] = 'https://mirrors.fedoraproject.org/metalink?repo=epel-debug-6&arch=$basearch' @@ -44,7 +37,7 @@ default['yum']['epel-debuginfo']['enabled'] = false default['yum']['epel-debuginfo']['managed'] = false ``` -```ruby +``` ruby default['yum']['epel-source']['repositoryid'] = 'epel-source' default['yum']['epel-source']['description'] = 'Extra Packages for Enterprise Linux 6 - $basearch - Source' default['yum']['epel-source']['mirrorlist'] = 'http://mirrors.fedoraproject.org/mirrorlist?repo=epel-source-6&arch=$basearch' @@ -55,7 +48,7 @@ default['yum']['epel-source']['enabled'] = false default['yum']['epel-source']['managed'] = false ``` -```ruby +``` ruby default['yum']['epel-testing']['repositoryid'] = 'epel-testing' default['yum']['epel-testing']['description'] = 'Extra Packages for Enterprise Linux 6 - Testing - $basearch' default['yum']['epel-testing']['mirrorlist'] = 'https://mirrors.fedoraproject.org/metalink?repo=testing-epel6&arch=$basearch' @@ -66,7 +59,7 @@ default['yum']['epel-testing']['enabled'] = false default['yum']['epel-testing']['managed'] = false ``` -```ruby +``` ruby default['yum']['epel-testing-debuginfo']['repositoryid'] = 'epel-testing-debuginfo' default['yum']['epel-testing-debuginfo']['description'] = 'Extra Packages for Enterprise Linux 6 - Testing - $basearch Debug' default['yum']['epel-testing-debuginfo']['mirrorlist'] = 'https://mirrors.fedoraproject.org/metalink?repo=testing-debug-epel6&arch=$basearch' @@ -77,7 +70,7 @@ default['yum']['epel-testing-debuginfo']['enabled'] = false default['yum']['epel-testing-debuginfo']['managed'] = false ``` -```ruby +``` ruby default['yum']['epel-testing-source']['repositoryid'] = 'epel-testing-source' default['yum']['epel-testing-source']['description'] = 'Extra Packages for Enterprise Linux 6 - Testing - $basearch Source' default['yum']['epel-testing-source']['mirrorlist'] = 'https://mirrors.fedoraproject.org/metalink?repo=testing-source-epel6&arch=$basearch' @@ -88,10 +81,11 @@ default['yum']['epel-testing-source']['enabled'] = false default['yum']['epel-testing-source']['managed'] = false ``` -## Recipes -- default - Walks through node attributes and feeds a yum_resource -- parameters. The following is an example a resource generated by the -- recipe during compilation. +Recipes +------- +* default - Walks through node attributes and feeds a yum_resource + parameters. The following is an example a resource generated by the + recipe during compilation. ```ruby yum_repository 'epel' do @@ -103,7 +97,8 @@ default['yum']['epel-testing-source']['managed'] = false end ``` -## Usage Example +Usage Example +------------- To disable the epel repository through a Role or Environment definition ``` @@ -118,18 +113,22 @@ default_attributes( ) ``` -Uncommonly used repositoryids are not managed by default. This is speeds up integration testing pipelines by avoiding yum-cache builds that nobody cares about. To enable the epel-testing repository with a wrapper cookbook, place the following in a recipe: +Uncommonly used repositoryids are not managed by default. This is +speeds up integration testing pipelines by avoiding yum-cache builds +that nobody cares about. To enable the epel-testing repository with a +wrapper cookbook, place the following in a recipe: -```ruby +``` node.default['yum']['epel-testing']['enabled'] = true node.default['yum']['epel-testing']['managed'] = true include_recipe 'yum-epel' ``` -## More Examples +More Examples +------------- Point the epel repositories at an internally hosted server. -```ruby +``` node.default['yum']['epel']['enabled'] = true node.default['yum']['epel']['mirrorlist'] = nil node.default['yum']['epel']['baseurl'] = 'https://internal.example.com/centos/6/os/x86_64' @@ -138,12 +137,13 @@ node.default['yum']['epel']['sslverify'] = false include_recipe 'yum-epel' ``` -## License & Authors -**Author:** Cookbook Engineering Team ([cookbooks@chef.io](mailto:cookbooks@chef.io)) +License & Authors +----------------- +- Author:: Sean OMeara () -**Copyright:** 2011-2016, Chef Software, Inc. +```text +Copyright:: 2011-2013 Opscode, Inc. -``` Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at diff --git a/cookbooks/yum-epel/attributes/default.rb b/cookbooks/yum-epel/attributes/default.rb deleted file mode 100644 index 5b03a69..0000000 --- a/cookbooks/yum-epel/attributes/default.rb +++ /dev/null @@ -1 +0,0 @@ -default['yum-epel']['repositories'] = %w(epel epel-debuginfo epel-source epel-testing epel-testing-debuginfo epel-testing-source) diff --git a/cookbooks/yum-epel/attributes/epel-debuginfo.rb b/cookbooks/yum-epel/attributes/epel-debuginfo.rb index 1f51fdd..0e72757 100644 --- a/cookbooks/yum-epel/attributes/epel-debuginfo.rb +++ b/cookbooks/yum-epel/attributes/epel-debuginfo.rb @@ -1,15 +1,28 @@ default['yum']['epel-debuginfo']['repositoryid'] = 'epel-debuginfo' -default['yum']['epel-debuginfo']['description'] = 'Extra Packages for $releasever - $basearch - Debug' -if node['platform'] == 'amazon' - default['yum']['epel-debuginfo']['mirrorlist'] = 'http://mirrors.fedoraproject.org/mirrorlist?repo=epel-debug-6&arch=$basearch' +case node['platform'] +when 'amazon' + default['yum']['epel-debuginfo']['description'] = 'Extra Packages for Enterprise Linux 6 - $basearch' + default['yum']['epel-debuginfo']['mirrorlist'] = 'http://mirrors.fedoraproject.org/mirrorlist?repo=epel-6&arch=$basearch' default['yum']['epel-debuginfo']['gpgkey'] = 'http://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-6' else - default['yum']['epel-debuginfo']['mirrorlist'] = "http://mirrors.fedoraproject.org/mirrorlist?repo=epel-debug-#{node['platform_version'].to_i}&arch=$basearch" - default['yum']['epel-debuginfo']['gpgkey'] = (node['platform_version'].to_i == 5 ? 'http://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL' : "https://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-#{node['platform_version'].to_i}") + case node['platform_version'].to_i + when 5 + default['yum']['epel-debuginfo']['description'] = 'Extra Packages for Enterprise Linux 5 - $basearch - Debug' + default['yum']['epel-debuginfo']['mirrorlist'] = 'http://mirrors.fedoraproject.org/mirrorlist?repo=epel-debug-5&arch=$basearch' + default['yum']['epel-debuginfo']['gpgkey'] = 'http://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL' + when 6 + default['yum']['epel-debuginfo']['description'] = 'Extra Packages for Enterprise Linux 6 - $basearch - Debug' + default['yum']['epel-debuginfo']['mirrorlist'] = 'https://mirrors.fedoraproject.org/metalink?repo=epel-debug-6&arch=$basearch' + default['yum']['epel-debuginfo']['gpgkey'] = 'http://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-6' + when 7 + default['yum']['epel-debuginfo']['description'] = 'Extra Packages for Enterprise Linux 7 - $basearch - Debug' + default['yum']['epel-debuginfo']['mirrorlist'] = 'https://mirrors.fedoraproject.org/metalink?repo=epel-debug-7&arch=$basearch' + default['yum']['epel-debuginfo']['gpgkey'] = 'http://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-7' + end end + default['yum']['epel-debuginfo']['failovermethod'] = 'priority' default['yum']['epel-debuginfo']['gpgcheck'] = true default['yum']['epel-debuginfo']['enabled'] = false default['yum']['epel-debuginfo']['managed'] = false -default['yum']['epel-debuginfo']['make_cache'] = true diff --git a/cookbooks/yum-epel/attributes/epel-source.rb b/cookbooks/yum-epel/attributes/epel-source.rb index 670bcc0..1433eed 100644 --- a/cookbooks/yum-epel/attributes/epel-source.rb +++ b/cookbooks/yum-epel/attributes/epel-source.rb @@ -1,15 +1,28 @@ default['yum']['epel-source']['repositoryid'] = 'epel-source' -default['yum']['epel-source']['description'] = 'Extra Packages for $releasever - $basearch - Source' -if node['platform'] == 'amazon' - default['yum']['epel-source']['mirrorlist'] = 'http://mirrors.fedoraproject.org/mirrorlist?repo=epel-source-6&arch=$basearch' + +case node['platform'] +when 'amazon' + default['yum']['epel-source']['description'] = 'Extra Packages for Enterprise Linux 6 - $basearch' + default['yum']['epel-source']['mirrorlist'] = 'http://mirrors.fedoraproject.org/mirrorlist?repo=epel-6&arch=$basearch' default['yum']['epel-source']['gpgkey'] = 'http://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-6' else - default['yum']['epel-source']['mirrorlist'] = "http://mirrors.fedoraproject.org/mirrorlist?repo=epel-source-#{node['platform_version'].to_i}&arch=$basearch" - default['yum']['epel-source']['gpgkey'] = (node['platform_version'].to_i == 5 ? 'http://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL' : "https://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-#{node['platform_version'].to_i}") + case node['platform_version'].to_i + when 5 + default['yum']['epel-source']['description'] = 'Extra Packages for Enterprise Linux 5 - $basearch - Source' + default['yum']['epel-source']['mirrorlist'] = 'http://mirrors.fedoraproject.org/mirrorlist?repo=epel-source-5&arch=$basearch' + default['yum']['epel-source']['gpgkey'] = 'http://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL' + when 6 + default['yum']['epel-source']['description'] = 'Extra Packages for Enterprise Linux 6 - $basearch - Source' + default['yum']['epel-source']['mirrorlist'] = 'http://mirrors.fedoraproject.org/mirrorlist?repo=epel-source-6&arch=$basearch' + default['yum']['epel-source']['gpgkey'] = 'http://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-6' + when 7 + default['yum']['epel-source']['description'] = 'Extra Packages for Enterprise Linux 7 - $basearch - Source' + default['yum']['epel-source']['mirrorlist'] = 'http://mirrors.fedoraproject.org/mirrorlist?repo=epel-source-7&arch=$basearch' + default['yum']['epel-source']['gpgkey'] = 'http://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-7' + end end default['yum']['epel-source']['failovermethod'] = 'priority' default['yum']['epel-source']['gpgcheck'] = true default['yum']['epel-source']['enabled'] = false default['yum']['epel-source']['managed'] = false -default['yum']['epel-source']['make_cache'] = true diff --git a/cookbooks/yum-epel/attributes/epel-testing-debuginfo.rb b/cookbooks/yum-epel/attributes/epel-testing-debuginfo.rb index fa8234b..14353dc 100644 --- a/cookbooks/yum-epel/attributes/epel-testing-debuginfo.rb +++ b/cookbooks/yum-epel/attributes/epel-testing-debuginfo.rb @@ -1,15 +1,24 @@ default['yum']['epel-testing-debuginfo']['repositoryid'] = 'epel-testing-debuginfo' -default['yum']['epel-testing-debuginfo']['description'] = 'Extra Packages for $releasever - $basearch - Testing Debug' -if node['platform'] == 'amazon' - default['yum']['epel-testing-debuginfo']['mirrorlist'] = 'http://mirrors.fedoraproject.org/mirrorlist?repo=testing-debug-epel6&arch=$basearch' + +case node['platform'] +when 'amazon' + default['yum']['epel-testing-debuginfo']['description'] = 'Extra Packages for Enterprise Linux 6 - $basearch' + default['yum']['epel-testing-debuginfo']['mirrorlist'] = 'http://mirrors.fedoraproject.org/mirrorlist?repo=epel-6&arch=$basearch' default['yum']['epel-testing-debuginfo']['gpgkey'] = 'http://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-6' else - default['yum']['epel-testing-debuginfo']['mirrorlist'] = "http://mirrors.fedoraproject.org/mirrorlist?repo=testing-debug-epel#{node['platform_version'].to_i}&arch=$basearch" - default['yum']['epel-testing-debuginfo']['gpgkey'] = (node['platform_version'].to_i == 5 ? 'http://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL' : "https://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-#{node['platform_version'].to_i}") + case node['platform_version'].to_i + when 5 + default['yum']['epel-testing-debuginfo']['description'] = 'Extra Packages for Enterprise Linux 5 - Testing - $basearch Debug' + default['yum']['epel-testing-debuginfo']['mirrorlist'] = 'http://mirrors.fedoraproject.org/mirrorlist?repo=testing-debug-epel5&arch=$basearch' + default['yum']['epel-testing-debuginfo']['gpgkey'] = 'http://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL' + when 6 + default['yum']['epel-testing-debuginfo']['description'] = 'Extra Packages for Enterprise Linux 6 - Testing - $basearch Debug' + default['yum']['epel-testing-debuginfo']['mirrorlist'] = 'https://mirrors.fedoraproject.org/metalink?repo=testing-debug-epel6&arch=$basearch' + default['yum']['epel-testing-debuginfo']['gpgkey'] = 'http://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-6' + end end default['yum']['epel-testing-debuginfo']['failovermethod'] = 'priority' default['yum']['epel-testing-debuginfo']['gpgcheck'] = true default['yum']['epel-testing-debuginfo']['enabled'] = false default['yum']['epel-testing-debuginfo']['managed'] = false -default['yum']['epel-testing-debuginfo']['make_cache'] = true diff --git a/cookbooks/yum-epel/attributes/epel-testing-source.rb b/cookbooks/yum-epel/attributes/epel-testing-source.rb index 731ef06..7f82192 100644 --- a/cookbooks/yum-epel/attributes/epel-testing-source.rb +++ b/cookbooks/yum-epel/attributes/epel-testing-source.rb @@ -1,14 +1,24 @@ default['yum']['epel-testing-source']['repositoryid'] = 'epel-testing-source' -default['yum']['epel-testing-source']['description'] = 'Extra Packages for $releasever - $basearch - Testing Source' -if node['platform'] == 'amazon' - default['yum']['epel-testing-source']['mirrorlist'] = 'http://mirrors.fedoraproject.org/mirrorlist?repo=testing-source-epel6&arch=$basearch' + +case node['platform'] +when 'amazon' + default['yum']['epel-testing-source']['description'] = 'Extra Packages for Enterprise Linux 6 - $basearch' + default['yum']['epel-testing-source']['mirrorlist'] = 'http://mirrors.fedoraproject.org/mirrorlist?repo=epel-6&arch=$basearch' default['yum']['epel-testing-source']['gpgkey'] = 'http://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-6' else - default['yum']['epel-testing-source']['mirrorlist'] = "http://mirrors.fedoraproject.org/mirrorlist?repo=testing-source-epel#{node['platform_version'].to_i}&arch=$basearch" - default['yum']['epel-testing-source']['gpgkey'] = (node['platform_version'].to_i == 5 ? 'http://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL' : "https://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-#{node['platform_version'].to_i}") + case node['platform_version'].to_i + when 5 + default['yum']['epel-testing-source']['description'] = 'Extra Packages for Enterprise Linux 5 - Testing - $basearch Source' + default['yum']['epel-testing-source']['mirrorlist'] = 'http://mirrors.fedoraproject.org/mirrorlist?repo=testing-source-epel5&arch=$basearch' + default['yum']['epel-testing-source']['gpgkey'] = 'http://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL' + when 6 + default['yum']['epel-testing-source']['description'] = 'Extra Packages for Enterprise Linux 6 - Testing - $basearch Source' + default['yum']['epel-testing-source']['mirrorlist'] = 'https://mirrors.fedoraproject.org/metalink?repo=testing-source-epel6&arch=$basearch' + default['yum']['epel-testing-source']['gpgkey'] = 'http://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-6' + end end + default['yum']['epel-testing-source']['failovermethod'] = 'priority' default['yum']['epel-testing-source']['gpgcheck'] = true default['yum']['epel-testing-source']['enabled'] = false default['yum']['epel-testing-source']['managed'] = false -default['yum']['epel-testing-source']['make_cache'] = true diff --git a/cookbooks/yum-epel/attributes/epel-testing.rb b/cookbooks/yum-epel/attributes/epel-testing.rb index 2a3c6d8..d54a0f1 100644 --- a/cookbooks/yum-epel/attributes/epel-testing.rb +++ b/cookbooks/yum-epel/attributes/epel-testing.rb @@ -1,15 +1,24 @@ default['yum']['epel-testing']['repositoryid'] = 'epel-testing' -default['yum']['epel-testing']['description'] = 'Extra Packages for $releasever - $basearch - Testing ' -if node['platform'] == 'amazon' - default['yum']['epel-testing-source']['mirrorlist'] = 'http://mirrors.fedoraproject.org/mirrorlist?repo=testing-epel6&arch=$basearch' - default['yum']['epel-testing-source']['gpgkey'] = 'http://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-6' + +case node['platform'] +when 'amazon' + default['yum']['epel-testing']['description'] = 'Extra Packages for Enterprise Linux 6 - $basearch' + default['yum']['epel-testing']['mirrorlist'] = 'http://mirrors.fedoraproject.org/mirrorlist?repo=epel-6&arch=$basearch' + default['yum']['epel-testing']['gpgkey'] = 'http://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-6' else - default['yum']['epel-testing-source']['mirrorlist'] = "http://mirrors.fedoraproject.org/mirrorlist?repo=testing-source-epel#{node['platform_version'].to_i}&arch=$basearch" - default['yum']['epel-testing-source']['gpgkey'] = (node['platform_version'].to_i == 5 ? 'http://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL' : "https://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-#{node['platform_version'].to_i}") + case node['platform_version'].to_i + when 5 + default['yum']['epel-testing']['description'] = 'Extra Packages for Enterprise Linux 5 - Testing - $basearch' + default['yum']['epel-testing']['mirrorlist'] = 'http://mirrors.fedoraproject.org/mirrorlist?repo=testing-epel5&arch=$basearch' + default['yum']['epel-testing']['gpgkey'] = 'http://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL' + when 6 + default['yum']['epel-testing']['description'] = 'Extra Packages for Enterprise Linux 6 - Testing - $basearch' + default['yum']['epel-testing']['mirrorlist'] = 'https://mirrors.fedoraproject.org/metalink?repo=testing-epel6&arch=$basearch' + default['yum']['epel-testing']['gpgkey'] = 'http://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-6' + end end default['yum']['epel-testing']['failovermethod'] = 'priority' default['yum']['epel-testing']['gpgcheck'] = true default['yum']['epel-testing']['enabled'] = false default['yum']['epel-testing']['managed'] = false -default['yum']['epel-testing']['make_cache'] = true diff --git a/cookbooks/yum-epel/attributes/epel.rb b/cookbooks/yum-epel/attributes/epel.rb index 9ee912f..07dceb6 100644 --- a/cookbooks/yum-epel/attributes/epel.rb +++ b/cookbooks/yum-epel/attributes/epel.rb @@ -1,17 +1,24 @@ default['yum']['epel']['repositoryid'] = 'epel' -default['yum']['epel']['description'] = 'Extra Packages for $releasever - $basearch' -case node['kernel']['machine'] -when 's390x' - default['yum']['epel']['baseurl'] = 'https://kojipkgs.fedoraproject.org/rhel/rc/7/Server/s390x/os/' - default['yum']['epel']['gpgkey'] = 'https://kojipkgs.fedoraproject.org/rhel/rc/7/Server/s390x/os/RPM-GPG-KEY-redhat-release' +case node['platform'] +when 'amazon' + default['yum']['epel']['description'] = 'Extra Packages for Enterprise Linux 6 - $basearch' + default['yum']['epel']['mirrorlist'] = 'http://mirrors.fedoraproject.org/mirrorlist?repo=epel-6&arch=$basearch' + default['yum']['epel']['gpgkey'] = 'http://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-6' else - if node['platform'] == 'amazon' + case node['platform_version'].to_i + when 5 + default['yum']['epel']['description'] = 'Extra Packages for Enterprise Linux 5 - $basearch' + default['yum']['epel']['mirrorlist'] = 'http://mirrors.fedoraproject.org/mirrorlist?repo=epel-5&arch=$basearch' + default['yum']['epel']['gpgkey'] = 'http://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL' + when 6 + default['yum']['epel']['description'] = 'Extra Packages for Enterprise Linux 6 - $basearch' default['yum']['epel']['mirrorlist'] = 'http://mirrors.fedoraproject.org/mirrorlist?repo=epel-6&arch=$basearch' default['yum']['epel']['gpgkey'] = 'http://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-6' - else - default['yum']['epel']['mirrorlist'] = "http://mirrors.fedoraproject.org/mirrorlist?repo=epel-#{node['platform_version'].to_i}&arch=$basearch" - default['yum']['epel']['gpgkey'] = (node['platform_version'].to_i == 5 ? 'http://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL' : "https://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-#{node['platform_version'].to_i}") + when 7 + default['yum']['epel']['description'] = 'Extra Packages for Enterprise Linux 7 - $basearch' + default['yum']['epel']['mirrorlist'] = 'http://mirrors.fedoraproject.org/mirrorlist?repo=epel-7&arch=$basearch' + default['yum']['epel']['gpgkey'] = 'http://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-7' end end @@ -19,4 +26,3 @@ default['yum']['epel']['failovermethod'] = 'priority' default['yum']['epel']['gpgcheck'] = true default['yum']['epel']['enabled'] = true default['yum']['epel']['managed'] = true -default['yum']['epel']['make_cache'] = true diff --git a/cookbooks/yum-epel/metadata.json b/cookbooks/yum-epel/metadata.json index e4c155c..f50f5c0 100644 --- a/cookbooks/yum-epel/metadata.json +++ b/cookbooks/yum-epel/metadata.json @@ -1 +1,30 @@ -{"name":"yum-epel","version":"0.7.1","description":"Installs and configures the EPEL Yum repository","long_description":"# yum-epel Cookbook\n[![Build Status](https://travis-ci.org/chef-cookbooks/yum-epel.svg?branch=master)](http://travis-ci.org/chef-cookbooks/yum-epel) [![Cookbook Version](https://img.shields.io/cookbook/v/yum-epel.svg)](https://supermarket.chef.io/cookbooks/yum-epel)\n\nExtra Packages for Enterprise Linux (or EPEL) is a Fedora Special Interest Group that creates, maintains, and manages a high quality set of additional packages for Enterprise Linux, including, but not limited to, Red Hat Enterprise Linux (RHEL), CentOS and Scientific Linux (SL), Oracle Linux (OL).\n\nThe yum-epel cookbook takes over management of the default repositoryids shipped with epel-release. It allows attribute manipulation of `epel`, `epel-debuginfo`, `epel-source`, `epel-testing`, `epel-testing-debuginfo`, and `epel-testing-source`.\n\n## Requirements\n### Platforms\n- RHEL/CentOS and derivatives\n\n### Chef\n- Chef 11+\n\n### Cookbooks\n- yum version 3.6.3 or higher\n\n## Attributes\nThe following attributes are set by default\n\n```ruby\ndefault['yum-epel']['repositories'] = %w{epel epel-debuginfo epel-source epel-testing epel-testing-debuginfo epel-testing-source}\n```\n\n```ruby\ndefault['yum']['epel']['repositoryid'] = 'epel'\ndefault['yum']['epel']['description'] = 'Extra Packages for Enterprise Linux 6 - $basearch'\ndefault['yum']['epel']['mirrorlist'] = 'http://mirrors.fedoraproject.org/mirrorlist?repo=epel-5&arch=$basearch'\ndefault['yum']['epel']['gpgkey'] = 'http://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-6'\ndefault['yum']['epel']['failovermethod'] = 'priority'\ndefault['yum']['epel']['gpgcheck'] = true\ndefault['yum']['epel']['enabled'] = true\ndefault['yum']['epel']['managed'] = true\n```\n\n```ruby\ndefault['yum']['epel-debuginfo']['repositoryid'] = 'epel-debuginfo'\ndefault['yum']['epel-debuginfo']['description'] = 'Extra Packages for Enterprise Linux 6 - $basearch - Debug'\ndefault['yum']['epel-debuginfo']['mirrorlist'] = 'https://mirrors.fedoraproject.org/metalink?repo=epel-debug-6&arch=$basearch'\ndefault['yum']['epel-debuginfo']['gpgkey'] = 'http://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-6'\ndefault['yum']['epel-debuginfo']['failovermethod'] = 'priority'\ndefault['yum']['epel-debuginfo']['gpgcheck'] = true\ndefault['yum']['epel-debuginfo']['enabled'] = false\ndefault['yum']['epel-debuginfo']['managed'] = false\n```\n\n```ruby\ndefault['yum']['epel-source']['repositoryid'] = 'epel-source'\ndefault['yum']['epel-source']['description'] = 'Extra Packages for Enterprise Linux 6 - $basearch - Source'\ndefault['yum']['epel-source']['mirrorlist'] = 'http://mirrors.fedoraproject.org/mirrorlist?repo=epel-source-6&arch=$basearch'\ndefault['yum']['epel-source']['gpgkey'] = 'http://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-6'\ndefault['yum']['epel-source']['failovermethod'] = 'priority'\ndefault['yum']['epel-source']['gpgcheck'] = true\ndefault['yum']['epel-source']['enabled'] = false\ndefault['yum']['epel-source']['managed'] = false\n```\n\n```ruby\ndefault['yum']['epel-testing']['repositoryid'] = 'epel-testing'\ndefault['yum']['epel-testing']['description'] = 'Extra Packages for Enterprise Linux 6 - Testing - $basearch'\ndefault['yum']['epel-testing']['mirrorlist'] = 'https://mirrors.fedoraproject.org/metalink?repo=testing-epel6&arch=$basearch'\ndefault['yum']['epel-testing']['gpgkey'] = 'http://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-6r'\ndefault['yum']['epel-testing']['failovermethod'] = 'priority'\ndefault['yum']['epel-testing']['gpgcheck'] = true\ndefault['yum']['epel-testing']['enabled'] = false\ndefault['yum']['epel-testing']['managed'] = false\n```\n\n```ruby\ndefault['yum']['epel-testing-debuginfo']['repositoryid'] = 'epel-testing-debuginfo'\ndefault['yum']['epel-testing-debuginfo']['description'] = 'Extra Packages for Enterprise Linux 6 - Testing - $basearch Debug'\ndefault['yum']['epel-testing-debuginfo']['mirrorlist'] = 'https://mirrors.fedoraproject.org/metalink?repo=testing-debug-epel6&arch=$basearch'\ndefault['yum']['epel-testing-debuginfo']['gpgkey'] = 'http://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-6'\ndefault['yum']['epel-testing-debuginfo']['failovermethod'] = 'priority'\ndefault['yum']['epel-testing-debuginfo']['gpgcheck'] = true\ndefault['yum']['epel-testing-debuginfo']['enabled'] = false\ndefault['yum']['epel-testing-debuginfo']['managed'] = false\n```\n\n```ruby\ndefault['yum']['epel-testing-source']['repositoryid'] = 'epel-testing-source'\ndefault['yum']['epel-testing-source']['description'] = 'Extra Packages for Enterprise Linux 6 - Testing - $basearch Source'\ndefault['yum']['epel-testing-source']['mirrorlist'] = 'https://mirrors.fedoraproject.org/metalink?repo=testing-source-epel6&arch=$basearch'\ndefault['yum']['epel-testing-source']['gpgkey'] = 'http://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-6'\ndefault['yum']['epel-testing-source']['failovermethod'] = 'priority'\ndefault['yum']['epel-testing-source']['gpgcheck'] = true\ndefault['yum']['epel-testing-source']['enabled'] = false\ndefault['yum']['epel-testing-source']['managed'] = false\n```\n\n## Recipes\n- default - Walks through node attributes and feeds a yum_resource\n- parameters. The following is an example a resource generated by the\n- recipe during compilation.\n\n```ruby\n yum_repository 'epel' do\n mirrorlist 'http://mirrors.fedoraproject.org/mirrorlist?repo=epel-5&arch=$basearch'\n description 'Extra Packages for Enterprise Linux 5 - $basearch'\n enabled true\n gpgcheck true\n gpgkey 'http://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL'\n end\n```\n\n## Usage Example\nTo disable the epel repository through a Role or Environment definition\n\n```\ndefault_attributes(\n :yum => {\n :epel => {\n :enabled => {\n false\n }\n }\n }\n )\n```\n\nUncommonly used repositoryids are not managed by default. This is speeds up integration testing pipelines by avoiding yum-cache builds that nobody cares about. To enable the epel-testing repository with a wrapper cookbook, place the following in a recipe:\n\n```ruby\nnode.default['yum']['epel-testing']['enabled'] = true\nnode.default['yum']['epel-testing']['managed'] = true\ninclude_recipe 'yum-epel'\n```\n\n## More Examples\nPoint the epel repositories at an internally hosted server.\n\n```ruby\nnode.default['yum']['epel']['enabled'] = true\nnode.default['yum']['epel']['mirrorlist'] = nil\nnode.default['yum']['epel']['baseurl'] = 'https://internal.example.com/centos/6/os/x86_64'\nnode.default['yum']['epel']['sslverify'] = false\n\ninclude_recipe 'yum-epel'\n```\n\n## License & Authors\n**Author:** Cookbook Engineering Team ([cookbooks@chef.io](mailto:cookbooks@chef.io))\n\n**Copyright:** 2011-2016, Chef Software, Inc.\n\n```\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n```\n","maintainer":"Chef Software, Inc.","maintainer_email":"cookbooks@chef.io","license":"Apache 2.0","platforms":{"amazon":">= 0.0.0","centos":">= 0.0.0","oracle":">= 0.0.0","redhat":">= 0.0.0","scientific":">= 0.0.0","zlinux":">= 0.0.0"},"dependencies":{"yum":">= 3.6.3"},"recommendations":{},"suggestions":{},"conflicting":{},"providing":{},"replacing":{},"attributes":{},"groupings":{},"recipes":{},"source_url":"https://github.com/chef-cookbooks/yum-epel","issues_url":"https://github.com/chef-cookbooks/yum-epel/issues","chef_version":{},"ohai_version":{}} \ No newline at end of file +{ + "name": "yum-epel", + "version": "0.3.6", + "description": "Installs/Configures yum-epel", + "long_description": "yum-epel Cookbook\n============\n\nThe yum-epel cookbook takes over management of the default\nrepositoryids shipped with epel-release. It allows attribute\nmanipulation of `epel`, `epel-debuginfo`, `epel-source`, `epel-testing`,\n`epel-testing-debuginfo`, and `epel-testing-source`.\n\nRequirements\n------------\n* Chef 11 or higher\n* yum cookbook version 3.0.0 or higher\n\nAttributes\n----------\nThe following attributes are set by default\n\n``` ruby\ndefault['yum']['epel']['repositoryid'] = 'epel'\ndefault['yum']['epel']['description'] = 'Extra Packages for Enterprise Linux 6 - $basearch'\ndefault['yum']['epel']['mirrorlist'] = 'http://mirrors.fedoraproject.org/mirrorlist?repo=epel-5&arch=$basearch'\ndefault['yum']['epel']['gpgkey'] = 'http://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-6'\ndefault['yum']['epel']['failovermethod'] = 'priority'\ndefault['yum']['epel']['gpgcheck'] = true\ndefault['yum']['epel']['enabled'] = true\ndefault['yum']['epel']['managed'] = true\n```\n\n``` ruby\ndefault['yum']['epel-debuginfo']['repositoryid'] = 'epel-debuginfo'\ndefault['yum']['epel-debuginfo']['description'] = 'Extra Packages for Enterprise Linux 6 - $basearch - Debug'\ndefault['yum']['epel-debuginfo']['mirrorlist'] = 'https://mirrors.fedoraproject.org/metalink?repo=epel-debug-6&arch=$basearch'\ndefault['yum']['epel-debuginfo']['gpgkey'] = 'http://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-6'\ndefault['yum']['epel-debuginfo']['failovermethod'] = 'priority'\ndefault['yum']['epel-debuginfo']['gpgcheck'] = true\ndefault['yum']['epel-debuginfo']['enabled'] = false\ndefault['yum']['epel-debuginfo']['managed'] = false\n```\n\n``` ruby\ndefault['yum']['epel-source']['repositoryid'] = 'epel-source'\ndefault['yum']['epel-source']['description'] = 'Extra Packages for Enterprise Linux 6 - $basearch - Source'\ndefault['yum']['epel-source']['mirrorlist'] = 'http://mirrors.fedoraproject.org/mirrorlist?repo=epel-source-6&arch=$basearch'\ndefault['yum']['epel-source']['gpgkey'] = 'http://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-6'\ndefault['yum']['epel-source']['failovermethod'] = 'priority'\ndefault['yum']['epel-source']['gpgcheck'] = true\ndefault['yum']['epel-source']['enabled'] = false\ndefault['yum']['epel-source']['managed'] = false\n```\n\n``` ruby\ndefault['yum']['epel-testing']['repositoryid'] = 'epel-testing'\ndefault['yum']['epel-testing']['description'] = 'Extra Packages for Enterprise Linux 6 - Testing - $basearch'\ndefault['yum']['epel-testing']['mirrorlist'] = 'https://mirrors.fedoraproject.org/metalink?repo=testing-epel6&arch=$basearch'\ndefault['yum']['epel-testing']['gpgkey'] = 'http://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-6r'\ndefault['yum']['epel-testing']['failovermethod'] = 'priority'\ndefault['yum']['epel-testing']['gpgcheck'] = true\ndefault['yum']['epel-testing']['enabled'] = false\ndefault['yum']['epel-testing']['managed'] = false\n```\n\n``` ruby\ndefault['yum']['epel-testing-debuginfo']['repositoryid'] = 'epel-testing-debuginfo'\ndefault['yum']['epel-testing-debuginfo']['description'] = 'Extra Packages for Enterprise Linux 6 - Testing - $basearch Debug'\ndefault['yum']['epel-testing-debuginfo']['mirrorlist'] = 'https://mirrors.fedoraproject.org/metalink?repo=testing-debug-epel6&arch=$basearch'\ndefault['yum']['epel-testing-debuginfo']['gpgkey'] = 'http://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-6'\ndefault['yum']['epel-testing-debuginfo']['failovermethod'] = 'priority'\ndefault['yum']['epel-testing-debuginfo']['gpgcheck'] = true\ndefault['yum']['epel-testing-debuginfo']['enabled'] = false\ndefault['yum']['epel-testing-debuginfo']['managed'] = false\n```\n\n``` ruby\ndefault['yum']['epel-testing-source']['repositoryid'] = 'epel-testing-source'\ndefault['yum']['epel-testing-source']['description'] = 'Extra Packages for Enterprise Linux 6 - Testing - $basearch Source'\ndefault['yum']['epel-testing-source']['mirrorlist'] = 'https://mirrors.fedoraproject.org/metalink?repo=testing-source-epel6&arch=$basearch'\ndefault['yum']['epel-testing-source']['gpgkey'] = 'http://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-6'\ndefault['yum']['epel-testing-source']['failovermethod'] = 'priority'\ndefault['yum']['epel-testing-source']['gpgcheck'] = true\ndefault['yum']['epel-testing-source']['enabled'] = false\ndefault['yum']['epel-testing-source']['managed'] = false\n```\n\nRecipes\n-------\n* default - Walks through node attributes and feeds a yum_resource\n parameters. The following is an example a resource generated by the\n recipe during compilation.\n\n```ruby\n yum_repository 'epel' do\n mirrorlist 'http://mirrors.fedoraproject.org/mirrorlist?repo=epel-5&arch=$basearch'\n description 'Extra Packages for Enterprise Linux 5 - $basearch'\n enabled true\n gpgcheck true\n gpgkey 'http://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL'\n end\n```\n\nUsage Example\n-------------\nTo disable the epel repository through a Role or Environment definition\n\n```\ndefault_attributes(\n :yum => {\n :epel => {\n :enabled => {\n false\n }\n }\n }\n )\n```\n\nUncommonly used repositoryids are not managed by default. This is\nspeeds up integration testing pipelines by avoiding yum-cache builds\nthat nobody cares about. To enable the epel-testing repository with a\nwrapper cookbook, place the following in a recipe:\n\n```\nnode.default['yum']['epel-testing']['enabled'] = true\nnode.default['yum']['epel-testing']['managed'] = true\ninclude_recipe 'yum-epel'\n```\n\nMore Examples\n-------------\nPoint the epel repositories at an internally hosted server.\n\n```\nnode.default['yum']['epel']['enabled'] = true\nnode.default['yum']['epel']['mirrorlist'] = nil\nnode.default['yum']['epel']['baseurl'] = 'https://internal.example.com/centos/6/os/x86_64'\nnode.default['yum']['epel']['sslverify'] = false\n\ninclude_recipe 'yum-epel'\n```\n\nLicense & Authors\n-----------------\n- Author:: Sean OMeara ()\n\n```text\nCopyright:: 2011-2013 Opscode, Inc.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n```\n", + "maintainer": "Chef", + "maintainer_email": "Sean OMeara ", + "license": "Apache 2.0", + "platforms": { + }, + "dependencies": { + "yum": "~> 3.0" + }, + "recommendations": { + }, + "suggestions": { + }, + "conflicting": { + }, + "providing": { + }, + "replacing": { + }, + "attributes": { + }, + "groupings": { + }, + "recipes": { + } +} \ No newline at end of file diff --git a/cookbooks/yum-epel/metadata.rb b/cookbooks/yum-epel/metadata.rb new file mode 100644 index 0000000..3b9958b --- /dev/null +++ b/cookbooks/yum-epel/metadata.rb @@ -0,0 +1,9 @@ +name 'yum-epel' +maintainer 'Chef' +maintainer_email 'Sean OMeara ' +license 'Apache 2.0' +description 'Installs/Configures yum-epel' +long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) +version '0.3.6' + +depends 'yum', '~> 3.0' diff --git a/cookbooks/yum-epel/recipes/default.rb b/cookbooks/yum-epel/recipes/default.rb index 8347394..b8811ba 100644 --- a/cookbooks/yum-epel/recipes/default.rb +++ b/cookbooks/yum-epel/recipes/default.rb @@ -1,9 +1,8 @@ # -# Author:: Sean OMeara () -# Cookbook Name:: yum-epel -# Recipe:: default +# Author:: Sean OMeara () +# Recipe:: yum-epel::default # -# Copyright 2013-2016, Chef Software, Inc. +# Copyright 2013, Chef # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,46 +16,41 @@ # See the License for the specific language governing permissions and # limitations under the License. -node['yum-epel']['repositories'].each do |repo| - next unless node['yum'][repo]['managed'] +%w{ + epel epel-debuginfo epel-source + epel-testing epel-testing-debuginfo epel-testing-source + }.each do |repo| - yum_repository repo do - baseurl node['yum'][repo]['baseurl'] unless node['yum'][repo]['baseurl'].nil? - cost node['yum'][repo]['cost'] unless node['yum'][repo]['cost'].nil? - description node['yum'][repo]['description'] unless node['yum'][repo]['description'].nil? - enabled node['yum'][repo]['enabled'] unless node['yum'][repo]['enabled'].nil? - enablegroups node['yum'][repo]['enablegroups'] unless node['yum'][repo]['enablegroups'].nil? - exclude node['yum'][repo]['exclude'] unless node['yum'][repo]['exclude'].nil? - failovermethod node['yum'][repo]['failovermethod'] unless node['yum'][repo]['failovermethod'].nil? - fastestmirror_enabled node['yum'][repo]['fastestmirror_enabled'] unless node['yum'][repo]['fastestmirror_enabled'].nil? - gpgcheck node['yum'][repo]['gpgcheck'] unless node['yum'][repo]['gpgcheck'].nil? - gpgkey node['yum'][repo]['gpgkey'] unless node['yum'][repo]['gpgkey'].nil? - http_caching node['yum'][repo]['http_caching'] unless node['yum'][repo]['http_caching'].nil? - include_config node['yum'][repo]['include_config'] unless node['yum'][repo]['include_config'].nil? - includepkgs node['yum'][repo]['includepkgs'] unless node['yum'][repo]['includepkgs'].nil? - keepalive node['yum'][repo]['keepalive'] unless node['yum'][repo]['keepalive'].nil? - make_cache node['yum'][repo]['make_cache'] unless node['yum'][repo]['make_cache'].nil? - max_retries node['yum'][repo]['max_retries'] unless node['yum'][repo]['max_retries'].nil? - metadata_expire node['yum'][repo]['metadata_expire'] unless node['yum'][repo]['metadata_expire'].nil? - mirror_expire node['yum'][repo]['mirror_expire'] unless node['yum'][repo]['mirror_expire'].nil? - mirrorlist node['yum'][repo]['mirrorlist'] unless node['yum'][repo]['mirrorlist'].nil? - mirrorlist_expire node['yum'][repo]['mirrorlist_expire'] unless node['yum'][repo]['mirrorlist_expire'].nil? - password node['yum'][repo]['password'] unless node['yum'][repo]['password'].nil? - priority node['yum'][repo]['priority'] unless node['yum'][repo]['priority'].nil? - proxy node['yum'][repo]['proxy'] unless node['yum'][repo]['proxy'].nil? - proxy_username node['yum'][repo]['proxy_username'] unless node['yum'][repo]['proxy_username'].nil? - proxy_password node['yum'][repo]['proxy_password'] unless node['yum'][repo]['proxy_password'].nil? - report_instanceid node['yum'][repo]['report_instanceid'] unless node['yum'][repo]['report_instanceid'].nil? - repositoryid node['yum'][repo]['repositoryid'] unless node['yum'][repo]['repositoryid'].nil? - skip_if_unavailable node['yum'][repo]['skip_if_unavailable'] unless node['yum'][repo]['skip_if_unavailable'].nil? - source node['yum'][repo]['source'] unless node['yum'][repo]['source'].nil? - sslcacert node['yum'][repo]['sslcacert'] unless node['yum'][repo]['sslcacert'].nil? - sslclientcert node['yum'][repo]['sslclientcert'] unless node['yum'][repo]['sslclientcert'].nil? - sslclientkey node['yum'][repo]['sslclientkey'] unless node['yum'][repo]['sslclientkey'].nil? - sslverify node['yum'][repo]['sslverify'] unless node['yum'][repo]['sslverify'].nil? - timeout node['yum'][repo]['timeout'] unless node['yum'][repo]['timeout'].nil? - username node['yum'][repo]['username'] unless node['yum'][repo]['username'].nil? - - action :create + if node['yum'][repo]['managed'] + yum_repository repo do + description node['yum'][repo]['description'] + baseurl node['yum'][repo]['baseurl'] + mirrorlist node['yum'][repo]['mirrorlist'] + gpgcheck node['yum'][repo]['gpgcheck'] + gpgkey node['yum'][repo]['gpgkey'] + enabled node['yum'][repo]['enabled'] + cost node['yum'][repo]['cost'] + exclude node['yum'][repo]['exclude'] + enablegroups node['yum'][repo]['enablegroups'] + failovermethod node['yum'][repo]['failovermethod'] + http_caching node['yum'][repo]['http_caching'] + include_config node['yum'][repo]['include_config'] + includepkgs node['yum'][repo]['includepkgs'] + keepalive node['yum'][repo]['keepalive'] + max_retries node['yum'][repo]['max_retries'] + metadata_expire node['yum'][repo]['metadata_expire'] + mirror_expire node['yum'][repo]['mirror_expire'] + priority node['yum'][repo]['priority'] + proxy node['yum'][repo]['proxy'] + proxy_username node['yum'][repo]['proxy_username'] + proxy_password node['yum'][repo]['proxy_password'] + repositoryid node['yum'][repo]['repositoryid'] + sslcacert node['yum'][repo]['sslcacert'] + sslclientcert node['yum'][repo]['sslclientcert'] + sslclientkey node['yum'][repo]['sslclientkey'] + sslverify node['yum'][repo]['sslverify'] + timeout node['yum'][repo]['timeout'] + action :create + end end end diff --git a/cookbooks/yum-mysql-community/CHANGELOG.md b/cookbooks/yum-mysql-community/CHANGELOG.md deleted file mode 100644 index 77d7ed7..0000000 --- a/cookbooks/yum-mysql-community/CHANGELOG.md +++ /dev/null @@ -1,82 +0,0 @@ -yum-mysql-community Cookbook CHANGELOG ---------------------------------------- -This file is used to list changes made in each version of the yum-mysql-community cookbook. - -v0.1.21 (2015-12-01) --------------------- -- Fixing if/unless logic in recipes - -v0.1.20 (2015-11-30) --------------------- -- Fixed attributes with a false value not being passed - -v0.1.19 (2015-10-28) --------------------- -- Fixing Chef 13 nil property deprecation warnings - -v0.1.18 (2015-09-21) --------------------- -- Added Travis CI config for lint and unit testing -- Added Chef standard Rubocop file and resolved all warnings -- Added Chef standard chefignore and .gitignore files -- Add supported platforms to the metadata -- Added source_url and issues_url to the metadata -- Added long_description to the metadata -- Updated and expanded development dependencies in the Gemfile -- Added contributing, testing, and maintainers docs -- Added platform requirements to the readme -- Added Travis and cookbook version badges to the readme -- Update Chefspec to 4.X format - -v0.1.17 (2015-04-06) --------------------- -- Updating pubkey link from someara to chef-client github orgs - -v0.1.16 (2015-03-25) --------------------- -- Adding support Amazon Linux 2015.03 to all channels - -v0.1.15 (2015-03-25) --------------------- -- Added support for amazon linux 2015.03 - -v0.1.14 (2015-03-12) --------------------- -- The content of 0.1.13 is questionable: didn't have changelog entry, may have had merged attribute change, but let's be clear and say at least this version 0.1.14 is the right thing. - -v0.1.13 (2015-03-12) --------------------- -- #3 corrected typo in public key attribute - -v0.1.12 (2015-01-20) --------------------- -- Minor style updates - -v0.1.11 (2014-07-21) --------------------- -- Adding RHEL-7 support - -v0.1.10 (2014-07-21) --------------------- -- Adding mysql-5.7 and centos 7 support - -v0.1.8 (2014-06-18) -------------------- -- Updating to support real RHEL - -v0.1.6 (2014-06-16) -------------------- -Fixing typo in mysql55-community attributes - -v0.1.4 (2014-06-13) -------------------- -- updating url to keys in cookbook attributes - -v0.1.2 (2014-06-11) -------------------- -#1 - Move files/mysql_pubkey.asc to files/default/mysql_pubkey.asc - -v0.1.0 (2014-04-30) -------------------- -Initial release - diff --git a/cookbooks/yum-mysql-community/CONTRIBUTING.md b/cookbooks/yum-mysql-community/CONTRIBUTING.md deleted file mode 100644 index ef2f2b8..0000000 --- a/cookbooks/yum-mysql-community/CONTRIBUTING.md +++ /dev/null @@ -1,2 +0,0 @@ -Please refer to -https://github.com/chef-cookbooks/community_cookbook_documentation/blob/master/CONTRIBUTING.MD diff --git a/cookbooks/yum-mysql-community/MAINTAINERS.md b/cookbooks/yum-mysql-community/MAINTAINERS.md deleted file mode 100644 index 2cf4d2f..0000000 --- a/cookbooks/yum-mysql-community/MAINTAINERS.md +++ /dev/null @@ -1,19 +0,0 @@ - - -# Maintainers -This file lists how this cookbook project is maintained. When making changes to the system, this -file tells you who needs to review your patch - you need a simple majority of maintainers -for the relevant subsystems to provide a :+1: on your pull request. Additionally, you need -to not receive a veto from a Lieutenant or the Project Lead. - -Check out [How Cookbooks are Maintained](https://github.com/chef-cookbooks/community_cookbook_documentation/blob/master/CONTRIBUTING.MD) -for details on the process and how to become a maintainer or the project lead. - -# Project Maintainer -* [Jennifer Davis](https://github.com/sigje) - -# Maintainers -* [Jennifer Davis](https://github.com/sigje) -* [Sean OMeara](https://github.com/someara) -* [Tim Smith](https://github.com/tas50) -* [Thom May](https://github.com/thommay) diff --git a/cookbooks/yum-mysql-community/README.md b/cookbooks/yum-mysql-community/README.md deleted file mode 100644 index 7bae244..0000000 --- a/cookbooks/yum-mysql-community/README.md +++ /dev/null @@ -1,131 +0,0 @@ -# yum-mysql-community Cookbook -[![Build Status](https://travis-ci.org/chef-cookbooks/yum-mysql-community.svg?branch=master)](http://travis-ci.org/chef-cookbooks/yum-mysql-community) [![Cookbook Version](https://img.shields.io/cookbook/v/yum-mysql-community.svg)](https://supermarket.chef.io/cookbooks/yum-mysql-community) - -The yum-mysql-community cookbook takes over management of the default repository ids shipped with epel-release. It allows attribute manipulation of `mysql-connectors-community`, `mysql56-community`, and `mysql57-community-dmr`. - -## Requirements -### Platforms -- RHEL/CentOS and derivatives -- Fedora - -### Chef -- Chef 11+ - -### Cookbooks -- yum version 3.0.0 or higher -- yum-epel - -## Attributes -The following attributes are set by default - -```ruby -default['yum']['mysql-connectors-community']['repositoryid'] = 'mysql-connectors-community' -default['yum']['mysql-connectors-community']['description'] = 'MySQL Connectors Community' -default['yum']['mysql-connectors-community']['baseurl'] = 'http://repo.mysql.com/yum/mysql-connectors-community/el/$releasever/$basearch/' -default['yum']['mysql-connectors-community']['gpgkey'] = 'https://raw.githubusercontent.com/rs-services/equinix-public/master/cookbooks/db_mysql/files/centos/mysql_pubkey.asc' -default['yum']['mysql-connectors-community']['failovermethod'] = 'priority' -default['yum']['mysql-connectors-community']['gpgcheck'] = true -default['yum']['mysql-connectors-community']['enabled'] = true -``` - -```ruby -default['yum']['mysql56-community']['repositoryid'] = 'mysql56-community' -default['yum']['mysql56-community']['description'] = 'MySQL 5.6 Community Server' -default['yum']['mysql56-community']['baseurl'] = 'http://repo.mysql.com/yum/mysql56-community/el/$releasever/$basearch/' -default['yum']['mysql56-community']['gpgkey'] = 'https://raw.githubusercontent.com/rs-services/equinix-public/master/cookbooks/db_mysql/files/centos/mysql_pubkey.asc' -default['yum']['mysql56-community']['failovermethod'] = 'priority' -default['yum']['mysql56-community']['gpgcheck'] = true -default['yum']['mysql56-community']['enabled'] = true -``` - -```ruby -default['yum']['mysql57-community-dmr']['repositoryid'] = 'mysql57-community-dmr' -default['yum']['mysql57-community-dmr']['description'] = 'MySQL 5.7 Community Server Development Milestone Release' -default['yum']['mysql57-community-dmr']['baseurl'] = 'http://repo.mysql.com/yum/mysql56-community/el/$releasever/$basearch/' -default['yum']['mysql57-community-dmr']['gpgkey'] = 'https://raw.githubusercontent.com/rs-services/equinix-public/master/cookbooks/db_mysql/files/centos/mysql_pubkey.asc' -default['yum']['mysql57-community-dmr']['failovermethod'] = 'priority' -default['yum']['mysql57-community-dmr']['gpgcheck'] = true -default['yum']['mysql57-community-dmr']['enabled'] = true -``` - -## Recipes -- mysql55 - Sets up the mysql56-community repository on supported -- platforms - -```ruby - yum_repository 'mysql55-community' do - mirrorlist 'http://repo.mysql.com/yum/mysql55-community/el/$releasever/$basearch/' - description '' - enabled true - gpgcheck true - end -``` - -- mysql56 - Sets up the mysql56-community repository on supported -- platforms - -```ruby - yum_repository 'mysql56-community' do - mirrorlist 'http://repo.mysql.com/yum/mysql56-community/el/$releasever/$basearch/' - description '' - enabled true - gpgcheck true - end -``` - -- connectors - Sets up the mysql-connectors-community repository on supported -- platforms - -## Usage Example -To disable the epel repository through a Role or Environment definition - -``` -default_attributes( - :yum => { - :mysql57-community-dmr => { - :enabled => { - false - } - } - } - ) -``` - -Uncommonly used repositoryids are not managed by default. This is speeds up integration testing pipelines by avoiding yum-cache builds that nobody cares about. To enable the epel-testing repository with a wrapper cookbook, place the following in a recipe: - -``` -node.default['yum']['mysql57-community-dmr']['enabled'] = true -node.default['yum']['mysql57-community-dmr']['managed'] = true -include_recipe 'mysql57-community-dmr' -``` - -## More Examples -Point the mysql56-community repositories at an internally hosted server. - -``` -node.default['yum']['mysql56-community']['enabled'] = true -node.default['yum']['mysql56-community']['mirrorlist'] = nil -node.default['yum']['mysql56-community']['baseurl'] = 'https://internal.example.com/mysql/mysql56-community/' -node.default['yum']['mysql56-community']['sslverify'] = false - -include_recipe 'mysql56-community' -``` - -## License & Authors -**Author:** Cookbook Engineering Team ([cookbooks@chef.io](mailto:cookbooks@chef.io)) - -**Copyright:** 2011-2015, Chef Software, Inc. - -``` -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -``` diff --git a/cookbooks/yum-mysql-community/attributes/mysql-connectors-community.rb b/cookbooks/yum-mysql-community/attributes/mysql-connectors-community.rb deleted file mode 100644 index 2ffd3d6..0000000 --- a/cookbooks/yum-mysql-community/attributes/mysql-connectors-community.rb +++ /dev/null @@ -1,35 +0,0 @@ -default['yum']['mysql-connectors-community']['repositoryid'] = 'mysql-connectors-community' -default['yum']['mysql-connectors-community']['gpgkey'] = 'https://raw.githubusercontent.com/chef-cookbooks/yum-mysql-community/master/files/default/mysql_pubkey.asc' -default['yum']['mysql-connectors-community']['description'] = 'MySQL Connectors Community' -default['yum']['mysql-connectors-community']['failovermethod'] = 'priority' -default['yum']['mysql-connectors-community']['gpgcheck'] = true -default['yum']['mysql-connectors-community']['enabled'] = true - -case node['platform_family'] -when 'rhel' - case node['platform'] - when 'amazon' - case node['platform_version'].to_i - when 2013 - default['yum']['mysql-connectors-community']['baseurl'] = 'http://repo.mysql.com/yum/mysql-connectors-community/el/6/$basearch/' - when 2014 - default['yum']['mysql-connectors-community']['baseurl'] = 'http://repo.mysql.com/yum/mysql-connectors-community/el/6/$basearch/' - when 2015 - default['yum']['mysql-connectors-community']['baseurl'] = 'http://repo.mysql.com/yum/mysql-connectors-community/el/6/$basearch/' - end - when 'redhat' - case node['platform_version'].to_i - when 5 - # Real Redhat identifies $releasever as 5Server and 6Server - default['yum']['mysql-connectors-community']['baseurl'] = 'http://repo.mysql.com/yum/mysql-connectors-community/el/5/$basearch/' - when 6 - default['yum']['mysql-connectors-community']['baseurl'] = 'http://repo.mysql.com/yum/mysql-connectors-community/el/6/$basearch/' - when 7 - default['yum']['mysql-connectors-community']['baseurl'] = 'http://repo.mysql.com/yum/mysql-connectors-community/el/7/$basearch/' - end - else # other rhel - default['yum']['mysql-connectors-community']['baseurl'] = 'http://repo.mysql.com/yum/mysql-connectors-community/el/$releasever/$basearch/' - end -when 'fedora' - default['yum']['mysql-connectors-community']['baseurl'] = 'http://repo.mysql.com/yum/mysql-connectors-community/fc/$releasever/$basearch/' -end diff --git a/cookbooks/yum-mysql-community/attributes/mysql55-community.rb b/cookbooks/yum-mysql-community/attributes/mysql55-community.rb deleted file mode 100644 index 73e2efd..0000000 --- a/cookbooks/yum-mysql-community/attributes/mysql55-community.rb +++ /dev/null @@ -1,33 +0,0 @@ -default['yum']['mysql55-community']['repositoryid'] = 'mysql55-community' -default['yum']['mysql55-community']['gpgkey'] = 'https://raw.githubusercontent.com/chef-cookbooks/yum-mysql-community/master/files/default/mysql_pubkey.asc' -default['yum']['mysql55-community']['description'] = 'MySQL 5.5 Community Server' -default['yum']['mysql55-community']['failovermethod'] = 'priority' -default['yum']['mysql55-community']['gpgcheck'] = true -default['yum']['mysql55-community']['enabled'] = true - -case node['platform_family'] -when 'rhel' - case node['platform'] - when 'amazon' - case node['platform_version'].to_i - when 2013 - default['yum']['mysql55-community']['baseurl'] = 'http://repo.mysql.com/yum/mysql-5.5-community/el/6/$basearch/' - when 2014 - default['yum']['mysql55-community']['baseurl'] = 'http://repo.mysql.com/yum/mysql-5.5-community/el/6/$basearch/' - when 2015 - default['yum']['mysql55-community']['baseurl'] = 'http://repo.mysql.com/yum/mysql-5.5-community/el/6/$basearch/' - end - when 'redhat' - case node['platform_version'].to_i - when 5 - # Real Redhat identifies $releasever as 5Server and 6Server - default['yum']['mysql55-community']['baseurl'] = 'http://repo.mysql.com/yum/mysql-5.5-community/el/5/$basearch/' - when 6 - default['yum']['mysql55-community']['baseurl'] = 'http://repo.mysql.com/yum/mysql-5.5-community/el/6/$basearch/' - when 7 - default['yum']['mysql55-community']['baseurl'] = 'http://repo.mysql.com/yum/mysql-5.5-community/el/7/$basearch/' - end - else # other rhel. only 6 and 7 for now - default['yum']['mysql55-community']['baseurl'] = 'http://repo.mysql.com/yum/mysql-5.5-community/el/$releasever/$basearch/' - end -end diff --git a/cookbooks/yum-mysql-community/attributes/mysql56-community.rb b/cookbooks/yum-mysql-community/attributes/mysql56-community.rb deleted file mode 100644 index c301a57..0000000 --- a/cookbooks/yum-mysql-community/attributes/mysql56-community.rb +++ /dev/null @@ -1,35 +0,0 @@ -default['yum']['mysql56-community']['repositoryid'] = 'mysql56-community' -default['yum']['mysql56-community']['gpgkey'] = 'https://raw.githubusercontent.com/chef-cookbooks/yum-mysql-community/master/files/default/mysql_pubkey.asc' -default['yum']['mysql56-community']['description'] = 'MySQL 5.6 Community Server' -default['yum']['mysql56-community']['failovermethod'] = 'priority' -default['yum']['mysql56-community']['gpgcheck'] = true -default['yum']['mysql56-community']['enabled'] = true - -case node['platform_family'] -when 'rhel' - case node['platform'] - when 'amazon' - case node['platform_version'].to_i - when 2013 - default['yum']['mysql56-community']['baseurl'] = 'http://repo.mysql.com/yum/mysql-5.6-community/el/6/$basearch/' - when 2014 - default['yum']['mysql56-community']['baseurl'] = 'http://repo.mysql.com/yum/mysql-5.6-community/el/6/$basearch/' - when 2015 - default['yum']['mysql56-community']['baseurl'] = 'http://repo.mysql.com/yum/mysql-5.6-community/el/6/$basearch/' - end - when 'redhat' - case node['platform_version'].to_i - when 5 - # Real Redhat identifies $releasever as 5Server and 6Server - default['yum']['mysql56-community']['baseurl'] = 'http://repo.mysql.com/yum/mysql-5.6-community/el/5/$basearch/' - when 6 - default['yum']['mysql56-community']['baseurl'] = 'http://repo.mysql.com/yum/mysql-5.6-community/el/6/$basearch/' - when 7 - default['yum']['mysql56-community']['baseurl'] = 'http://repo.mysql.com/yum/mysql-5.6-community/el/7/$basearch/' - end - else # other rhel - default['yum']['mysql56-community']['baseurl'] = 'http://repo.mysql.com/yum/mysql-5.6-community/el/$releasever/$basearch/' - end -when 'fedora' - default['yum']['mysql56-community']['baseurl'] = 'http://repo.mysql.com/yum/mysql-5.6-community/fc/$releasever/$basearch/' -end diff --git a/cookbooks/yum-mysql-community/attributes/mysql57-community.rb b/cookbooks/yum-mysql-community/attributes/mysql57-community.rb deleted file mode 100644 index ad8e55c..0000000 --- a/cookbooks/yum-mysql-community/attributes/mysql57-community.rb +++ /dev/null @@ -1,35 +0,0 @@ -default['yum']['mysql57-community']['repositoryid'] = 'mysql57-community' -default['yum']['mysql57-community']['gpgkey'] = 'https://raw.githubusercontent.com/chef-cookbooks/yum-mysql-community/master/files/default/mysql_pubkey.asc' -default['yum']['mysql57-community']['description'] = 'MySQL 5.7 Community Server' -default['yum']['mysql57-community']['failovermethod'] = 'priority' -default['yum']['mysql57-community']['gpgcheck'] = true -default['yum']['mysql57-community']['enabled'] = true - -case node['platform_family'] -when 'rhel' - case node['platform'] - when 'amazon' - case node['platform_version'].to_i - when 2013 - default['yum']['mysql57-community']['baseurl'] = 'http://repo.mysql.com/yum/mysql-5.7-community/el/6/$basearch/' - when 2014 - default['yum']['mysql57-community']['baseurl'] = 'http://repo.mysql.com/yum/mysql-5.7-community/el/6/$basearch/' - when 2015 - default['yum']['mysql57-community']['baseurl'] = 'http://repo.mysql.com/yum/mysql-5.7-community/el/6/$basearch/' - end - when 'redhat' - case node['platform_version'].to_i - when 5 - # Real Redhat identifies $releasever as 5Server and 6Server - default['yum']['mysql57-community']['baseurl'] = 'http://repo.mysql.com/yum/mysql-5.7-community/el/5/$basearch/' - when 6 - default['yum']['mysql57-community']['baseurl'] = 'http://repo.mysql.com/yum/mysql-5.7-community/el/6/$basearch/' - when 7 - default['yum']['mysql57-community']['baseurl'] = 'http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/' - end - else # other rhel - default['yum']['mysql57-community']['baseurl'] = 'http://repo.mysql.com/yum/mysql-5.7-community/el/$releasever/$basearch/' - end -when 'fedora' - default['yum']['mysql57-community']['baseurl'] = 'http://repo.mysql.com/yum/mysql-5.7-community/fc/$releasever/$basearch/' -end diff --git a/cookbooks/yum-mysql-community/files/default/mysql_pubkey.asc b/cookbooks/yum-mysql-community/files/default/mysql_pubkey.asc deleted file mode 100644 index 8009b88..0000000 --- a/cookbooks/yum-mysql-community/files/default/mysql_pubkey.asc +++ /dev/null @@ -1,33 +0,0 @@ ------BEGIN PGP PUBLIC KEY BLOCK----- -Version: GnuPG v1.4.5 (GNU/Linux) - -mQGiBD4+owwRBAC14GIfUfCyEDSIePvEW3SAFUdJBtoQHH/nJKZyQT7h9bPlUWC3 -RODjQReyCITRrdwyrKUGku2FmeVGwn2u2WmDMNABLnpprWPkBdCk96+OmSLN9brZ -fw2vOUgCmYv2hW0hyDHuvYlQA/BThQoADgj8AW6/0Lo7V1W9/8VuHP0gQwCgvzV3 -BqOxRznNCRCRxAuAuVztHRcEAJooQK1+iSiunZMYD1WufeXfshc57S/+yeJkegNW -hxwR9pRWVArNYJdDRT+rf2RUe3vpquKNQU/hnEIUHJRQqYHo8gTxvxXNQc7fJYLV -K2HtkrPbP72vwsEKMYhhr0eKCbtLGfls9krjJ6sBgACyP/Vb7hiPwxh6rDZ7ITnE -kYpXBACmWpP8NJTkamEnPCia2ZoOHODANwpUkP43I7jsDmgtobZX9qnrAXw+uNDI -QJEXM6FSbi0LLtZciNlYsafwAPEOMDKpMqAK6IyisNtPvaLd8lH0bPAnWqcyefep -rv0sxxqUEMcM3o7wwgfN83POkDasDbs3pjwPhxvhz6//62zQJ7Q7TXlTUUwgUGFj -a2FnZSBzaWduaW5nIGtleSAod3d3Lm15c3FsLmNvbSkgPGJ1aWxkQG15c3FsLmNv -bT6IXQQTEQIAHQULBwoDBAMVAwIDFgIBAheABQJLcC5lBQkQ8/JZAAoJEIxxjTtQ -cuH1oD4AoIcOQ4EoGsZvy06D0Ei5vcsWEy8dAJ4g46i3WEcdSWxMhcBSsPz65sh5 -lohMBBMRAgAMBQI+PqPRBYMJZgC7AAoJEElQ4SqycpHyJOEAn1mxHijft00bKXvu -cSo/pECUmppiAJ41M9MRVj5VcdH/KN/KjRtW6tHFPYhMBBMRAgAMBQI+QoIDBYMJ -YiKJAAoJELb1zU3GuiQ/lpEAoIhpp6BozKI8p6eaabzF5MlJH58pAKCu/ROofK8J -Eg2aLos+5zEYrB/LsrkCDQQ+PqMdEAgA7+GJfxbMdY4wslPnjH9rF4N2qfWsEN/l -xaZoJYc3a6M02WCnHl6ahT2/tBK2w1QI4YFteR47gCvtgb6O1JHffOo2HfLmRDRi -Rjd1DTCHqeyX7CHhcghj/dNRlW2Z0l5QFEcmV9U0Vhp3aFfWC4Ujfs3LU+hkAWzE -7zaD5cH9J7yv/6xuZVw411x0h4UqsTcWMu0iM1BzELqX1DY7LwoPEb/O9Rkbf4fm -Le11EzIaCa4PqARXQZc4dhSinMt6K3X4BrRsKTfozBu74F47D8Ilbf5vSYHbuE5p -/1oIDznkg/p8kW+3FxuWrycciqFTcNz215yyX39LXFnlLzKUb/F5GwADBQf+Lwqq -a8CGrRfsOAJxim63CHfty5mUc5rUSnTslGYEIOCR1BeQauyPZbPDsDD9MZ1ZaSaf -anFvwFG6Llx9xkU7tzq+vKLoWkm4u5xf3vn55VjnSd1aQ9eQnUcXiL4cnBGoTbOW -I39EcyzgslzBdC++MPjcQTcA7p6JUVsP6oAB3FQWg54tuUo0Ec8bsM8b3Ev42Lmu -QT5NdKHGwHsXTPtl0klk4bQk4OajHsiy1BMahpT27jWjJlMiJc+IWJ0mghkKHt92 -6s/ymfdf5HkdQ1cyvsz5tryVI3Fx78XeSYfQvuuwqp2H139pXGEkg0n6KdUOetdZ -Whe70YGNPw1yjWJT1IhMBBgRAgAMBQI+PqMdBQkJZgGAAAoJEIxxjTtQcuH17p4A -n3r1QpVC9yhnW2cSAjq+kr72GX0eAJ4295kl6NxYEuFApmr1+0uUq/SlsQ== -=Mski ------END PGP PUBLIC KEY BLOCK----- diff --git a/cookbooks/yum-mysql-community/metadata.json b/cookbooks/yum-mysql-community/metadata.json deleted file mode 100644 index 0e996cb..0000000 --- a/cookbooks/yum-mysql-community/metadata.json +++ /dev/null @@ -1 +0,0 @@ -{"name":"yum-mysql-community","version":"0.1.21","description":"Installs/Configures yum-mysql-community","long_description":"","maintainer":"Chef Software, Inc.","maintainer_email":"cookbooks@chef.io","license":"Apache 2.0","platforms":{"amazon":">= 0.0.0","centos":">= 0.0.0","fedora":">= 0.0.0","oracle":">= 0.0.0","redhat":">= 0.0.0","scientific":">= 0.0.0"},"dependencies":{"yum":">= 3.2"},"recommendations":{},"suggestions":{},"conflicting":{},"providing":{},"replacing":{},"attributes":{},"groupings":{},"recipes":{}} \ No newline at end of file diff --git a/cookbooks/yum-mysql-community/recipes/connectors.rb b/cookbooks/yum-mysql-community/recipes/connectors.rb deleted file mode 100644 index 40fc983..0000000 --- a/cookbooks/yum-mysql-community/recipes/connectors.rb +++ /dev/null @@ -1,48 +0,0 @@ -# -# Author:: Sean OMeara () -# Recipe:: yum-mysql-community::connectors -# -# Copyright 2014-2015, Chef Software, Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -yum_repository 'mysql-connectors-community' do - description node['yum']['mysql-connectors-community']['description'] unless node['yum']['mysql-connectors-community']['description'].nil? - baseurl node['yum']['mysql-connectors-community']['baseurl'] unless node['yum']['mysql-connectors-community']['baseurl'].nil? - mirrorlist node['yum']['mysql-connectors-community']['mirrorlist'] unless node['yum']['mysql-connectors-community']['mirrorlist'].nil? - gpgcheck node['yum']['mysql-connectors-community']['gpgcheck'] unless node['yum']['mysql-connectors-community']['gpgcheck'].nil? - gpgkey node['yum']['mysql-connectors-community']['gpgkey'] unless node['yum']['mysql-connectors-community']['gpgkey'].nil? - enabled node['yum']['mysql-connectors-community']['enabled'] unless node['yum']['mysql-connectors-community']['enabled'].nil? - cost node['yum']['mysql-connectors-community']['cost'] unless node['yum']['mysql-connectors-community']['cost'].nil? - exclude node['yum']['mysql-connectors-community']['exclude'] unless node['yum']['mysql-connectors-community']['exclude'].nil? - enablegroups node['yum']['mysql-connectors-community']['enablegroups'] unless node['yum']['mysql-connectors-community']['enablegroups'].nil? - failovermethod node['yum']['mysql-connectors-community']['failovermethod'] unless node['yum']['mysql-connectors-community']['failovermethod'].nil? - http_caching node['yum']['mysql-connectors-community']['http_caching'] unless node['yum']['mysql-connectors-community']['http_caching'].nil? - include_config node['yum']['mysql-connectors-community']['include_config'] unless node['yum']['mysql-connectors-community']['include_config'].nil? - includepkgs node['yum']['mysql-connectors-community']['includepkgs'] unless node['yum']['mysql-connectors-community']['includepkgs'].nil? - keepalive node['yum']['mysql-connectors-community']['keepalive'] unless node['yum']['mysql-connectors-community']['keepalive'].nil? - max_retries node['yum']['mysql-connectors-community']['max_retries'] unless node['yum']['mysql-connectors-community']['max_retries'].nil? - metadata_expire node['yum']['mysql-connectors-community']['metadata_expire'] unless node['yum']['mysql-connectors-community']['metadata_expire'].nil? - mirror_expire node['yum']['mysql-connectors-community']['mirror_expire'] unless node['yum']['mysql-connectors-community']['mirror_expire'].nil? - priority node['yum']['mysql-connectors-community']['priority'] unless node['yum']['mysql-connectors-community']['priority'].nil? - proxy node['yum']['mysql-connectors-community']['proxy'] unless node['yum']['mysql-connectors-community']['proxy'].nil? - proxy_username node['yum']['mysql-connectors-community']['proxy_username'] unless node['yum']['mysql-connectors-community']['proxy_username'].nil? - proxy_password node['yum']['mysql-connectors-community']['proxy_password'] unless node['yum']['mysql-connectors-community']['proxy_password'].nil? - repositoryid node['yum']['mysql-connectors-community']['repositoryid'] unless node['yum']['mysql-connectors-community']['repositoryid'].nil? - sslcacert node['yum']['mysql-connectors-community']['sslcacert'] unless node['yum']['mysql-connectors-community']['sslcacert'].nil? - sslclientcert node['yum']['mysql-connectors-community']['sslclientcert'] unless node['yum']['mysql-connectors-community']['sslclientcert'].nil? - sslclientkey node['yum']['mysql-connectors-community']['sslclientkey'] unless node['yum']['mysql-connectors-community']['sslclientkey'].nil? - sslverify node['yum']['mysql-connectors-community']['sslverify'] unless node['yum']['mysql-connectors-community']['sslverify'].nil? - timeout node['yum']['mysql-connectors-community']['timeout'] unless node['yum']['mysql-connectors-community']['timeout'].nil? - action :create -end diff --git a/cookbooks/yum-mysql-community/recipes/mysql55.rb b/cookbooks/yum-mysql-community/recipes/mysql55.rb deleted file mode 100644 index 6b6d46c..0000000 --- a/cookbooks/yum-mysql-community/recipes/mysql55.rb +++ /dev/null @@ -1,48 +0,0 @@ -# -# Author:: Sean OMeara () -# Recipe:: yum-mysql-community::mysql55 -# -# Copyright 2014-2015, Chef Software, Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -yum_repository 'mysql55-community' do - description node['yum']['mysql55-community']['description'] unless node['yum']['mysql55-community']['description'].nil? - baseurl node['yum']['mysql55-community']['baseurl'] unless node['yum']['mysql55-community']['baseurl'].nil? - mirrorlist node['yum']['mysql55-community']['mirrorlist'] unless node['yum']['mysql55-community']['mirrorlist'].nil? - gpgcheck node['yum']['mysql55-community']['gpgcheck'] unless node['yum']['mysql55-community']['gpgcheck'].nil? - gpgkey node['yum']['mysql55-community']['gpgkey'] unless node['yum']['mysql55-community']['gpgkey'].nil? - enabled node['yum']['mysql55-community']['enabled'] unless node['yum']['mysql55-community']['enabled'].nil? - cost node['yum']['mysql55-community']['cost'] unless node['yum']['mysql55-community']['cost'].nil? - exclude node['yum']['mysql55-community']['exclude'] unless node['yum']['mysql55-community']['exclude'].nil? - enablegroups node['yum']['mysql55-community']['enablegroups'] unless node['yum']['mysql55-community']['enablegroups'].nil? - failovermethod node['yum']['mysql55-community']['failovermethod'] unless node['yum']['mysql55-community']['failovermethod'].nil? - http_caching node['yum']['mysql55-community']['http_caching'] unless node['yum']['mysql55-community']['http_caching'].nil? - include_config node['yum']['mysql55-community']['include_config'] unless node['yum']['mysql55-community']['include_config'].nil? - includepkgs node['yum']['mysql55-community']['includepkgs'] unless node['yum']['mysql55-community']['includepkgs'].nil? - keepalive node['yum']['mysql55-community']['keepalive'] unless node['yum']['mysql55-community']['keepalive'].nil? - max_retries node['yum']['mysql55-community']['max_retries'] unless node['yum']['mysql55-community']['max_retries'].nil? - metadata_expire node['yum']['mysql55-community']['metadata_expire'] unless node['yum']['mysql55-community']['metadata_expire'].nil? - mirror_expire node['yum']['mysql55-community']['mirror_expire'] unless node['yum']['mysql55-community']['mirror_expire'].nil? - priority node['yum']['mysql55-community']['priority'] unless node['yum']['mysql55-community']['priority'].nil? - proxy node['yum']['mysql55-community']['proxy'] unless node['yum']['mysql55-community']['proxy'].nil? - proxy_username node['yum']['mysql55-community']['proxy_username'] unless node['yum']['mysql55-community']['proxy_username'].nil? - proxy_password node['yum']['mysql55-community']['proxy_password'] unless node['yum']['mysql55-community']['proxy_password'].nil? - repositoryid node['yum']['mysql55-community']['repositoryid'] unless node['yum']['mysql55-community']['repositoryid'].nil? - sslcacert node['yum']['mysql55-community']['sslcacert'] unless node['yum']['mysql55-community']['sslcacert'].nil? - sslclientcert node['yum']['mysql55-community']['sslclientcert'] unless node['yum']['mysql55-community']['sslclientcert'].nil? - sslclientkey node['yum']['mysql55-community']['sslclientkey'] unless node['yum']['mysql55-community']['sslclientkey'].nil? - sslverify node['yum']['mysql55-community']['sslverify'] unless node['yum']['mysql55-community']['sslverify'].nil? - timeout node['yum']['mysql55-community']['timeout'] unless node['yum']['mysql55-community']['timeout'].nil? - action :create -end diff --git a/cookbooks/yum-mysql-community/recipes/mysql56.rb b/cookbooks/yum-mysql-community/recipes/mysql56.rb deleted file mode 100644 index 5adb378..0000000 --- a/cookbooks/yum-mysql-community/recipes/mysql56.rb +++ /dev/null @@ -1,48 +0,0 @@ -# -# Author:: Sean OMeara () -# Recipe:: yum-mysql-community::mysql56-community -# -# Copyright 2014-2015, Chef Software, Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -yum_repository 'mysql56-community' do - description node['yum']['mysql56-community']['description'] unless node['yum']['mysql56-community']['description'].nil? - baseurl node['yum']['mysql56-community']['baseurl'] unless node['yum']['mysql56-community']['baseurl'].nil? - mirrorlist node['yum']['mysql56-community']['mirrorlist'] unless node['yum']['mysql56-community']['mirrorlist'].nil? - gpgcheck node['yum']['mysql56-community']['gpgcheck'] unless node['yum']['mysql56-community']['gpgcheck'].nil? - gpgkey node['yum']['mysql56-community']['gpgkey'] unless node['yum']['mysql56-community']['gpgkey'].nil? - enabled node['yum']['mysql56-community']['enabled'] unless node['yum']['mysql56-community']['enabled'].nil? - cost node['yum']['mysql56-community']['cost'] unless node['yum']['mysql56-community']['cost'].nil? - exclude node['yum']['mysql56-community']['exclude'] unless node['yum']['mysql56-community']['exclude'].nil? - enablegroups node['yum']['mysql56-community']['enablegroups'] unless node['yum']['mysql56-community']['enablegroups'].nil? - failovermethod node['yum']['mysql56-community']['failovermethod'] unless node['yum']['mysql56-community']['failovermethod'].nil? - http_caching node['yum']['mysql56-community']['http_caching'] unless node['yum']['mysql56-community']['http_caching'].nil? - include_config node['yum']['mysql56-community']['include_config'] unless node['yum']['mysql56-community']['include_config'].nil? - includepkgs node['yum']['mysql56-community']['includepkgs'] unless node['yum']['mysql56-community']['includepkgs'].nil? - keepalive node['yum']['mysql56-community']['keepalive'] unless node['yum']['mysql56-community']['keepalive'].nil? - max_retries node['yum']['mysql56-community']['max_retries'] unless node['yum']['mysql56-community']['max_retries'].nil? - metadata_expire node['yum']['mysql56-community']['metadata_expire'] unless node['yum']['mysql56-community']['metadata_expire'].nil? - mirror_expire node['yum']['mysql56-community']['mirror_expire'] unless node['yum']['mysql56-community']['mirror_expire'].nil? - priority node['yum']['mysql56-community']['priority'] unless node['yum']['mysql56-community']['priority'].nil? - proxy node['yum']['mysql56-community']['proxy'] unless node['yum']['mysql56-community']['proxy'].nil? - proxy_username node['yum']['mysql56-community']['proxy_username'] unless node['yum']['mysql56-community']['proxy_username'].nil? - proxy_password node['yum']['mysql56-community']['proxy_password'] unless node['yum']['mysql56-community']['proxy_password'].nil? - repositoryid node['yum']['mysql56-community']['repositoryid'] unless node['yum']['mysql56-community']['repositoryid'].nil? - sslcacert node['yum']['mysql56-community']['sslcacert'] unless node['yum']['mysql56-community']['sslcacert'].nil? - sslclientcert node['yum']['mysql56-community']['sslclientcert'] unless node['yum']['mysql56-community']['sslclientcert'].nil? - sslclientkey node['yum']['mysql56-community']['sslclientkey'] unless node['yum']['mysql56-community']['sslclientkey'].nil? - sslverify node['yum']['mysql56-community']['sslverify'] unless node['yum']['mysql56-community']['sslverify'].nil? - timeout node['yum']['mysql56-community']['timeout'] unless node['yum']['mysql56-community']['timeout'].nil? - action :create -end diff --git a/cookbooks/yum-mysql-community/recipes/mysql57.rb b/cookbooks/yum-mysql-community/recipes/mysql57.rb deleted file mode 100644 index ba617c1..0000000 --- a/cookbooks/yum-mysql-community/recipes/mysql57.rb +++ /dev/null @@ -1,48 +0,0 @@ -# -# Author:: Sean OMeara () -# Recipe:: yum-mysql-community::mysql57-community -# -# Copyright 2014-2015, Chef Software, Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -yum_repository 'mysql57-community' do - description node['yum']['mysql57-community']['description'] unless node['yum']['mysql57-community']['description'].nil? - baseurl node['yum']['mysql57-community']['baseurl'] unless node['yum']['mysql57-community']['baseurl'].nil? - mirrorlist node['yum']['mysql57-community']['mirrorlist'] unless node['yum']['mysql57-community']['mirrorlist'].nil? - gpgcheck node['yum']['mysql57-community']['gpgcheck'] unless node['yum']['mysql57-community']['gpgcheck'].nil? - gpgkey node['yum']['mysql57-community']['gpgkey'] unless node['yum']['mysql57-community']['gpgkey'].nil? - enabled node['yum']['mysql57-community']['enabled'] unless node['yum']['mysql57-community']['enabled'].nil? - cost node['yum']['mysql57-community']['cost'] unless node['yum']['mysql57-community']['cost'].nil? - exclude node['yum']['mysql57-community']['exclude'] unless node['yum']['mysql57-community']['exclude'].nil? - enablegroups node['yum']['mysql57-community']['enablegroups'] unless node['yum']['mysql57-community']['enablegroups'].nil? - failovermethod node['yum']['mysql57-community']['failovermethod'] unless node['yum']['mysql57-community']['failovermethod'].nil? - http_caching node['yum']['mysql57-community']['http_caching'] unless node['yum']['mysql57-community']['http_caching'].nil? - include_config node['yum']['mysql57-community']['include_config'] unless node['yum']['mysql57-community']['include_config'].nil? - includepkgs node['yum']['mysql57-community']['includepkgs'] unless node['yum']['mysql57-community']['includepkgs'].nil? - keepalive node['yum']['mysql57-community']['keepalive'] unless node['yum']['mysql57-community']['keepalive'].nil? - max_retries node['yum']['mysql57-community']['max_retries'] unless node['yum']['mysql57-community']['max_retries'].nil? - metadata_expire node['yum']['mysql57-community']['metadata_expire'] unless node['yum']['mysql57-community']['metadata_expire'].nil? - mirror_expire node['yum']['mysql57-community']['mirror_expire'] unless node['yum']['mysql57-community']['mirror_expire'].nil? - priority node['yum']['mysql57-community']['priority'] unless node['yum']['mysql57-community']['priority'].nil? - proxy node['yum']['mysql57-community']['proxy'] unless node['yum']['mysql57-community']['proxy'].nil? - proxy_username node['yum']['mysql57-community']['proxy_username'] unless node['yum']['mysql57-community']['proxy_username'].nil? - proxy_password node['yum']['mysql57-community']['proxy_password'] unless node['yum']['mysql57-community']['proxy_password'].nil? - repositoryid node['yum']['mysql57-community']['repositoryid'] unless node['yum']['mysql57-community']['repositoryid'].nil? - sslcacert node['yum']['mysql57-community']['sslcacert'] unless node['yum']['mysql57-community']['sslcacert'].nil? - sslclientcert node['yum']['mysql57-community']['sslclientcert'] unless node['yum']['mysql57-community']['sslclientcert'].nil? - sslclientkey node['yum']['mysql57-community']['sslclientkey'] unless node['yum']['mysql57-community']['sslclientkey'].nil? - sslverify node['yum']['mysql57-community']['sslverify'] unless node['yum']['mysql57-community']['sslverify'].nil? - timeout node['yum']['mysql57-community']['timeout'] unless node['yum']['mysql57-community']['timeout'].nil? - action :create -end diff --git a/cookbooks/yum/CHANGELOG.md b/cookbooks/yum/CHANGELOG.md index 045b197..d49c48a 100644 --- a/cookbooks/yum/CHANGELOG.md +++ b/cookbooks/yum/CHANGELOG.md @@ -2,31 +2,6 @@ This file is used to list changes made in each version of the yum cookbook. -## 5.0.0 (2017-02-12) - -### Breaking changes - -- Removed the yum_repository resource and instead require chef-client 12.14 or later, which has the yum repository functionality built in. This resolves Chef 13 compatibility warnings for any cookbook with the yum cookbook. - -### Other changes - -- Convert yum_globalconfig from an LWRP to a custom resource - -## 4.2.0 (2017-02-12) - -- Make cache in the DNF compat recipe -- Fix `fastestmirror_enabled`. -- Require Chef 12.1 not 12.0 -- Convert to Inspec - -## 4.1.0 (2016-10-21) - -- Purge yum cache before removing a repo not after - -## 4.0.0 (2016-09-06) - -- Remove support for Chef 11 - ## 3.13.0 (2016-09-06) - Add deprecation warning for add/remove actions, which were replaced with create/delete in Yum 3.0 diff --git a/cookbooks/yum/MAINTAINERS.md b/cookbooks/yum/MAINTAINERS.md index b3548a4..c6a51ae 100644 --- a/cookbooks/yum/MAINTAINERS.md +++ b/cookbooks/yum/MAINTAINERS.md @@ -1,10 +1,13 @@ # Maintainers +This file lists how this cookbook project is maintained. When making changes to the system, this +file tells you who needs to review your patch - you need a simple majority of maintainers +for the relevant subsystems to provide a :+1: on your pull request. Additionally, you need +to not receive a veto from a Lieutenant or the Project Lead. -This file lists how this cookbook project is maintained. When making changes to the system, this file tells you who needs to review your patch - you need a review from an existing maintainer for the cookbook to provide a :+1: on your pull request. Additionally, you need to not receive a veto from a Lieutenant or the Project Lead. - -Check out [How Cookbooks are Maintained](https://github.com/chef-cookbooks/community_cookbook_documentation/blob/master/CONTRIBUTING.MD) for details on the process and how to become a maintainer or the project lead. +Check out [How Cookbooks are Maintained](https://github.com/chef-cookbooks/community_cookbook_documentation/blob/master/CONTRIBUTING.MD) +for details on the process and how to become a maintainer or the project lead. # Project Maintainer * [Tim Smith](https://github.com/tas50) diff --git a/cookbooks/yum/README.md b/cookbooks/yum/README.md index a312325..b73c3de 100644 --- a/cookbooks/yum/README.md +++ b/cookbooks/yum/README.md @@ -1,28 +1,92 @@ # yum Cookbook - [![Build Status](https://travis-ci.org/chef-cookbooks/yum.svg?branch=master)](http://travis-ci.org/chef-cookbooks/yum) [![Cookbook Version](https://img.shields.io/cookbook/v/yum.svg)](https://supermarket.chef.io/cookbooks/yum) -The Yum cookbook exposes the `yum_globalconfig` resource which allows a user to control global yum behavior. This resources aims to allow the user to configure all options listed in the `yum.conf` man page, found at +The Yum cookbook exposes the `yum_globalconfig` and `yum_repository` resources that allows a user to both control global behavior and make individual Yum repositories available for use. These resources aim to allow the user to configure all options listed in the `yum.conf` man page, found at [http://linux.die.net/man/5/yum.conf](http://linux.die.net/man/5/yum.conf) ## Requirements - ### Platforms - - RHEL/CentOS and derivatives - Fedora ### Chef - -- Chef 12.14+ +- Chef 11+ ### Cookbooks - - none -## Resources +## Resources/Providers +### yum_repository +This resource manages a yum repository configuration file at /etc/yum.repos.d/`repositoryid`.repo. When the file needs to be repaired, it calls yum-makecache so packages in the repo become available to the next resource. + +#### Example + +```ruby +# add the Zenoss repository +yum_repository 'zenoss' do + description "Zenoss Stable repo" + baseurl "http://dev.zenoss.com/yum/stable/" + gpgkey 'http://dev.zenoss.com/yum/RPM-GPG-KEY-zenoss' + action :create +end + +# add some internal company repo +yum_repository 'OurCo' do + description 'OurCo yum repository' + mirrorlist 'http://artifacts.ourco.org/mirrorlist?repo=ourco-6&arch=$basearch' + gpgkey 'http://artifacts.ourco.org/pub/yum/RPM-GPG-KEY-OURCO-6' + action :create +end +``` + +```ruby +# delete CentOS-Media repo +yum_repository 'CentOS-Media' do + action :delete +end +``` + +#### Actions +- `:create` - creates a repository file and builds the repository listing +- `:delete` - deletes the repository file +- `:makecache` - update yum cache + +#### Parameters +- `baseurl` - Must be a URL to the directory where the yum repository's 'repodata' directory lives. Can be an http://, ftp:// or file:// URL. You can specify multiple URLs in one baseurl statement. +- `cost` - relative cost of accessing this repository. Useful for weighing one repo's packages as greater/less than any other. defaults to 1000 +- `clean_metadata` - Run "yum clean metadata " during repository creation. defaults to true. +- `description` - Maps to the 'name' parameter in a repository .conf. Descriptive name for the repository channel. This directive must be specified. +- `enabled` - Either `true` or `false`. This tells yum whether or not use this repository. +- `enablegroups` - Either `true` or `false`. Determines whether yum will allow the use of package groups for this repository. Default is `true` (package groups are allowed). +- `exclude` - List of packages to exclude from updates or installs. This should be a space separated list in a single string. Shell globs using wildcards (eg. * and ?) are allowed. +- `failovermethod` - Either 'roundrobin' or 'priority'. +- `fastestmirror_enabled` - Either `true` or `false` +- `gpgcheck` - Either `true` or `false`. This tells yum whether or not it should perform a GPG signature check on packages. When this is set in the [main] section it sets the default for all repositories. The default is `true`. +- `gpgkey` - A URL pointing to the ASCII-armored GPG key file for the repository. This option is used if yum needs a public key to verify a package and the required key hasn't been imported into the RPM database. If this option is set, yum will automatically import the key from the specified URL. +- `http_caching` - Either 'all', 'packages', or 'none'. Determines how upstream HTTP caches are instructed to handle any HTTP downloads that Yum does. Defaults to 'all' +- `includepkgs` - Inverse of exclude. This is a list of packages you want to use from a repository. If this option lists only one package then that is all yum will ever see from the repository. Defaults to an empty list. +- `keepalive` - Either `true` or `false`. This tells yum whether or not HTTP/1.1 keepalive should be used with this repository. +- `make_cache` - Optional, Default is `true`, if `false` then `yum -q makecache` will not be ran +- `max_retries` - Set the number of times any attempt to retrieve a file should retry before returning an error. Setting this to '0' makes yum try forever. Default is '10'. +- `metadata_expire` - Time (in seconds) after which the metadata will expire. So that if the current metadata downloaded is less than this many seconds old then yum will not update the metadata against the repository. If you find that yum is not downloading information on updates as often as you would like lower the value of this option. You can also change from the default of using seconds to using days, hours or minutes by appending a d, h or m respectively. The default is 6 hours, to compliment yum-updatesd running once an hour. It's also possible to use the word "never", meaning that the metadata will never expire. Note that when using a metalink file the metalink must always be newer than the metadata for the repository, due to the validation, so this timeout also applies to the metalink file. +- `mirrorlist` - Specifies a URL to a file containing a list of baseurls. This can be used instead of or with the baseurl option. Substitution variables, described below, can be used with this option. As a special hack is the mirrorlist URL contains the word "metalink" then the value of mirrorlist is copied to metalink (if metalink is not set) +- `mirror_expire` - Time (in seconds) after which the mirrorlist locally cached will expire. If the current mirrorlist is less than this many seconds old then yum will not download another copy of the mirrorlist, it has the same extra format as metadata_expire. If you find that yum is not downloading the mirrorlists as often as you would like lower the value of this option. +- `mirrorlist_expire` - alias for mirror_expire +- `mode` - Permissions mode of .repo file on disk. Useful for scenarios where secrets are in the repo file. If set to '600', normal users will not be able to use yum search, yum info, etc. Defaults to '0644' +- `priority` - When the yum-priorities plug-in is enabled, you set priorities on repository entries, where N is an integer from 1 to 99. The default priority for repositories is 99. +- `proxy` - URL to the proxy server that yum should use. +- `proxy_username` - username to use for proxy +- `proxy_password` - password for this proxy +- `report_instanceid` - Report instance ID when using Amazon Linux AMIs and repositories +- `repositoryid` - Must be a unique name for each repository, one word. Defaults to name attribute. +- `sensitive` - Optional, Default is `false`, if `true` then content of repository file is hidden from chef run output. +- `source` - Use a custom template source instead of the default one in the yum cookbook +- `sslcacert` - Path to the directory containing the databases of the certificate authorities yum should use to verify SSL certificates. Defaults to none - uses system default +- `sslclientcert` - Path to the SSL client certificate yum should use to connect to repos/remote sites Defaults to none. +- `sslclientkey` - Path to the SSL client key yum should use to connect to repos/remote sites Defaults to none. +- `sslverify` - Either `true` or `false`. Determines if yum will verify SSL certificates/hosts. Defaults to `true` +- `timeout` - Number of seconds to wait for a connection before timing out. Defaults to 30 seconds. This may be too short of a time for extremely overloaded sites. ### yum_globalconfig - This renders a template with global yum configuration parameters. The default recipe uses it to render `/etc/yum.conf`. It is flexible enough to be used in other scenarios, such as building RPMs in isolation by modifying `installroot`. #### Example @@ -37,30 +101,22 @@ yum_globalconfig '/my/chroot/etc/yum.conf' do end ``` -#### Properties - -`yum_globalconfig` can take most of the same parameters as a `yum_repository`, plus more, too numerous to describe here. Below are a few of the more commonly used ones. For a complete list, please consult the `yum.conf` man page, found here: - +#### Parameters +`yum_globalconfig` can take most of the same parameters as a `yum_repository`, plus more, too numerous to describe here. Below are a few of the more commonly used ones. For a complete list, please consult the `yum.conf` man page, found here: [http://linux.die.net/man/5/yum.conf](http://linux.die.net/man/5/yum.conf) - `cachedir` - Directory where yum should store its cache and db files. The default is '/var/cache/yum'. - `keepcache` - Either `true` or `false`. Determines whether or not yum keeps the cache of headers and packages after successful installation. Default is `false` -- `debuglevel` - Debug message output level. Practical range is 0-10\. Default is '2'. +- `debuglevel` - Debug message output level. Practical range is 0-10. Default is '2'. - `exclude` - List of packages to exclude from updates or installs. This should be a space separated list. Shell globs using wildcards (eg. * and ?) are allowed. - `installonlypkgs` = List of package provides that should only ever be installed, never updated. Kernels in particular fall into this category. Defaults to kernel, kernel-bigmem, kernel-enterprise, kernel-smp, kernel-debug, kernel-unsupported, kernel-source, kernel-devel, kernel-PAE, kernel-PAE-debug. - `logfile` - Full directory and file name for where yum should write its log file. -- `exactarch` - Either `true` or `false`. Set to `true` to make 'yum update' only update the architectures of packages that you have installed. ie: with this enabled yum will not install an i686 package to update an x86_64 package. Default is `true` +- `exactarch` - Either `true` or `false`. Set to `true` to make 'yum update' only update the architectures of packages that you have installed. ie: with this enabled yum will not install an i686 package to update an x86_64 package. Default is `true` - `gpgcheck` - Either `true` or `false`. This tells yum whether or not it should perform a GPG signature check on the packages gotten from this repository. -### yum_repository - -This resource is now provided by chef-client 12.14 and later and has been removed from this cookbook. If you require this resource we highly recommend upgrading your chef-client, but if that is not an option you can pin the 4.X yum cookbook. - ## Recipes - - `default` - Configures `yum_globalconfig[/etc/yum.conf]` with values found in node attributes at `node['yum']['main']` -- `dnf_yum_compat` - Installs the yum package using dnf on Fedora systems to provide support for the package resource in recipes. This is necessary on chef-client < 12.18\. This recipe should be 1st on a Fedora runlist +- `dnf_yum_compat` - Installs the yum package using dnf on Fedora systems to provide support for the package resource in recipes. This is necessary as Chef does not yet (as of Q4 2015) have native support for DNF. This recipe should be 1st on a Fedora runlist ## Attributes - The following attributes are set by default ```ruby @@ -76,16 +132,14 @@ default['yum']['main']['installonlypkgs'] = nil default['yum']['main']['installroot'] = nil ``` -For Amazon platform nodes, +For Amazon platform nodes, ```ruby default['yum']['main']['releasever'] = 'latest' ``` ## Related Cookbooks - Recipes from older versions of this cookbook have been moved individual cookbooks. Recipes for managing platform yum configurations and installing specific repositories can be found in one (or more!) of the following cookbook. - - yum-centos - yum-fedora - yum-amazon @@ -97,11 +151,9 @@ Recipes from older versions of this cookbook have been moved individual cookbook - yum-pgdg ## Usage - Put `depends 'yum'` in your metadata.rb to gain access to the yum_repository resource. ## License & Authors - - Author:: Eric G. Wolfe - Author:: Matt Ray ([matt@chef.io](mailto:matt@chef.io)) - Author:: Joshua Timberman ([joshua@chef.io](mailto:joshua@chef.io)) @@ -109,7 +161,7 @@ Put `depends 'yum'` in your metadata.rb to gain access to the yum_repository res ```text Copyright:: 2011 Eric G. Wolfe -Copyright:: 2013-2017 Chef Software, Inc. +Copyright:: 2013-2016 Chef Software, Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/cookbooks/yum/libraries/matchers.rb b/cookbooks/yum/libraries/matchers.rb index 220238a..631b708 100644 --- a/cookbooks/yum/libraries/matchers.rb +++ b/cookbooks/yum/libraries/matchers.rb @@ -1,4 +1,20 @@ if defined?(ChefSpec) + def create_yum_repository(resource_name) + ChefSpec::Matchers::ResourceMatcher.new(:yum_repository, :create, resource_name) + end + + def add_yum_repository(resource_name) + ChefSpec::Matchers::ResourceMatcher.new(:yum_repository, :add, resource_name) + end + + def delete_yum_repository(resource_name) + ChefSpec::Matchers::ResourceMatcher.new(:yum_repository, :delete, resource_name) + end + + def remove_yum_repository(resource_name) + ChefSpec::Matchers::ResourceMatcher.new(:yum_repository, :remove, resource_name) + end + def create_yum_globalconfig(resource_name) ChefSpec::Matchers::ResourceMatcher.new(:yum_globalconfig, :create, resource_name) end diff --git a/cookbooks/yum/metadata.json b/cookbooks/yum/metadata.json index 550e2ab..3b3faac 100644 --- a/cookbooks/yum/metadata.json +++ b/cookbooks/yum/metadata.json @@ -1 +1 @@ -{"name":"yum","version":"5.0.0","description":"Configures various yum components on Red Hat-like systems","long_description":"","maintainer":"Chef Software, Inc.","maintainer_email":"cookbooks@chef.io","license":"Apache 2.0","platforms":{"amazon":">= 0.0.0","centos":">= 0.0.0","fedora":">= 0.0.0","oracle":">= 0.0.0","redhat":">= 0.0.0","scientific":">= 0.0.0","zlinux":">= 0.0.0"},"dependencies":{},"recommendations":{},"suggestions":{},"conflicting":{},"providing":{},"replacing":{},"attributes":{},"groupings":{},"recipes":{}} \ No newline at end of file +{"name":"yum","version":"3.13.0","description":"Configures various yum components on Red Hat-like systems","long_description":"","maintainer":"Chef Software, Inc.","maintainer_email":"cookbooks@chef.io","license":"Apache 2.0","platforms":{"amazon":">= 0.0.0","centos":">= 0.0.0","fedora":">= 0.0.0","oracle":">= 0.0.0","redhat":">= 0.0.0","scientific":">= 0.0.0","zlinux":">= 0.0.0"},"dependencies":{},"recommendations":{},"suggestions":{},"conflicting":{},"providing":{},"replacing":{},"attributes":{},"groupings":{},"recipes":{}} \ No newline at end of file diff --git a/cookbooks/yum/providers/globalconfig.rb b/cookbooks/yum/providers/globalconfig.rb new file mode 100644 index 0000000..ef649bb --- /dev/null +++ b/cookbooks/yum/providers/globalconfig.rb @@ -0,0 +1,40 @@ +# +# Cookbook Name:: yum +# Provider:: repository +# +# Author:: Sean OMeara +# Copyright 2013-2016, Chef Software, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +use_inline_resources + +def whyrun_supported? + true +end + +action :create do + template new_resource.path do + source 'main.erb' + cookbook 'yum' + mode '0644' + variables(config: new_resource) + end +end + +action :delete do + file new_resource.path do + action :delete + end +end diff --git a/cookbooks/yum/providers/repository.rb b/cookbooks/yum/providers/repository.rb new file mode 100644 index 0000000..0b7846c --- /dev/null +++ b/cookbooks/yum/providers/repository.rb @@ -0,0 +1,115 @@ +# +# Cookbook Name:: yum +# Provider:: repository +# +# Author:: Sean OMeara +# Copyright 2013-2016, Chef Software, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# In Chef 11 and above, calling the use_inline_resources method will +# make Chef create a new "run_context". When an action is called, any +# nested resources are compiled and converged in isolation from the +# recipe that calls it. + +use_inline_resources + +def whyrun_supported? + true +end + +action :add do + Chef::Log.warn('The :add method in yum_repository has been deprecated in favor of :create. Please update your cookbook to use the :create action') + action_create +end + +action :remove do + Chef::Log.warn('The :remove method in yum_repository has been deprecated in favor of :delete. Repository deletion in Chef 12.14+ with :remove will fail') + action_delete +end + +action :create do + if new_resource.clean_headers + Chef::Log.warn <<-eos + Use of `clean_headers` in resource yum[#{new_resource.repositoryid}] is now deprecated and will be removed in a future release. + `clean_metadata` should be used instead + eos + end + + template "/etc/yum.repos.d/#{new_resource.repositoryid}.repo" do + if new_resource.source.nil? + source 'repo.erb' + cookbook 'yum' + else + source new_resource.source + end + mode new_resource.mode + sensitive new_resource.sensitive + variables(config: new_resource) + if new_resource.make_cache + notifies :run, "execute[yum clean metadata #{new_resource.repositoryid}]", :immediately if new_resource.clean_metadata || new_resource.clean_headers + notifies :run, "execute[yum-makecache-#{new_resource.repositoryid}]", :immediately + notifies :create, "ruby_block[yum-cache-reload-#{new_resource.repositoryid}]", :immediately + end + end + + execute "yum clean metadata #{new_resource.repositoryid}" do + command "yum clean metadata --disablerepo=* --enablerepo=#{new_resource.repositoryid}" + action :nothing + end + + # get the metadata for this repo only + execute "yum-makecache-#{new_resource.repositoryid}" do + command "yum -q -y makecache --disablerepo=* --enablerepo=#{new_resource.repositoryid}" + action :nothing + only_if { new_resource.enabled } + end + + # reload internal Chef yum cache + ruby_block "yum-cache-reload-#{new_resource.repositoryid}" do + block { Chef::Provider::Package::Yum::YumCache.instance.reload } + action :nothing + end +end + +action :delete do + file "/etc/yum.repos.d/#{new_resource.repositoryid}.repo" do + action :delete + notifies :run, "execute[yum clean all #{new_resource.repositoryid}]", :immediately + notifies :create, "ruby_block[yum-cache-reload-#{new_resource.repositoryid}]", :immediately + end + + execute "yum clean all #{new_resource.repositoryid}" do + command "yum clean all --disablerepo=* --enablerepo=#{new_resource.repositoryid}" + only_if "yum repolist | grep -P '^#{new_resource.repositoryid}([ \t]|$)'" + action :nothing + end + + ruby_block "yum-cache-reload-#{new_resource.repositoryid}" do + block { Chef::Provider::Package::Yum::YumCache.instance.reload } + action :nothing + end +end + +action :makecache do + execute "yum-makecache-#{new_resource.repositoryid}" do + command "yum -q makecache --disablerepo=* --enablerepo=#{new_resource.repositoryid}" + action :run + end + + ruby_block "yum-cache-reload-#{new_resource.repositoryid}" do + block { Chef::Provider::Package::Yum::YumCache.instance.reload } + action :run + end +end diff --git a/cookbooks/yum/recipes/default.rb b/cookbooks/yum/recipes/default.rb index 2270028..d1fe392 100644 --- a/cookbooks/yum/recipes/default.rb +++ b/cookbooks/yum/recipes/default.rb @@ -3,7 +3,7 @@ # Author:: Joshua Timberman () # Recipe:: yum::default # -# Copyright:: 2013-2016, Chef Software, Inc () +# Copyright 2013-2016, Chef Software, Inc () # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/cookbooks/yum/recipes/dnf_yum_compat.rb b/cookbooks/yum/recipes/dnf_yum_compat.rb index f217cb7..a673f17 100644 --- a/cookbooks/yum/recipes/dnf_yum_compat.rb +++ b/cookbooks/yum/recipes/dnf_yum_compat.rb @@ -2,7 +2,7 @@ # Author:: Tim Smith () # Recipe:: yum::fedora_yum_compat # -# Copyright:: 2015-2016, Chef Software, Inc () +# Copyright 2015-2016, Chef Software, Inc () # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,14 +16,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -execute 'make yum cache' do - command 'yum makecache' - action :nothing -end - execute 'install yum' do command 'dnf install yum -y' not_if { ::File.exist?('/var/lib/yum') } action :nothing - notifies :run, 'execute[make yum cache]', :immediately end.run_action(:run) diff --git a/cookbooks/yum/resources/globalconfig.rb b/cookbooks/yum/resources/globalconfig.rb index a452e4c..e30185b 100644 --- a/cookbooks/yum/resources/globalconfig.rb +++ b/cookbooks/yum/resources/globalconfig.rb @@ -1,9 +1,9 @@ # -# Cookbook:: yum +# Cookbook Name:: yum # Resource:: repository # # Author:: Sean OMeara -# Copyright:: 2013-2017, Chef Software, Inc. +# Copyright 2013-2016, Chef Software, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,102 +18,92 @@ # limitations under the License. # +actions :create, :delete + +default_action :create + # http://linux.die.net/man/5/yum.conf -property :alwaysprompt, [TrueClass, FalseClass] -property :assumeyes, [TrueClass, FalseClass] -property :bandwidth, String, regex: /^\d+/ -property :bugtracker_url, String, regex: /.*/ -property :clean_requirements_on_remove, [TrueClass, FalseClass] -property :cachedir, String, regex: /.*/, default: '/var/cache/yum/$basearch/$releasever' -property :color, String, equal_to: %w(always never) -property :color_list_available_downgrade, String, regex: /.*/ -property :color_list_available_install, String, regex: /.*/ -property :color_list_available_reinstall, String, regex: /.*/ -property :color_list_available_upgrade, String, regex: /.*/ -property :color_list_installed_extra, String, regex: /.*/ -property :color_list_installed_newer, String, regex: /.*/ -property :color_list_installed_older, String, regex: /.*/ -property :color_list_installed_reinstall, String, regex: /.*/ -property :color_search_match, String, regex: /.*/ -property :color_update_installed, String, regex: /.*/ -property :color_update_local, String, regex: /.*/ -property :color_update_remote, String, regex: /.*/ -property :commands, String, regex: /.*/ -property :debuglevel, String, regex: /^\d+$/, default: '2' -property :deltarpm, [TrueClass, FalseClass] -property :diskspacecheck, [TrueClass, FalseClass] -property :distroverpkg, String, regex: /.*/ -property :enable_group_conditionals, [TrueClass, FalseClass] -property :errorlevel, String, regex: /^\d+$/ -property :exactarch, [TrueClass, FalseClass], default: true -property :exclude, String, regex: /.*/ -property :gpgcheck, [TrueClass, FalseClass], default: true -property :group_package_types, String, regex: /.*/ -property :groupremove_leaf_only, [TrueClass, FalseClass] -property :history_list_view, String, equal_to: %w(users commands single-user-commands) -property :history_record, [TrueClass, FalseClass] -property :history_record_packages, String, regex: /.*/ -property :http_caching, String, equal_to: %w(packages all none) -property :installonly_limit, String, regex: [/^\d+/, /keep/], default: '3' -property :installonlypkgs, String, regex: /.*/ -property :installroot, String, regex: /.*/ -property :keepalive, [TrueClass, FalseClass] -property :keepcache, [TrueClass, FalseClass], default: false -property :kernelpkgnames, String, regex: /.*/ -property :localpkg_gpgcheck, [TrueClass, FalseClass] -property :logfile, String, regex: /.*/, default: '/var/log/yum.log' -property :max_retries, String, regex: /^\d+$/ -property :mdpolicy, String, equal_to: %w(instant group:primary group:small group:main group:all) -property :metadata_expire, String, regex: [/^\d+$/, /^\d+[mhd]$/, /never/] -property :mirrorlist_expire, String, regex: /^\d+$/ -property :multilib_policy, String, equal_to: %w(all best) -property :obsoletes, [TrueClass, FalseClass] -property :overwrite_groups, [TrueClass, FalseClass] -property :password, String, regex: /.*/ -property :path, String, regex: /.*/, name_property: true -property :persistdir, String, regex: /.*/ -property :pluginconfpath, String, regex: /.*/ -property :pluginpath, String, regex: /.*/ -property :plugins, [TrueClass, FalseClass], default: true -property :protected_multilib, [TrueClass, FalseClass] -property :protected_packages, String, regex: /.*/ -property :proxy, String, regex: /.*/ -property :proxy_password, String, regex: /.*/ -property :proxy_username, String, regex: /.*/ -property :recent, String, regex: /^\d+$/ -property :releasever, String, regex: /.*/ -property :repo_gpgcheck, [TrueClass, FalseClass] -property :reposdir, String, regex: /.*/ -property :reset_nice, [TrueClass, FalseClass] -property :rpmverbosity, String, equal_to: %w(info critical emergency error warn debug) -property :showdupesfromrepos, [TrueClass, FalseClass] -property :skip_broken, [TrueClass, FalseClass] -property :ssl_check_cert_permissions, [TrueClass, FalseClass] -property :sslcacert, String, regex: /.*/ -property :sslclientcert, String, regex: /.*/ -property :sslclientkey, String, regex: /.*/ -property :sslverify, [TrueClass, FalseClass] -property :syslog_device, String, regex: /.*/ -property :syslog_facility, String, regex: /.*/ -property :syslog_ident, String, regex: /.*/ -property :throttle, String, regex: [/\d+k/, /\d+M/, /\d+G/] -property :timeout, String, regex: /^\d+$/ -property :tolerant, [TrueClass, FalseClass] -property :tsflags, String, regex: /.*/ -property :username, String, regex: /.*/ -property :options, Hash +attribute :alwaysprompt, kind_of: [TrueClass, FalseClass], default: nil +attribute :assumeyes, kind_of: [TrueClass, FalseClass], default: nil +attribute :bandwidth, kind_of: String, regex: /^\d+/, default: nil +attribute :bugtracker_url, kind_of: String, regex: /.*/, default: nil +attribute :clean_requirements_on_remove, kind_of: [TrueClass, FalseClass], default: nil +attribute :cachedir, kind_of: String, regex: /.*/, default: '/var/cache/yum/$basearch/$releasever' +attribute :color, kind_of: String, equal_to: %w(always never), default: nil +attribute :color_list_available_downgrade, kind_of: String, regex: /.*/, default: nil +attribute :color_list_available_install, kind_of: String, regex: /.*/, default: nil +attribute :color_list_available_reinstall, kind_of: String, regex: /.*/, default: nil +attribute :color_list_available_upgrade, kind_of: String, regex: /.*/, default: nil +attribute :color_list_installed_extra, kind_of: String, regex: /.*/, default: nil +attribute :color_list_installed_newer, kind_of: String, regex: /.*/, default: nil +attribute :color_list_installed_older, kind_of: String, regex: /.*/, default: nil +attribute :color_list_installed_reinstall, kind_of: String, regex: /.*/, default: nil +attribute :color_search_match, kind_of: String, regex: /.*/, default: nil +attribute :color_update_installed, kind_of: String, regex: /.*/, default: nil +attribute :color_update_local, kind_of: String, regex: /.*/, default: nil +attribute :color_update_remote, kind_of: String, regex: /.*/, default: nil +attribute :commands, kind_of: String, regex: /.*/, default: nil +attribute :debuglevel, kind_of: String, regex: /^\d+$/, default: '2' +attribute :deltarpm, kind_of: [TrueClass, FalseClass], default: nil +attribute :diskspacecheck, kind_of: [TrueClass, FalseClass], default: nil +attribute :distroverpkg, kind_of: String, regex: /.*/, default: nil +attribute :enable_group_conditionals, kind_of: [TrueClass, FalseClass], default: nil +attribute :errorlevel, kind_of: String, regex: /^\d+$/, default: nil +attribute :exactarch, kind_of: [TrueClass, FalseClass], default: true +attribute :exclude, kind_of: String, regex: /.*/, default: nil +attribute :gpgcheck, kind_of: [TrueClass, FalseClass], default: true +attribute :group_package_types, kind_of: String, regex: /.*/, default: nil +attribute :groupremove_leaf_only, kind_of: [TrueClass, FalseClass], default: nil +attribute :history_list_view, kind_of: String, equal_to: %w(users commands single-user-commands), default: nil +attribute :history_record, kind_of: [TrueClass, FalseClass], default: nil +attribute :history_record_packages, kind_of: String, regex: /.*/, default: nil +attribute :http_caching, kind_of: String, equal_to: %w(packages all none), default: nil +attribute :installonly_limit, kind_of: String, regex: [/^\d+/, /keep/], default: '3' +attribute :installonlypkgs, kind_of: String, regex: /.*/, default: nil +attribute :installroot, kind_of: String, regex: /.*/, default: nil +attribute :keepalive, kind_of: [TrueClass, FalseClass], default: nil +attribute :keepcache, kind_of: [TrueClass, FalseClass], default: false +attribute :kernelpkgnames, kind_of: String, regex: /.*/, default: nil +attribute :localpkg_gpgcheck, kind_of: [TrueClass, FalseClass], default: nil +attribute :logfile, kind_of: String, regex: /.*/, default: '/var/log/yum.log' +attribute :max_retries, kind_of: String, regex: /^\d+$/, default: nil +attribute :mdpolicy, kind_of: String, equal_to: %w(instant group:primary group:small group:main group:all), default: nil +attribute :metadata_expire, kind_of: String, regex: [/^\d+$/, /^\d+[mhd]$/, /never/], default: nil +attribute :mirrorlist_expire, kind_of: String, regex: /^\d+$/, default: nil +attribute :multilib_policy, kind_of: String, equal_to: %w(all best), default: nil +attribute :obsoletes, kind_of: [TrueClass, FalseClass], default: nil +attribute :overwrite_groups, kind_of: [TrueClass, FalseClass], default: nil +attribute :password, kind_of: String, regex: /.*/, default: nil +attribute :path, kind_of: String, regex: /.*/, name_attribute: true +attribute :persistdir, kind_of: String, regex: /.*/, default: nil +attribute :pluginconfpath, kind_of: String, regex: /.*/, default: nil +attribute :pluginpath, kind_of: String, regex: /.*/, default: nil +attribute :plugins, kind_of: [TrueClass, FalseClass], default: true +attribute :protected_multilib, kind_of: [TrueClass, FalseClass], default: nil +attribute :protected_packages, kind_of: String, regex: /.*/, default: nil +attribute :proxy, kind_of: String, regex: /.*/, default: nil +attribute :proxy_password, kind_of: String, regex: /.*/, default: nil +attribute :proxy_username, kind_of: String, regex: /.*/, default: nil +attribute :recent, kind_of: String, regex: /^\d+$/, default: nil +attribute :releasever, kind_of: String, regex: /.*/, default: nil +attribute :repo_gpgcheck, kind_of: [TrueClass, FalseClass], default: nil +attribute :reposdir, kind_of: String, regex: /.*/, default: nil +attribute :reset_nice, kind_of: [TrueClass, FalseClass], default: nil +attribute :rpmverbosity, kind_of: String, equal_to: %w(info critical emergency error warn debug), default: nil +attribute :showdupesfromrepos, kind_of: [TrueClass, FalseClass], default: nil +attribute :skip_broken, kind_of: [TrueClass, FalseClass], default: nil +attribute :ssl_check_cert_permissions, kind_of: [TrueClass, FalseClass], default: nil +attribute :sslcacert, kind_of: String, regex: /.*/, default: nil +attribute :sslclientcert, kind_of: String, regex: /.*/, default: nil +attribute :sslclientkey, kind_of: String, regex: /.*/, default: nil +attribute :sslverify, kind_of: [TrueClass, FalseClass], default: nil +attribute :syslog_device, kind_of: String, regex: /.*/, default: nil +attribute :syslog_facility, kind_of: String, regex: /.*/, default: nil +attribute :syslog_ident, kind_of: String, regex: /.*/, default: nil +attribute :throttle, kind_of: String, regex: [/\d+k/, /\d+M/, /\d+G/], default: nil +attribute :timeout, kind_of: String, regex: /^\d+$/, default: nil +attribute :tolerant, kind_of: [TrueClass, FalseClass], default: nil +attribute :tsflags, kind_of: String, regex: /.*/, default: nil +attribute :username, kind_of: String, regex: /.*/, default: nil -action :create do - template new_resource.path do - source 'main.erb' - cookbook 'yum' - mode '0644' - variables(config: new_resource) - end -end - -action :delete do - file new_resource.path do - action :delete - end -end +attribute :options, kind_of: Hash diff --git a/cookbooks/yum/resources/repository.rb b/cookbooks/yum/resources/repository.rb new file mode 100644 index 0000000..7514d5a --- /dev/null +++ b/cookbooks/yum/resources/repository.rb @@ -0,0 +1,71 @@ +# +# Cookbook Name:: yum +# Resource:: repository +# +# Author:: Sean OMeara +# Copyright 2013-2016, Chef Software, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +actions :create, :delete, :add, :remove, :makecache + +default_action :create + +# http://linux.die.net/man/5/yum.conf +attribute :baseurl, kind_of: [String, Array], regex: /.*/, default: nil +attribute :cost, kind_of: String, regex: /^\d+$/, default: nil +attribute :clean_headers, kind_of: [TrueClass, FalseClass], default: false # deprecated +attribute :clean_metadata, kind_of: [TrueClass, FalseClass], default: true +attribute :description, kind_of: String, regex: /.*/, default: 'Ye Ole Rpm Repo' +attribute :enabled, kind_of: [TrueClass, FalseClass], default: true +attribute :enablegroups, kind_of: [TrueClass, FalseClass], default: nil +attribute :exclude, kind_of: String, regex: /.*/, default: nil +attribute :failovermethod, kind_of: String, equal_to: %w(priority roundrobin), default: nil +attribute :fastestmirror_enabled, kind_of: [TrueClass, FalseClass], default: nil +attribute :gpgcheck, kind_of: [TrueClass, FalseClass], default: true +attribute :gpgkey, kind_of: [String, Array], regex: /.*/, default: nil +attribute :http_caching, kind_of: String, equal_to: %w(packages all none), default: nil +attribute :include_config, kind_of: String, regex: /.*/, default: nil +attribute :includepkgs, kind_of: String, regex: /.*/, default: nil +attribute :keepalive, kind_of: [TrueClass, FalseClass], default: nil +attribute :make_cache, kind_of: [TrueClass, FalseClass], default: true +attribute :max_retries, kind_of: [String, Integer], default: nil +attribute :metadata_expire, kind_of: String, regex: [/^\d+$/, /^\d+[mhd]$/, /never/], default: nil +attribute :mirrorexpire, kind_of: String, regex: /.*/, default: nil +attribute :mirrorlist, kind_of: String, regex: /.*/, default: nil +attribute :mirror_expire, kind_of: String, regex: [/^\d+$/, /^\d+[mhd]$/], default: nil +attribute :mirrorlist_expire, kind_of: String, regex: [/^\d+$/, /^\d+[mhd]$/], default: nil +attribute :mode, default: '0644' +attribute :priority, kind_of: String, regex: /^(\d?[0-9]|[0-9][0-9])$/, default: nil +attribute :proxy, kind_of: String, regex: /.*/, default: nil +attribute :proxy_username, kind_of: String, regex: /.*/, default: nil +attribute :proxy_password, kind_of: String, regex: /.*/, default: nil +attribute :username, kind_of: String, regex: /.*/, default: nil +attribute :password, kind_of: String, regex: /.*/, default: nil +attribute :repo_gpgcheck, kind_of: [TrueClass, FalseClass], default: nil +attribute :report_instanceid, kind_of: [TrueClass, FalseClass], default: nil +attribute :repositoryid, kind_of: String, regex: /.*/, name_attribute: true +attribute :sensitive, kind_of: [TrueClass, FalseClass], default: false +attribute :skip_if_unavailable, kind_of: [TrueClass, FalseClass], default: nil +attribute :source, kind_of: String, regex: /.*/, default: nil +attribute :sslcacert, kind_of: String, regex: /.*/, default: nil +attribute :sslclientcert, kind_of: String, regex: /.*/, default: nil +attribute :sslclientkey, kind_of: String, regex: /.*/, default: nil +attribute :sslverify, kind_of: [TrueClass, FalseClass], default: nil +attribute :timeout, kind_of: String, regex: /^\d+$/, default: nil + +attribute :options, kind_of: Hash + +alias_method :url, :baseurl +alias_method :keyurl, :gpgkey diff --git a/cookbooks/yum/templates/main.erb b/cookbooks/yum/templates/default/main.erb similarity index 100% rename from cookbooks/yum/templates/main.erb rename to cookbooks/yum/templates/default/main.erb diff --git a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider/support/yum_repo.erb b/cookbooks/yum/templates/default/repo.erb similarity index 95% rename from cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider/support/yum_repo.erb rename to cookbooks/yum/templates/default/repo.erb index 7d9a2d0..5fd6e7f 100644 --- a/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider/support/yum_repo.erb +++ b/cookbooks/yum/templates/default/repo.erb @@ -4,8 +4,13 @@ [<%= @config.repositoryid %>] name=<%= @config.description %> <% if @config.baseurl %> -baseurl=<%= @config.baseurl %> -<% end %> +baseurl=<%= case @config.baseurl + when Array + @config.baseurl.join("\n") + else + @config.baseurl + end %> +<% end -%> <% if @config.cost %> cost=<%= @config.cost %> <% end %>