2013-04-27 14:07:14 +02:00
|
|
|
|
|
|
|
module Dyndnsd
|
|
|
|
module Updater
|
|
|
|
class CommandWithBindZone
|
2020-02-28 15:13:28 +01:00
|
|
|
# @param domain [String]
|
|
|
|
# @param config [Hash{String => Object}]
|
2013-04-27 15:08:36 +02:00
|
|
|
def initialize(domain, config)
|
2013-04-27 14:07:14 +02:00
|
|
|
@zone_file = config['zone_file']
|
|
|
|
@command = config['command']
|
2013-04-27 15:08:36 +02:00
|
|
|
@generator = Generator::Bind.new(domain, config)
|
2013-04-27 14:07:14 +02:00
|
|
|
end
|
2018-02-23 12:54:43 +01:00
|
|
|
|
2020-02-28 15:13:28 +01:00
|
|
|
# @param db [Dyndnsd::Database]
|
|
|
|
# @return [void]
|
2020-02-28 16:01:44 +01:00
|
|
|
def update(db)
|
2018-01-26 16:25:15 +01:00
|
|
|
Helper.span('updater_update') do |span|
|
|
|
|
span.set_tag('dyndnsd.updater.name', self.class.name.split('::').last)
|
|
|
|
|
|
|
|
# write zone file in bind syntax
|
2020-02-28 16:01:44 +01:00
|
|
|
File.open(@zone_file, 'w') { |f| f.write(@generator.generate(db)) }
|
2018-01-26 16:25:15 +01:00
|
|
|
# call user-defined command
|
|
|
|
pid = fork do
|
|
|
|
exec @command
|
|
|
|
end
|
|
|
|
|
|
|
|
# detach so children don't become zombies
|
|
|
|
Process.detach(pid)
|
2013-04-27 14:07:14 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|