reverseproxy: rebuild only when needed
re-creating nginx configs is only needed in 3 cases: * provider changes. we create a rebuild file for this * nginx config is somehow corrupt by external changes. user can click ui button on startup, dashboard also always creates the nginx configs. so it's always up to provide the button
This commit is contained in:
@@ -26,6 +26,8 @@ exports = module.exports = {
|
||||
|
||||
removeAppConfigs,
|
||||
restoreFallbackCertificates,
|
||||
|
||||
handleCertificateProviderChanged
|
||||
};
|
||||
|
||||
const acme2 = require('./acme2.js'),
|
||||
@@ -596,7 +598,8 @@ async function cleanupCerts(locations, auditSource, progressCallback) {
|
||||
debug('cleanupCerts: done');
|
||||
}
|
||||
|
||||
async function checkCerts(auditSource, progressCallback) {
|
||||
async function checkCerts(options, auditSource, progressCallback) {
|
||||
assert.strictEqual(typeof options, 'object');
|
||||
assert.strictEqual(typeof auditSource, 'object');
|
||||
assert.strictEqual(typeof progressCallback, 'function');
|
||||
|
||||
@@ -611,13 +614,18 @@ async function checkCerts(auditSource, progressCallback) {
|
||||
|
||||
await ensureCertificates(locations, auditSource, progressCallback);
|
||||
|
||||
progressCallback( { message: 'Rebuilding app configs' });
|
||||
for (const app of allApps) {
|
||||
await writeAppConfigs(app);
|
||||
if (options.rebuild || fs.existsSync(paths.REVERSE_PROXY_REBUILD_FILE)) {
|
||||
progressCallback( { message: 'Rebuilding app configs' });
|
||||
for (const app of allApps) {
|
||||
await writeAppConfigs(app);
|
||||
}
|
||||
await writeDashboardConfig(settings.dashboardDomain());
|
||||
safe.fs.unlinkSync(paths.REVERSE_PROXY_REBUILD_FILE);
|
||||
}
|
||||
await writeDashboardConfig(settings.dashboardDomain());
|
||||
|
||||
// let other parts of code know about any cert changes. apptask can trigger a renewal, provider can change, for example
|
||||
await mail.handleCertChanged();
|
||||
await shell.promises.sudo('rebuildConfigs', [ RESTART_SERVICE_CMD, 'box' ], {});
|
||||
await shell.promises.sudo('rebuildConfigs', [ RESTART_SERVICE_CMD, 'box' ], {}); // directory server
|
||||
for (const app of allApps) {
|
||||
if (app.manifest.addons?.tls) await setupTlsAddon(app);
|
||||
}
|
||||
@@ -679,3 +687,9 @@ async function writeDefaultConfig(options) {
|
||||
|
||||
await reload();
|
||||
}
|
||||
|
||||
async function handleCertificateProviderChanged(domain) {
|
||||
assert.strictEqual(typeof domain, 'string');
|
||||
|
||||
safe.fs.appendFileSync(paths.REVERSE_PROXY_REBUILD_FILE, `${domain}\n`, 'utf8');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user