Sha256: 3ba2852f060834d174b88648a609297f86789004c197a4a9e92074259d5b364c

Contents?: true

Size: 931 Bytes

Versions: 1

Compression:

Stored size: 931 Bytes

Contents

# frozen_string_literal: true

module Dyndnsd
  module Updater
    class CommandWithBindZone
      # @param domain [String]
      # @param config [Hash{String => Object}]
      def initialize(domain, config)
        @zone_file = config['zone_file']
        @command = config['command']
        @generator = Generator::Bind.new(domain, config)
      end

      # @param db [Dyndnsd::Database]
      # @return [void]
      def update(db)
        Helper.span('updater_update') do |span|
          span.set_tag('dyndnsd.updater.name', self.class.name&.split('::')&.last || 'None')

          # write zone file in bind syntax
          File.open(@zone_file, 'w') { |f| f.write(@generator.generate(db)) }
          # call user-defined command
          pid = fork do
            exec @command
          end

          # detach so children don't become zombies
          Process.detach(pid) if pid
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dyndnsd-2.2.0 lib/dyndnsd/updater/command_with_bind_zone.rb