- hostfile = File.join @@confdir, hostname
- File.open hostfile, 'w' do |f|
- f.puts "address=/#{hostname}/#{ip_address}"
- f.puts "address=/#{hostname}.#{@@domain}/#{ip_address}" if @@domain
- f.puts "ptr-record=#{ptr_domain},#{hostname}"
+
+ template_vars = {
+ hostname: hostname,
+ uuid_prefix: Rails.configuration.ClusterID,
+ 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