Fix installs stuck as "Uninstalling"; remove a failed install's record
An uninstall whose export failed was cancelled, but its install stayed "uninstalling" for good. It now goes back to live (or waiting for the proxy), like a failed or hand-cancelled uninstall. Uninstall is refused for a failed install (nothing of it is on the server, so the export always failed) and for one still installing. A failed install's page offers "Remove the record" instead, which also clears records already stuck from before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -191,7 +191,7 @@ async function afterJob(job, { exportKey }, now) {
|
||||
await makeJob(prisma, { serverId: deployment.serverId, type: 'purge', args: { church: deployment.shortName }, deploymentId: deployment.id, notBefore: new Date(now.getTime() + EXPORT_DAYS * DAY), windowMinutes: 3 * 24 * 60 });
|
||||
await emailJoshua(`Uninstalled: ${deployment.shortName}`, `${jobReportText(job)}\n\nRemove the FastPanel site ${deployment.domain} (ports ${deployment.webPort}, ${deployment.apiPort}).\nThe final backup is kept on the server for ${EXPORT_DAYS} days, then purged.`);
|
||||
} else {
|
||||
await prisma.deployment.update({ where: { id: deployment.id }, data: { status: 'live' } });
|
||||
await prisma.deployment.update({ where: { id: deployment.id }, data: { status: statusBeforeUninstall(deployment) } });
|
||||
await emailJoshua(`Uninstall failed: ${deployment.shortName}`, jobReportText(job));
|
||||
}
|
||||
break;
|
||||
@@ -223,6 +223,11 @@ async function advanceBatch(job, now) {
|
||||
for (const j of rest) {
|
||||
await prisma.job.update({ where: { id: j.id }, data: { status: 'cancelled', message: `Not run: ${job.id} before it in the same batch didn't succeed.`, finishedAt: now } });
|
||||
if (j.noticeId) await endNotice(j.noticeId, now);
|
||||
// An uninstall that won't run (its export failed): the install is still there. Before 2.3.2 it
|
||||
// stayed "uninstalling" for good.
|
||||
if (j.deployment && j.type === 'uninstall') {
|
||||
await prisma.deployment.update({ where: { id: j.deployment.id }, data: { status: statusBeforeUninstall(j.deployment) } });
|
||||
}
|
||||
if (j.deployment && j.scheduled && j.type === 'deploy') {
|
||||
await emailSiteAdmin(j.deployment, `${PRODUCT_NAMES[j.deployment.product]} update postponed`, `The planned update of ${PRODUCT_NAMES[j.deployment.product]} at ${j.deployment.domain} has been postponed. Your site keeps running as it is; we'll let you know the new time.`);
|
||||
}
|
||||
@@ -545,10 +550,40 @@ async function cancelJob(jobId, admin, now = new Date()) {
|
||||
await emailSiteAdmin(job.deployment, `${PRODUCT_NAMES[job.deployment.product]} update cancelled`, `The update of ${PRODUCT_NAMES[job.deployment.product]} at ${job.deployment.domain} planned for ${sast(job.notBefore)} is cancelled. Your site keeps running as it is.`);
|
||||
}
|
||||
if (job.batchId) await advanceBatch(updated, now);
|
||||
if (job.type === 'uninstall' && job.deploymentId) await prisma.deployment.update({ where: { id: job.deploymentId }, data: { status: 'live' } });
|
||||
if (job.type === 'uninstall' && job.deployment) await prisma.deployment.update({ where: { id: job.deployment.id }, data: { status: statusBeforeUninstall(job.deployment) } });
|
||||
return updated;
|
||||
}
|
||||
|
||||
/** What an install goes back to when its uninstall doesn't happen: it's still on the server. */
|
||||
function statusBeforeUninstall(d) {
|
||||
return d.liveAt || d.installId ? 'live' : 'waiting_for_proxy';
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether an install never made it onto the server, so its record can simply be removed: its
|
||||
* install failed (the server already removed what it made) and nothing is planned for it. Also
|
||||
* one that was planned for uninstall after its install failed, from before 2.3.2 (stuck as
|
||||
* "uninstalling" when the export found nothing to export).
|
||||
*/
|
||||
async function neverInstalled(d) {
|
||||
if (!['failed', 'uninstalling'].includes(d.status) || d.liveAt || d.installId) return false;
|
||||
const open = await prisma.job.count({ where: { deploymentId: d.id, status: { in: ['scheduled', 'queued', 'delivered'] } } });
|
||||
if (open) return false;
|
||||
if (d.status === 'failed') return true;
|
||||
const install = await prisma.job.findFirst({ where: { deploymentId: d.id, type: { in: ['install', 'add-product'] } }, orderBy: { createdAt: 'desc' } });
|
||||
return !!install && install.status !== 'succeeded';
|
||||
}
|
||||
|
||||
/** Remove a failed install's record: there's nothing on the server to export or uninstall. */
|
||||
async function removeFailedInstall(deploymentId) {
|
||||
const d = await prisma.deployment.findUnique({ where: { id: deploymentId } });
|
||||
if (!d) throw fail(404, 'NOT_FOUND', 'Not found.');
|
||||
if (!(await neverInstalled(d))) throw fail(409, 'NOT_FAILED', 'Only a failed install\'s record can be removed; a working install is uninstalled.');
|
||||
await prisma.port.deleteMany({ where: { port: { in: [d.webPort, d.apiPort] }, deploymentId: d.id, releasedAt: null } });
|
||||
await prisma.deployment.delete({ where: { id: d.id } });
|
||||
return d;
|
||||
}
|
||||
|
||||
/**
|
||||
* Uninstall (§9): 2FA, typing the short name, at least 4 hours ahead. A batch of two: the export
|
||||
* (encrypted, emailed to the site admin), then the uninstall, which only runs if the export worked.
|
||||
@@ -559,6 +594,8 @@ async function scheduleUninstall({ deploymentId, at, totp, confirm }, admin, now
|
||||
if (!d) throw fail(404, 'NOT_FOUND', 'Not found.');
|
||||
if (confirm !== d.shortName) throw fail(400, 'CONFIRM', `Type ${d.shortName} to confirm.`);
|
||||
if (['removed', 'uninstalling'].includes(d.status)) throw fail(409, 'ALREADY', `It's already ${d.status}.`);
|
||||
if (d.status === 'failed') throw fail(409, 'NOT_INSTALLED', 'Its install failed, so nothing of it is on the server: remove the record instead.');
|
||||
if (d.status === 'installing') throw fail(409, 'BUSY', 'Wait until the install has finished.');
|
||||
const when = new Date(at || now.getTime() + 7 * DAY);
|
||||
if (when - now < SCHEDULE_MIN_HOURS * HOUR) throw fail(400, 'TOO_SOON', `An uninstall is planned at least ${SCHEDULE_MIN_HOURS} hours ahead.`);
|
||||
const exportId = servers.newId('exp');
|
||||
@@ -639,6 +676,6 @@ async function runNow({ serverId, type, args, deploymentId = null }, admin, now
|
||||
module.exports = {
|
||||
WINDOW_MIN, SCHEDULE_MIN_HOURS, EMERGENCY_MIN_MINUTES,
|
||||
makeJob, signedJob, jobConfig, poll, receiveReport, finish, tick, advanceBatch,
|
||||
newInstall, proxyDone, scheduleUpdate, cancelJob, scheduleUninstall, receiveExport, linkDeployment, scheduleAdopt, queueCentralCheck, runNow,
|
||||
newInstall, proxyDone, scheduleUpdate, cancelJob, scheduleUninstall, neverInstalled, removeFailedInstall, receiveExport, linkDeployment, scheduleAdopt, queueCentralCheck, runNow,
|
||||
fastPanelText, jobReportText, scheduleWarnings, requireTotp, agentOnline, siteAdminEmail,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user