Freitag, 16. Mai 2014

Using AutoDNS as PowerDNS Slave Server

If you use AutoDNS as Slave Server you might automatically create and delete zones.

Notifies doesn't work because the Slave Servers did not know your domain. One way to do this is using a MySQL trigger with a simple script.


For example:

CREATE TABLE `domain_events` (
  `id` int(11) NOT NULL auto_increment,
  `name` varchar(255) NOT NULL default '',
  `action` varchar(255) NOT NULL default '',
  `status` varchar(255) NOT NULL default '',
  `error_code` varchar(255) NOT NULL default '',
  `created` datetime,
  `updated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY  (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=latin1;

DELIMITER $$

CREATE TRIGGER new_domain_created
AFTER INSERT ON `domains` for each row
begin
INSERT INTO domain_events (name,action,status,created)
VALUES (new.name, 'create','pending',now());
END$$

CREATE TRIGGER new_domain_deleted
AFTER DELETE ON `domains` for each row
begin
INSERT INTO domain_events (name,action,status,created)
VALUES (old.name, 'delete','pending',now());
END$$

DELIMITER ; 


On every INSERT/DELETE on the domains-table a corresponding row in the domain-events table is inserted, which can be processed by a simple script.

This script (powerdns-master-sync) can be found here:
https://bitbucket.org/mschrieck/autodns-tools