- populated = template % {hostname:hostname, uuid_prefix:@@uuid_prefix, ip_address:ip_address, ptr_domain:ptr_domain}
+ if (!Rails.configuration.Containers.SLURM.Managed.DNSServerConfDir.to_s.empty? and
+ !Rails.configuration.Containers.SLURM.Managed.DNSServerConfTemplate.to_s.empty?)
+ tmpfile = nil
+ begin
+ begin
+ template = IO.read(Rails.configuration.Containers.SLURM.Managed.DNSServerConfTemplate)
+ rescue IOError, SystemCallError => e
+ logger.error "Reading #{Rails.configuration.Containers.SLURM.Managed.DNSServerConfTemplate}: #{e.message}"
+ raise
+ end
+
+ hostfile = File.join Rails.configuration.Containers.SLURM.Managed.DNSServerConfDir, "#{hostname}.conf"
+ Tempfile.open(["#{hostname}-", ".conf.tmp"],
+ Rails.configuration.Containers.SLURM.Managed.DNSServerConfDir) do |f|
+ tmpfile = f.path
+ f.puts template % template_vars
+ end
+ File.rename tmpfile, hostfile
+ rescue IOError, SystemCallError => e
+ logger.error "Writing #{hostfile}: #{e.message}"
+ ok = false
+ ensure
+ if tmpfile and File.file? tmpfile
+ # Cleanup remaining temporary file.
+ File.unlink tmpfile
+ end
+ end
+ end