Add graceful shutdown button and improve shutdown status display

- Add refresh/shutdown button next to status indicator that gracefully
  stops the process without cleaning my-storage
- Create /api/shutdown endpoint that triggers graceful shutdown via SIGTERM
- Update status indicator to show "Gracefully Cleaning...." when system
  is shutting down (instead of "Searching for peers...")
- Include isShuttingDown flag in /api/status endpoint response
- Use built-in ConfirmationModal for shutdown confirmation with warning styling

The shutdown button appears in the top-right corner next to the status
indicator and uses the existing confirmation modal system for user
confirmation before initiating shutdown.
This commit is contained in:
Raven Scott
2025-12-26 22:03:23 -05:00
parent 1888289067
commit 3466d17eda
6 changed files with 188 additions and 6 deletions
+26 -1
View File
@@ -14,7 +14,8 @@ async function handleStatusRoutes(req, res) {
isMaster: state.isMaster,
isConnected: !!state.dnsPass,
peersCount: state.connectedPeers.size,
pid: process.pid
pid: process.pid,
isShuttingDown: state.isShuttingDown || false
};
trackRequest('/api/status', true);
res.writeHead(200, { 'Content-Type': 'application/json' });
@@ -28,6 +29,30 @@ async function handleStatusRoutes(req, res) {
return true;
}
if (method === 'POST' && urlPath === '/api/shutdown') {
try {
const { logInfo } = require('../../../infrastructure/logger');
// Send success response before shutting down
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({
success: true,
message: 'Graceful shutdown initiated. Process will exit after cleanup completes.'
}));
// Trigger graceful shutdown after sending response
setTimeout(() => {
logInfo('Admin', 'Initiating graceful shutdown (without cleaning storage)...');
process.emit('SIGTERM');
}, 500); // Small delay to ensure response is sent
} catch (err) {
const errorResponse = createErrorResponse(err, 500);
res.writeHead(errorResponse.statusCode, errorResponse.headers);
res.end(errorResponse.body);
}
return true;
}
if (method === 'GET' && urlPath === '/api/health') {
try {
const query = url.parse(req.url, true).query;