mailserver: a056bcfd broke mail server restart

after proxying, we never restarted the mail server

also add note that restart has to reconfigure
This commit is contained in:
Girish Ramakrishnan
2024-04-18 13:14:59 +02:00
parent 18ec929501
commit 1afa2e87ec
3 changed files with 23 additions and 12 deletions
+2
View File
@@ -203,6 +203,8 @@ async function restart() {
const mailConfig = await services.getServiceConfig('mail');
const { domain, fqdn } = await getLocation();
debug(`restart: restarting mail container with mailFqdn:${fqdn} mailDomain:${domain}`);
// NOTE: the email container has to be re-created. this is because some of the settings like solr config rely on starting with a clean /run state
await configureMail(fqdn, domain, mailConfig);
}
+18 -9
View File
@@ -2,7 +2,7 @@
exports = module.exports = {
proxy,
restart,
proxyAndRestart,
queueProxy,
setLocation,
@@ -21,12 +21,6 @@ const assert = require('assert'),
services = require('../services.js'),
url = require('url');
// because of how the proxy middleware works, the http response is already sent by the time this function is called
async function restart(req, res, next) {
await safe(mailServer.restart(), { debug });
next();
}
async function proxyToMailContainer(port, pathname, req, res, next) {
const parsedUrl = url.parse(req.url, true /* parseQueryString */);
@@ -46,7 +40,7 @@ async function proxyToMailContainer(port, pathname, req, res, next) {
req.clearTimeout(); // TODO: add timeout to mail server proxy logic instead of this
mailserverProxy(req, res, function (error) {
if (!error) return; // response was already sent by proxy, do not proceed to connect-lastmile
if (!error) return next(); // note: response was already sent by proxy by this point
if (error.code === 'ECONNREFUSED') return next(new HttpError(424, 'Unable to connect to mail server'));
if (error.code === 'ECONNRESET') return next(new HttpError(424, 'Unable to query mail server'));
@@ -58,7 +52,22 @@ async function proxyToMailContainer(port, pathname, req, res, next) {
async function proxy(req, res, next) {
const pathname = req.path.split('/').pop();
proxyToMailContainer(3000, pathname, req, res, next);
proxyToMailContainer(3000, pathname, req, res, function (httpError) {
if (httpError) return next(httpError);
// for success, the proxy already sent the response. do not proceed to connect-lastmile which will result in double headers
});
}
async function proxyAndRestart(req, res, next) {
const pathname = req.path.split('/').pop();
proxyToMailContainer(3000, pathname, req, res, async function (httpError) {
if (httpError) return next(httpError);
// for success, the proxy already sent the response. do not proceed to connect-lastmile which will result in double headers
await safe(mailServer.restart(), { debug });
});
}
async function queueProxy(req, res, next) {
+3 -3
View File
@@ -344,11 +344,11 @@ async function initializeExpressSync() {
router.get ('/api/v1/mailserver/dnsbl_config', token, authorizeAdmin, routes.mailserver.proxy);
router.post('/api/v1/mailserver/dnsbl_config', token, authorizeAdmin, routes.mailserver.proxy);
router.get ('/api/v1/mailserver/solr_config', token, authorizeAdmin, routes.mailserver.proxy);
router.post('/api/v1/mailserver/solr_config', token, authorizeAdmin, routes.mailserver.proxy, routes.mailserver.restart);
router.post('/api/v1/mailserver/solr_config', token, authorizeAdmin, routes.mailserver.proxyAndRestart);
router.get ('/api/v1/mailserver/mailbox_sharing', token, authorizeAdmin, routes.mailserver.proxy);
router.post('/api/v1/mailserver/mailbox_sharing', token, authorizeAdmin, routes.mailserver.proxy, routes.mailserver.restart);
router.post('/api/v1/mailserver/mailbox_sharing', token, authorizeAdmin, routes.mailserver.proxyAndRestart);
router.get ('/api/v1/mailserver/virtual_all_mail', token, authorizeAdmin, routes.mailserver.proxy);
router.post('/api/v1/mailserver/virtual_all_mail', token, authorizeAdmin, routes.mailserver.proxy, routes.mailserver.restart);
router.post('/api/v1/mailserver/virtual_all_mail', token, authorizeAdmin, routes.mailserver.proxyAndRestart);
router.get ('/api/v1/mailserver/usage', token, authorizeMailManager, routes.mailserver.proxy);
router.use ('/api/v1/mailserver/queue', token, authorizeAdmin, routes.mailserver.queueProxy);