Search
SailfishOS Open Build Service
>
Projects
>
home:ballock
:
puppet4
>
puppet
> deb-0007-Fix-service-listing-and-enable-disable-in-Debian.patch
Log In
Username
Password
Cancel
Overview
Repositories
Revisions
Requests
Users
Advanced
Attributes
Meta
File deb-0007-Fix-service-listing-and-enable-disable-in-Debian.patch of Package puppet
From a9b76dbfba96f537227c445297d3ccd115de46ca Mon Sep 17 00:00:00 2001 From: Apollon Oikonomopoulos <apoikos@debian.org> Date: Fri, 27 Feb 2015 10:55:34 +0200 Subject: [PATCH] Fix service listing and enable/disable in Debian MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit • Under systemd, use systemctl enable/disable for all services. This works correctly for all types of services. As of Stretch, systemctl is-enabled also works correctly for all service types • Fix self.instances to augment the list of systemd-enabled services with the sysv services. • Drop pre-2.88 sysv-rc support and use `update-rc.d enable' for all services when running under sysv-rc; in addition to simplifying things, this also preserves any ordering changes across enable/disable. --- lib/puppet/provider/service/debian.rb | 94 ++++++++++++++++++++++++++--------- 1 file changed, 71 insertions(+), 23 deletions(-) --- a/lib/puppet/provider/service/debian.rb +++ b/lib/puppet/provider/service/debian.rb @@ -16,43 +16,78 @@ # is resolved. commands :invoke_rc => "/usr/sbin/invoke-rc.d" commands :service => "/usr/sbin/service" + optional_commands :systemctl => "/bin/systemctl" defaultfor :operatingsystem => :cumuluslinux, :operatingsystemmajrelease => ['1','2'] defaultfor :operatingsystem => :debian, :operatingsystemmajrelease => ['5','6','7'] + def self.runs_on_systemd? + Dir.exists? "/run/systemd/system" + end + + def self.instances + # We need to merge services with systemd unit files with those only having + # an initscript. Note that we could use `systemctl --all` to get sysv + # services as well, however it would only output *enabled* services. + i = {} + if self.runs_on_systemd? + begin + output = systemctl('list-unit-files', '--type', 'service', '--full', '--all', '--no-pager') + output.scan(/^(\S+)\.service\s+(disabled|enabled)\s*$/i).each do |m| + i[m[0]] = new(:name => m[0]) + end + rescue Puppet::ExecutionFailure + end + end + get_services(defpath).each do |sysv| + unless i.has_key?(sysv.name) + i[sysv.name] = sysv + end + end + return i.values + end + # Remove the symlinks def disable - if `dpkg --compare-versions $(dpkg-query -W --showformat '${Version}' sysv-rc) ge 2.88 ; echo $?`.to_i == 0 - update_rc @resource[:name], "disable" + if self.class.runs_on_systemd? + systemctl(:disable, @resource[:name]) else - update_rc "-f", @resource[:name], "remove" - update_rc @resource[:name], "stop", "00", "1", "2", "3", "4", "5", "6", "." + update_rc @resource[:name], "disable" end end def enabled? - # TODO: Replace system call when Puppet::Util::Execution.execute gives us a way - # to determine exit status. https://projects.puppetlabs.com/issues/2538 - system("/usr/sbin/invoke-rc.d", "--quiet", "--query", @resource[:name], "start") - - # 104 is the exit status when you query start an enabled service. - # 106 is the exit status when the policy layer supplies a fallback action - # See x-man-page://invoke-rc.d - if [104, 106].include?($CHILD_STATUS.exitstatus) - return :true - elsif [101, 105].include?($CHILD_STATUS.exitstatus) - # 101 is action not allowed, which means we have to do the check manually. - # 105 is unknown, which generally means the initscript does not support query - # The debian policy states that the initscript should support methods of query - # For those that do not, perform the checks manually - # http://www.debian.org/doc/debian-policy/ch-opersys.html - if get_start_link_count >= 4 + if self.class.runs_on_systemd? + begin + systemctl("is-enabled", @resource[:name]) return :true - else + rescue Puppet::ExecutionFailure return :false end else - return :false + # TODO: Replace system call when Puppet::Util::Execution.execute gives us a way + # to determine exit status. https://projects.puppetlabs.com/issues/2538 + system("/usr/sbin/invoke-rc.d", "--quiet", "--query", @resource[:name], "start") + + # 104 is the exit status when you query start an enabled service. + # 106 is the exit status when the policy layer supplies a fallback action + # See x-man-page://invoke-rc.d + if [104, 106].include?($CHILD_STATUS.exitstatus) + return :true + elsif [101, 105].include?($CHILD_STATUS.exitstatus) + # 101 is action not allowed, which means we have to do the check manually. + # 105 is unknown, which generally means the iniscript does not support query + # The debian policy states that the initscript should support methods of query + # For those that do not, peform the checks manually + # http://www.debian.org/doc/debian-policy/ch-opersys.html + if get_start_link_count >= 4 + return :true + else + return :false + end + else + return :false + end end end @@ -61,8 +96,12 @@ end def enable - update_rc "-f", @resource[:name], "remove" - update_rc @resource[:name], "defaults" + if self.class.runs_on_systemd? + systemctl(:enable, @resource[:name]) + else + update_rc @resource[:name], "defaults" + update_rc @resource[:name], "enable" + end end # The start, stop, restart and status command use service