forked from snxraven/p2ns
Updates
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user