Skip to content

Instantly share code, notes, and snippets.

@ahamid
Created June 27, 2012 22:30
Show Gist options
  • Save ahamid/3007309 to your computer and use it in GitHub Desktop.
Save ahamid/3007309 to your computer and use it in GitHub Desktop.
chef restorecon helper
libraries/restorecon.rb
def restorecon_cmd(path)
%Q(restorecon "#{path}")
end
# restores selinux label for path
def restorecon(path)
execute restorecon_cmd(path) do
action :nothing
end
if block_given?
res = yield path
res && res.notifies(:run, resources(:execute => restorecon_cmd(path)), :immediately)
end
end
def notify_restorecon(path)
# todo: can't the particular restorecon resource just be generated dynamically?
# looks ugly :/ http://comments.gmane.org/gmane.comp.sysutils.chef.user/1982
notifies :run, resources(:execute => restorecon_cmd(path)), :immediately
end
...
restorecon '/etc/smartd.conf' do |path|
cookbook_file path do
source path
owner "root"
group "root"
mode "0644"
notifies :restart, "service[smartd]"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment