Class: Chef::Resource::File::Verification::SystemdUnit
- Inherits:
-
Chef::Resource::File::Verification
- Object
- Chef::Resource::File::Verification
- Chef::Resource::File::Verification::SystemdUnit
- Includes:
- Mixin::Which
- Defined in:
- lib/chef/resource/file/verification/systemd_unit.rb
Overview
Systemd provides a binary for verifying the correctness of unit files. Unfortunately some units have constraints on the filename meaning that normal verification against temp files won’t work.
Working around that requires placing a copy of the temp file in a temp directory, under its real name and running the verification tool against that file.
Instance Attribute Summary
Attributes inherited from Chef::Resource::File::Verification
Instance Method Summary collapse
-
#initialize(parent_resource, command, opts, &block) ⇒ SystemdUnit
constructor
A new instance of SystemdUnit.
- #systemd_analyze_cmd ⇒ Object
- #systemd_analyze_path ⇒ Object
- #verify(path, opts = {}) ⇒ Object
Methods inherited from Chef::Resource::File::Verification
#logger, lookup, provides, provides?, #to_s, #verify_block, #verify_command, #verify_registered_verification
Methods included from Mixin::DescendantsTracker
#descendants, descendants, direct_descendants, #direct_descendants, find_descendants_by_name, #find_descendants_by_name, #inherited, store_inherited
Constructor Details
#initialize(parent_resource, command, opts, &block) ⇒ SystemdUnit
Returns a new instance of SystemdUnit.
42 43 44 45 |
# File 'lib/chef/resource/file/verification/systemd_unit.rb', line 42 def initialize(parent_resource, command, opts, &block) super @command = systemd_analyze_cmd end |
Instance Method Details
#systemd_analyze_cmd ⇒ Object
57 58 59 |
# File 'lib/chef/resource/file/verification/systemd_unit.rb', line 57 def systemd_analyze_cmd @systemd_analyze_cmd ||= "#{systemd_analyze_path} verify %{path}" end |
#systemd_analyze_path ⇒ Object
61 62 63 |
# File 'lib/chef/resource/file/verification/systemd_unit.rb', line 61 def systemd_analyze_path @systemd_analyze_path ||= which("systemd-analyze") end |
#verify(path, opts = {}) ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/chef/resource/file/verification/systemd_unit.rb', line 47 def verify(path, opts = {}) return true unless systemd_analyze_path Dir.mktmpdir("chef-systemd-unit") do |dir| temp = "#{dir}/#{::File.basename(@parent_resource.path)}" ::TargetIO::FileUtils.cp(path, temp) verify_command(temp, opts) end end |