1
0
mirror of https://github.com/cmur2/dyndnsd.git synced 2024-06-01 10:34:39 +02:00
dyndnsd/lib/dyndnsd/updater/command_with_bind_zone.rb

37 lines
1.0 KiB
Ruby
Raw Normal View History

2020-03-06 21:33:29 +01:00
# frozen_string_literal: true
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]
2020-07-18 14:45:56 +02:00
# @param updater_params [Hash{String => Object}]
def initialize(domain, updater_params)
@zone_file = updater_params['zone_file']
@command = updater_params['command']
@generator = Generator::Bind.new(domain, updater_params)
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]
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
2021-12-24 13:20:11 +01:00
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
2013-04-27 14:07:14 +02:00
end
end
end
end
end