Class: Dyndnsd::Updater::CommandWithBindZone

Inherits:
Object
  • Object
show all
Defined in:
lib/dyndnsd/updater/command_with_bind_zone.rb

Instance Method Summary collapse

Constructor Details

#initialize(domain, updater_params) ⇒ CommandWithBindZone

Returns a new instance of CommandWithBindZone.

Parameters:

  • domain (String)
  • updater_params (Hash{String => Object})


8
9
10
11
12
# File 'lib/dyndnsd/updater/command_with_bind_zone.rb', line 8

def initialize(domain, updater_params)
  @zone_file = updater_params['zone_file']
  @command = updater_params['command']
  @generator = Generator::Bind.new(domain, updater_params)
end

Instance Method Details

#update(db) ⇒ void

This method returns an undefined value.

Parameters:



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/dyndnsd/updater/command_with_bind_zone.rb', line 16

def update(db)
  # do not regenerate zone file (assumed to be persistent) if DB did not change
  return if !db.changed?

  Helper.span('updater_update') do |span|
    span.set_attribute('dyndnsd.updater.name', self.class.name&.split('::')&.last || 'None')

    # write zone file in bind syntax
    File.write(@zone_file, @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