reverseproxy: fix issue where renewed certs are not written to disk

This commit is contained in:
Girish Ramakrishnan
2023-01-31 17:58:28 +01:00
parent 2759b6268e
commit ce9e78d23b

View File

@@ -562,19 +562,6 @@ async function unconfigureApp(app) {
await reload();
}
async function ensureCertificates(locations, auditSource, progressCallback) {
assert(Array.isArray(locations));
assert.strictEqual(typeof auditSource, 'object');
assert.strictEqual(typeof progressCallback, 'function');
let percent = 1;
for (const location of locations) {
percent += Math.round(100/locations.length);
progressCallback({ percent, message: `Ensuring certs of ${location.fqdn}` });
await ensureCertificate(location, auditSource);
}
}
async function cleanupCerts(locations, auditSource, progressCallback) {
assert(Array.isArray(locations));
assert.strictEqual(typeof auditSource, 'object');
@@ -634,7 +621,12 @@ async function checkCerts(options, auditSource, progressCallback) {
locations = locations.concat(getAppLocationsSync(app));
}
await ensureCertificates(locations, auditSource, progressCallback);
let percent = 1;
for (const location of locations) {
percent += Math.round(100/locations.length);
progressCallback({ percent, message: `Ensuring certs of ${location.fqdn}` });
await ensureCertificate(location, auditSource);
}
if (options.rebuild || fs.existsSync(paths.REVERSE_PROXY_REBUILD_FILE)) {
progressCallback( { message: 'Rebuilding app configs' });
@@ -645,6 +637,12 @@ async function checkCerts(options, auditSource, progressCallback) {
await notifyCertChange(); // this allows user to "rebuild" using UI just in case we crashed and went out of sync
safe.fs.unlinkSync(paths.REVERSE_PROXY_REBUILD_FILE);
} else {
// sync all locations and not just the ones that changed. this helps with 0 length certs when disk is full and also
// if renewal task crashed midway.
for (const location of locations) {
await writeCertificate(location);
}
await reload();
await notifyCertChange(); // propagate any cert changes to services
}