diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2014-09-05 13:20:04 -0700 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2014-09-05 13:20:04 -0700 |
commit | e541db80bd5f297614dd3c6b838c3fcd67ac7c6d (patch) | |
tree | c053b11eadc3dfcc5e6ac2d562738717798129f7 | |
parent | ad0bfd815f24938acaf9d4627c31dee8a3642583 (diff) | |
download | chef-lcg/ubuntu-service-provider.tar.gz |
Add magical ubuntu service providerlcg/ubuntu-service-provider
This is a minimum viable Provider Resolver just for Ubuntu 14.04
services that need to be either upstart or debian-flavoured sysv
init scripts.
-rw-r--r-- | lib/chef/platform/provider_mapping.rb | 3 | ||||
-rw-r--r-- | lib/chef/provider/service/ubuntu.rb | 62 | ||||
-rw-r--r-- | lib/chef/providers.rb | 1 | ||||
-rw-r--r-- | lib/chef/resource.rb | 13 |
4 files changed, 77 insertions, 2 deletions
diff --git a/lib/chef/platform/provider_mapping.rb b/lib/chef/platform/provider_mapping.rb index 7f79c38a6a..1bc3be2666 100644 --- a/lib/chef/platform/provider_mapping.rb +++ b/lib/chef/platform/provider_mapping.rb @@ -26,7 +26,6 @@ require 'chef/version_constraint/platform' # Therefore, we do the includes inline rather than up top. require 'chef/provider' - class Chef class Platform @@ -65,7 +64,7 @@ class Chef :ubuntu => { :default => { :package => Chef::Provider::Package::Apt, - :service => Chef::Provider::Service::Debian, + :service => Chef::Provider::Service::Ubuntu, :cron => Chef::Provider::Cron, :mdadm => Chef::Provider::Mdadm }, diff --git a/lib/chef/provider/service/ubuntu.rb b/lib/chef/provider/service/ubuntu.rb new file mode 100644 index 0000000000..7a2d1507a4 --- /dev/null +++ b/lib/chef/provider/service/ubuntu.rb @@ -0,0 +1,62 @@ +# +# Author:: Lamont Granquist <lamont@getchef.com> +# Copyright:: Copyright (c) 2014 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/provider/service/upstart' +require 'chef/provider/service/debian' +require 'forwardable' + +class Chef + class Provider + class Service + class Ubuntu + extend Forwardable + + attr_reader :sub_service + + def_delegator :@sub_service, :load_current_resource + def_delegator :@sub_service, :action_start + def_delegator :@sub_service, :action_stop + def_delegator :@sub_service, :action_restart + def_delegator :@sub_service, :action_enable + def_delegator :@sub_service, :action_disable + def_delegator :@sub_service, :define_resource_requirements + def_delegator :@sub_service, :whyrun_supported? + def_delegator :@sub_service, :action= + def_delegator :@sub_service, :run_action + + def initialize(new_resource, run_context) + platform, version = Chef::Platform.find_platform_and_version(run_context.node) + if platform == "ubuntu" && (8.04..9.04).include?(version.to_f) + upstart_job_dir = "/etc/event.d" + upstart_conf_suffix = "" + else + upstart_job_dir = "/etc/init" + upstart_conf_suffix = ".conf" + end + + @sub_service = + if ::File.exists?("#{upstart_job_dir}/#{new_resource.service_name}#{upstart_conf_suffix}") + Chef::Provider::Service::Upstart.new(new_resource, run_context) + else + Chef::Provider::Service::Debian.new(new_resource, run_context) + end + end + end + end + end +end diff --git a/lib/chef/providers.rb b/lib/chef/providers.rb index 3c9e94e6f7..8aab4a8694 100644 --- a/lib/chef/providers.rb +++ b/lib/chef/providers.rb @@ -81,6 +81,7 @@ require 'chef/provider/service/invokercd' require 'chef/provider/service/redhat' require 'chef/provider/service/simple' require 'chef/provider/service/systemd' +require 'chef/provider/service/ubuntu' require 'chef/provider/service/upstart' require 'chef/provider/service/windows' require 'chef/provider/service/solaris' diff --git a/lib/chef/resource.rb b/lib/chef/resource.rb index 70abfbcdb0..2fe99a3af2 100644 --- a/lib/chef/resource.rb +++ b/lib/chef/resource.rb @@ -33,6 +33,16 @@ require 'chef/platform' require 'chef/mixin/deprecation' +# need the symbol to not be undefined +class Chef + class Provider + class Service < Chef::Provider + class Ubuntu + end + end + end +end + class Chef class Resource class Notification < Struct.new(:resource, :action, :notifying_resource) @@ -325,6 +335,9 @@ F end def provider(arg=nil) + if arg == Chef::Provider::Service::Ubuntu + raise "The Chef::Provider::Service::Ubuntu service provider is not a stable API, and should not be used directly by user code" + end klass = if arg.kind_of?(String) || arg.kind_of?(Symbol) lookup_provider_constant(arg) else |