swiftinit provider check init/systemd file content

Compare contents of the init/systemd file on disk against
swiftinit provider template contents.  If they don't match
then the distro provided init/systemd file has not been replaced.
swiftinit provider will call service enable and write out correct
init/systemd file.

Change-Id: I722f6cfa8c537d62a607880cc37863f2d1139636
This commit is contained in:
Adam Vinsh
2015-12-14 20:46:36 -05:00
parent 1dfe3d29a9
commit f3c1832bbb

View File

@@ -53,11 +53,16 @@ Puppet::Type.type(:service).provide :swiftinit, :parent => :service do
end
end
# Returns service enabled status using systemctl on Redhat/Debian
# and using presence of init file on Ubuntu.
# Returns service enabled status first checking for init/systemd file
# presence then checking if file content matches this provider and not
# distro provided. Also on Redhat/Debian checks systemctl status.
def enabled?
if Facter.value(:operatingsystem) != 'Ubuntu'
if Puppet::FileSystem.exist?("/etc/systemd/system/#{resource[:pattern]}.service")
current_conf = File.read("/etc/systemd/system/#{resource[:pattern]}.service")
if !current_conf.eql? systemd_template
return :false
end
if systemctl_run('is-enabled', [resource[:pattern]], false).exitstatus == 0
return :true
end
@@ -66,7 +71,10 @@ Puppet::Type.type(:service).provide :swiftinit, :parent => :service do
end
elsif Facter.value(:operatingsystem) == 'Ubuntu'
if Puppet::FileSystem.exist?("/etc/init/#{resource[:pattern]}.conf")
return :true
current_conf = File.read("/etc/init/#{resource[:pattern]}.conf")
if current_conf.eql? upstart_template
return :true
end
else
return :false
end