diff options
author | Robby Dyer <rdyer@tropo.com> | 2014-06-17 14:53:46 -0400 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2015-08-18 13:40:45 -0700 |
commit | b5e9c70e43b8d37eee1fb9f5aaae391125c4cc22 (patch) | |
tree | 3d60b52c13c5ce007c00ba9cf3409beca15af1d7 /lib | |
parent | 1bdf739b844489424283852af56f5a8f2b8f362a (diff) | |
download | chef-b5e9c70e43b8d37eee1fb9f5aaae391125c4cc22.tar.gz |
CHEF-5372: Support specific run_levels for RedHat service
Diffstat (limited to 'lib')
-rw-r--r-- | lib/chef/provider/service/redhat.rb | 24 | ||||
-rw-r--r-- | lib/chef/resource/service.rb | 11 |
2 files changed, 30 insertions, 5 deletions
diff --git a/lib/chef/provider/service/redhat.rb b/lib/chef/provider/service/redhat.rb index 19cd2aa485..a471d4bbe4 100644 --- a/lib/chef/provider/service/redhat.rb +++ b/lib/chef/provider/service/redhat.rb @@ -1,6 +1,6 @@ # # Author:: AJ Christensen (<aj@hjksolutions.com>) -# Copyright:: Copyright (c) 2008 Opscode, Inc. +# Copyright:: Copyright (c) 2008-2015 Chef Software, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -39,6 +39,7 @@ class Chef @init_command = "/sbin/service #{@new_resource.service_name}" @new_resource.supports[:status] = true @service_missing = false + @run_levels = @new_resource.run_levels end def define_resource_requirements @@ -62,19 +63,34 @@ class Chef if ::File.exists?("/sbin/chkconfig") chkconfig = shell_out!("/sbin/chkconfig --list #{@current_resource.service_name}", :returns => [0,1]) - @current_resource.enabled(!!(chkconfig.stdout =~ CHKCONFIG_ON)) + unless @run_levels.nil? or @run_levels.empty? + chkconfig.split(/\s+/)[1..-1].each do |level| + index = level.split(':').first + status = level.split(':').last + is_enabled = false + is_enabled = true if @run_levels.include?(index) and status =~ CHKCONFIG_ON + @current_resource.enabled(is_enabled) + end + else + @current_resource.enabled(!!(chkconfig.stdout =~ CHKCONFIG_ON)) + end @service_missing = !!(chkconfig.stderr =~ CHKCONFIG_MISSING) end @current_resource end + def levels + (@run_levels.nil? or @run_levels.empty?) ? levels = "" : levels = "--level #{@run_levels.join('')} " + levels + end + def enable_service() - shell_out! "/sbin/chkconfig #{@new_resource.service_name} on" + shell_out! "/sbin/chkconfig #{levels}#{@new_resource.service_name} on" end def disable_service() - shell_out! "/sbin/chkconfig #{@new_resource.service_name} off" + shell_out! "/sbin/chkconfig #{levels}#{@new_resource.service_name} off" end end end diff --git a/lib/chef/resource/service.rb b/lib/chef/resource/service.rb index aa59b543be..e65f1bf724 100644 --- a/lib/chef/resource/service.rb +++ b/lib/chef/resource/service.rb @@ -1,7 +1,7 @@ # # Author:: AJ Christensen (<aj@hjksolutions.com>) # Author:: Tyler Cloke (<tyler@opscode.com>) -# Copyright:: Copyright (c) 2008 Opscode, Inc. +# Copyright:: Copyright (c) 2008-2015 Chef Software, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -44,6 +44,8 @@ class Chef @init_command = nil @priority = nil @timeout = nil + @run_levels = nil + @action = "nothing" @supports = { :restart => false, :reload => false, :status => false } end @@ -174,6 +176,13 @@ class Chef ) end + def run_levels(arg=nil) + set_or_return( + :run_levels, + arg, + :kind_of => [ Array ] ) + end + def supports(args={}) if args.is_a? Array args.each { |arg| @supports[arg] = true } |