This commit is contained in:
Raven Scott
2026-05-27 22:43:41 -04:00
parent 8b6789805c
commit 276eb4e015
4 changed files with 154 additions and 7 deletions
@@ -6,6 +6,7 @@ const { logError, logWarn, logDebug } = require('../../../infrastructure/logger'
const { getAvailableIPsForSubnet } = require('../../../networking/virtual_interfaces');
const { settingsMetadata, restartRequiredSettings, liveReloadableSettings, envWhitelist, applyLiveSettings } = require('../settings');
const { broadcast } = require('../websocket');
const { resetPluginStorage } = require('../../../../scripts/reset-plugin-storage');
async function handleSettingsRoutes(req, res) {
const urlPath = req.urlPath || new URL(req.url, `https://${req.headers.host}`).pathname;
@@ -548,6 +549,21 @@ async function handleSettingsRoutes(req, res) {
}
}
// Clean plugin HyperDB generated storage (same behavior as --clean)
let pluginResetSummary = null;
try {
pluginResetSummary = await resetPluginStorage({
logger: (level, message) => {
if (level === 'WARN') logWarn('Admin', message);
else if (level === 'ERROR') logError('Admin', message);
else logInfo('Admin', message);
}
});
logInfo('Admin', `Reset plugin spec/db directories for ${pluginResetSummary.resetCandidates} plugin(s)`);
} catch (pluginErr) {
logWarn('Admin', `Failed to reset plugin spec/db directories: ${pluginErr.message}`);
}
// Reset state variables that depend on the storage
state.dnsPass = null;
state.consecutiveInviteFailures = 0; // Reset failure counter
@@ -560,8 +576,9 @@ async function handleSettingsRoutes(req, res) {
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({
success: true,
message: 'DNS Pass storage cleaned. Shutting down for reinitialization...',
message: 'DNS Pass and plugin storage cleaned. Shutting down for reinitialization...',
storageDir: storageDir,
pluginResetSummary,
shutdownInitiated: true,
restartInstructions: 'Process will shut down. Restart manually with: sudo node p2ns.js' + (state.isMaster ? ' --master' : '')
}));
@@ -570,7 +587,7 @@ async function handleSettingsRoutes(req, res) {
// Add a longer delay to ensure storage cleanup is complete and state is reset
setTimeout(() => {
logInfo('Admin', 'Initiating graceful shutdown after DNS storage cleanup...');
logInfo('Admin', '🔄 SYSTEM IS SHUTTING DOWN - Storage has been cleaned and will reinitialize on restart');
logInfo('Admin', '🔄 SYSTEM IS SHUTTING DOWN - DNS + plugin storage has been cleaned and will reinitialize on restart');
process.emit('SIGTERM');
}, 3000); // Give more time for response to be sent and cleanup to complete
} catch (err) {
@@ -682,7 +682,7 @@ async function cleanDnsPassStorage() {
console.warn('Could not fetch status for confirmation dialog:', err);
}
let warningMessage = '⚠️ WARNING: This will delete all DNS Pass data and immediately shut down the system for reinitialization.\n\n';
let warningMessage = '⚠️ WARNING: This will delete DNS Pass data plus plugin spec/db cache data and immediately shut down the system for reinitialization.\n\n';
if (statusInfo.peersCount > 0) {
warningMessage += `${statusInfo.peersCount} peers are currently connected - they will be disconnected\n`;
@@ -715,7 +715,7 @@ async function cleanDnsPassStorage() {
const result = await response.json();
if (window.showNotification) {
window.showNotification('🧹 DNS Pass storage cleaned. System shutting down for reinitialization...', 'success');
window.showNotification('🧹 DNS + plugin storage cleaned. System shutting down for reinitialization...', 'success');
}
// Clear any existing invite diagnostics results since the state has changed
@@ -734,7 +734,7 @@ async function cleanDnsPassStorage() {
// Restore button
if (buttonEl) {
buttonEl.disabled = false;
buttonEl.innerHTML = '🗑️ Clean DNS Storage';
buttonEl.innerHTML = '🗑️ Clean & Restart';
}
}
}
@@ -782,7 +782,7 @@ async function showRestartRequiredMessage() {
<div class="ml-3 flex-1">
<h4 class="text-base font-semibold text-orange-200 mb-1">System Restart Required</h4>
<p class="text-orange-100 text-sm mb-2">
DNS Pass storage cleaned. Process must restart for reinitialization.
DNS + plugin storage cleaned. Process must restart for reinitialization.
</p>
<div class="bg-orange-800 rounded p-2 mb-2">
<p class="text-xs text-orange-200 font-mono">
@@ -820,7 +820,7 @@ function showShutdownMessage(result) {
<div class="ml-3 flex-1">
<h4 class="text-base font-semibold text-red-200 mb-1">System Shutting Down</h4>
<p class="text-red-100 text-sm mb-2">
DNS Pass storage cleaned. Process shutting down for reinitialization.
DNS + plugin storage cleaned. Process shutting down for reinitialization.
</p>
<div class="bg-red-800 rounded p-2 mb-2">
<p class="text-xs text-red-200 font-mono">