settings: move mailFqdn/Domain into mailServer
This commit is contained in:
@@ -14,8 +14,10 @@ exports = module.exports = {
|
||||
getMailAuth,
|
||||
|
||||
getLocation,
|
||||
setLocation, // triggers the change task
|
||||
changeLocation, // does the actual changing
|
||||
startChangeLocation,
|
||||
changeLocation,
|
||||
|
||||
initLocation,
|
||||
|
||||
DEFAULT_MEMORY_LIMIT: 512 * 1024 * 1024,
|
||||
};
|
||||
@@ -194,8 +196,9 @@ async function restart() {
|
||||
if (process.env.BOX_ENV === 'test' && !process.env.TEST_CREATE_INFRA) return;
|
||||
|
||||
const mailConfig = await services.getServiceConfig('mail');
|
||||
debug(`restart: restarting mail container with mailFqdn:${settings.mailFqdn()} mailDomain:${settings.mailDomain()}`);
|
||||
await configureMail(settings.mailFqdn(), settings.mailDomain(), mailConfig);
|
||||
const { domain, fqdn } = await getLocation();
|
||||
debug(`restart: restarting mail container with mailFqdn:${fqdn} mailDomain:${domain}`);
|
||||
await configureMail(fqdn, domain, mailConfig);
|
||||
}
|
||||
|
||||
async function start(existingInfra) {
|
||||
@@ -220,10 +223,11 @@ async function restartIfActivated() {
|
||||
async function onDomainAdded(domain) {
|
||||
assert.strictEqual(typeof domain, 'string');
|
||||
|
||||
if (!settings.mailFqdn()) return; // mail domain is not set yet (when provisioning)
|
||||
const { fqdn } = await getLocation();
|
||||
if (!fqdn) return; // mail domain is not set yet (when provisioning)
|
||||
|
||||
debug(`onDomainAdded: configuring mail for added domain ${domain}`);
|
||||
await mail.upsertDnsRecords(domain, settings.mailFqdn());
|
||||
await mail.upsertDnsRecords(domain, fqdn);
|
||||
await restartIfActivated();
|
||||
}
|
||||
|
||||
@@ -247,18 +251,21 @@ async function checkCertificate() {
|
||||
}
|
||||
|
||||
async function getLocation() {
|
||||
const domain = settings.mailDomain(), fqdn = settings.mailFqdn();
|
||||
const domain = await settings.get(settings.MAIL_DOMAIN_KEY);
|
||||
const fqdn = await settings.get(settings.MAIL_FQDN_KEY);
|
||||
|
||||
if (!domain || !fqdn) return {};
|
||||
|
||||
const subdomain = fqdn.substr(0, fqdn.length - domain.length - 1);
|
||||
|
||||
return { domain, subdomain };
|
||||
return { domain, fqdn, subdomain };
|
||||
}
|
||||
|
||||
async function changeLocation(auditSource, progressCallback) {
|
||||
assert.strictEqual(typeof auditSource, 'object');
|
||||
assert.strictEqual(typeof progressCallback, 'function');
|
||||
|
||||
const fqdn = settings.mailFqdn(), domain = settings.mailDomain();
|
||||
const subdomain = fqdn.substr(0, fqdn.length - domain.length - 1);
|
||||
const { fqdn, domain, subdomain } = await getLocation();
|
||||
|
||||
let progress = 20;
|
||||
progressCallback({ percent: progress, message: `Setting up DNS of certs of mail server ${fqdn}` });
|
||||
@@ -280,7 +287,15 @@ async function changeLocation(auditSource, progressCallback) {
|
||||
await restartIfActivated();
|
||||
}
|
||||
|
||||
async function setLocation(subdomain, domain, auditSource) {
|
||||
async function initLocation(mailDomain, mailFqdn) {
|
||||
assert.strictEqual(typeof mailDomain, 'string');
|
||||
assert.strictEqual(typeof mailFqdn, 'string');
|
||||
|
||||
await settings.set(settings.MAIL_DOMAIN_KEY, mailDomain);
|
||||
await settings.set(settings.MAIL_FQDN_KEY, mailFqdn);
|
||||
}
|
||||
|
||||
async function startChangeLocation(subdomain, domain, auditSource) {
|
||||
assert.strictEqual(typeof subdomain, 'string');
|
||||
assert.strictEqual(typeof domain, 'string');
|
||||
assert.strictEqual(typeof auditSource, 'object');
|
||||
@@ -292,7 +307,7 @@ async function setLocation(subdomain, domain, auditSource) {
|
||||
|
||||
const fqdn = dns.fqdn(subdomain, domain);
|
||||
|
||||
await settings.setMailLocation(domain, fqdn);
|
||||
await initLocation(domain, fqdn);
|
||||
|
||||
const taskId = await tasks.add(tasks.TASK_CHANGE_MAIL_LOCATION, [ auditSource ]);
|
||||
tasks.startTask(taskId, {});
|
||||
|
||||
Reference in New Issue
Block a user