class Chef::Resource::File::Verification::SystemdUnit

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.

Public Class Methods

new(parent_resource, command, opts, &block) click to toggle source
Calls superclass method Chef::Resource::File::Verification.new
# File lib/chef/resource/file/verification/systemd_unit.rb, line 42
def initialize(parent_resource, command, opts, &block)
  super
  @command = systemd_analyze_cmd
end

Public Instance Methods

systemd_analyze_cmd() click to toggle source
# File lib/chef/resource/file/verification/systemd_unit.rb, line 56
def systemd_analyze_cmd
  @systemd_analyze_cmd ||= "#{systemd_analyze_path} verify %{path}"
end
systemd_analyze_path() click to toggle source
# File lib/chef/resource/file/verification/systemd_unit.rb, line 60
def systemd_analyze_path
  @systemd_analyze_path ||= which("systemd-analyze")
end
verify(path, opts = {}) click to toggle source
# 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)}"
    ::FileUtils.cp(path, temp)
    verify_command(temp, opts)
  end
end