Backup MX for External MX affects Postfix transport.

This commit is contained in:
Michael Hierweck 2012-10-31 15:34:49 +01:00
parent b673617734
commit d3ceb761a8

View File

@ -59,7 +59,7 @@ public class DomainProcessorFactory implements EntityProcessorFactory {
mainProcessor.appendProcessor(queueName, createDNSServerSetupProcessor(domName, pacInetAddr), queueName + ".hostsharing.net"); mainProcessor.appendProcessor(queueName, createDNSServerSetupProcessor(domName, pacInetAddr), queueName + ".hostsharing.net");
} }
for (String queueName : config.getProperty("queues.mail").split(",")) { for (String queueName : config.getProperty("queues.mail").split(",")) {
mainProcessor.appendProcessor(queueName, createMailinSetupProcessor(em, domName, pac), queueName + ".hostsharing.net"); mainProcessor.appendProcessor(queueName, createMailinSetupProcessor(em, dom, pac), queueName + ".hostsharing.net");
} }
templateVars = new HashMap<String, String>(); templateVars = new HashMap<String, String>();
templateVars.put("PAC", pacName); templateVars.put("PAC", pacName);
@ -95,7 +95,7 @@ public class DomainProcessorFactory implements EntityProcessorFactory {
WaitingTasksProcessor processor = new WaitingTasksProcessor(createApacheVHostSetupProcessor(em, dom, templateVars)); WaitingTasksProcessor processor = new WaitingTasksProcessor(createApacheVHostSetupProcessor(em, dom, templateVars));
Config config = Config.getInstance(); Config config = Config.getInstance();
for (String queueName : config.getProperty("queues.mail").split(",")) { for (String queueName : config.getProperty("queues.mail").split(",")) {
processor.appendProcessor(queueName, createPostgreyConfiguration(em), queueName + ".hostsharing.net"); processor.appendProcessor(queueName, createMailinSetupProcessor(em, dom, pac), queueName + ".hostsharing.net");
} }
return processor; return processor;
} }
@ -111,8 +111,7 @@ public class DomainProcessorFactory implements EntityProcessorFactory {
mainProcessor.appendProcessor(queueName, createDNSServerRemoveProcessor(domName), queueName + ".hostsharing.net"); mainProcessor.appendProcessor(queueName, createDNSServerRemoveProcessor(domName), queueName + ".hostsharing.net");
} }
for (String queueName : config.getProperty("queues.mail").split(",")) { for (String queueName : config.getProperty("queues.mail").split(",")) {
mainProcessor.appendProcessor(queueName, createMailinDeleteProcessor(domName), queueName + ".hostsharing.net"); mainProcessor.appendProcessor(queueName, createMailinUnsetupProcessor(em, dom), queueName + ".hostsharing.net");
mainProcessor.appendProcessor(queueName, createPostgreyConfiguration(em), queueName + ".hostsharing.net");
} }
mainProcessor.appendProcessor(dom.getHiveName(), createApacheVHostDeleteProcessor(dom), "remove apache vhost"); mainProcessor.appendProcessor(dom.getHiveName(), createApacheVHostDeleteProcessor(dom), "remove apache vhost");
return mainProcessor; return mainProcessor;
@ -176,17 +175,30 @@ public class DomainProcessorFactory implements EntityProcessorFactory {
" && invoke-rc.d bind9 reload"); " && invoke-rc.d bind9 reload");
} }
private Processor createMailinSetupProcessor(EntityManager em, String domName, Pac pac) throws ProcessorException { private Processor createMailinSetupProcessor(EntityManager em, Domain dom, Pac pac) throws ProcessorException {
String inetAddr = pac.getCurINetAddr().getInetAddr(); String inetAddr = pac.getCurINetAddr().getInetAddr();
return new CompoundProcessor( CompoundProcessor cp = new CompoundProcessor(
createPostgreyConfiguration(em), createPostgreyConfiguration(em),
new ShellProcessor("postmap -r -i /etc/postfix-mailin/relaydomains", new ShellProcessor("postmap -r -i /etc/postfix-mailin/relaydomains",
domName + " anything\n" + dom.getName() + " anything\n" +
"." + domName + " anything\n"), "." + dom.getName() + " anything\n"));
new ShellProcessor("postmap -r -i /etc/postfix-mailin/transport", Query query = em.createQuery("SELECT d FROM Domains d WHERE d.domainoptions.name = :option AND d.name = :domname");
domName + " smtp:" + inetAddr + ":225\n" + query.setParameter("domname", dom.getName());
"." + domName + " smtp:" + inetAddr + ":225\n") query.setParameter("option", "backupmxforexternalmx");
); if (query.getResultList().isEmpty()) {
cp.appendProcessor(
new ShellProcessor("postmap -r -i /etc/postfix-mailin/transport",
dom.getName() + " smtp:" + inetAddr + ":225\n" +
"." + dom.getName() + " smtp:" + inetAddr + ":225\n")
);
} else {
cp.appendProcessor(
new ShellProcessor(
"postmap -d '" + dom.getName() + "' /etc/postfix-mailin/transport && " +
"postmap -d '." + dom.getName() + "' /etc/postfix-mailin/transport")
);
}
return cp;
} }
private Processor createPostgreyConfiguration(EntityManager em) throws ProcessorException { private Processor createPostgreyConfiguration(EntityManager em) throws ProcessorException {
@ -213,12 +225,14 @@ public class DomainProcessorFactory implements EntityProcessorFactory {
); );
} }
private Processor createMailinDeleteProcessor(String domName) { private Processor createMailinUnsetupProcessor(EntityManager em, Domain dom) throws ProcessorException {
Processor mailQueueProcessor = new ShellProcessor( Processor mailQueueProcessor = new CompoundProcessor(
"postmap -d '" + domName + "' /etc/postfix-mailin/relaydomains && " + createPostgreyConfiguration(em),
"postmap -d '" + domName + "' /etc/postfix-mailin/transport && " + new ShellProcessor(
"postmap -d '." + domName + "' /etc/postfix-mailin/relaydomains && " + "postmap -d '" + dom.getName() + "' /etc/postfix-mailin/relaydomains && " +
"postmap -d '." + domName + "' /etc/postfix-mailin/transport"); "postmap -d '" + dom.getName() + "' /etc/postfix-mailin/transport && " +
"postmap -d '." + dom.getName() + "' /etc/postfix-mailin/relaydomains && " +
"postmap -d '." + dom.getName() + "' /etc/postfix-mailin/transport"));
return mailQueueProcessor; return mailQueueProcessor;
} }