Skip to content

Commit

Permalink
SMF LWRP triggers import/reload if service does not exist
Browse files Browse the repository at this point in the history
If the manifest already existed and matched the LWRP attributes,
but the service did not actually exist, it would not get imported.
This could happen if you manually ran `svccfg delete`, then reran chef.
  • Loading branch information
sax committed Jul 26, 2013
1 parent f828c62 commit 5dbf485
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
17 changes: 7 additions & 10 deletions providers/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
include Chef::Mixin::ShellOut

def load_current_resource
find_fmri

@current_resource = Chef::Resource::Smf.new(new_resource.name)
@current_resource.fmri(new_resource.fmri)
@current_resource.load

find_fmri
end

action :install do
Expand Down Expand Up @@ -45,7 +46,7 @@ def load_current_resource
action :delete do
new_resource.updated_by_last_action(false)

if smf_exists?
if @current_resource.smf_exists?
service new_resource.name do
action [:stop, :disable]
end
Expand All @@ -63,18 +64,14 @@ def load_current_resource

private

def smf_exists?
shell_out("svcs -a #{new_resource.name}").exitstatus == 0
end

def smf_changed?
@current_resource.checksum != new_resource.checksum
@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} | awk 'BEGIN { FS=":"}; {print $2}'})
fmri_check = shell_out(%{svcs -H -o FMRI #{new_resource.name}})
if fmri_check.exitstatus == 0
new_resource.fmri fmri_check.stdout.chomp
new_resource.fmri fmri_check.stdout.chomp.split(':')[1]
else
new_resource.fmri "/#{new_resource.manifest_type}/management/#{new_resource.name}"
end
Expand Down
9 changes: 9 additions & 0 deletions resources/default.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@

require 'chef/mixin/shell_out'
include Chef::Mixin::ShellOut

actions :install, :add_rbac, :delete
default_action :install

Expand Down Expand Up @@ -70,7 +73,9 @@ def remove_checksum
#
def load
@checksum ||= ::File.exists?(checksum_file) ? ::File.read(checksum_file) : ''
@smf_exists = shell_out("svcs #{self.fmri}").exitstatus == 0
Chef::Log.debug("Loaded checksum for SMF #{self.name}: #{@checksum}")
Chef::Log.debug("SMF service already exists for #{self.fmri}? #{@smf_exists.inspect}")
end

def checksum
Expand Down Expand Up @@ -109,3 +114,7 @@ def environment_as_string
return nil if self.environment.nil?
self.environment.inject('') { |memo, k,v| memo << [k,v].join('|')}
end

def smf_exists?
@smf_exists
end

0 comments on commit 5dbf485

Please sign in to comment.