db shutdown on deploy
This commit is contained in:
parent
3663b31c64
commit
883d267328
|
|
@ -1,10 +1,5 @@
|
|||
work/
|
||||
/import
|
||||
ka-note/server/ka-note.db-wal
|
||||
ka-note/server/ka-note.db-wal
|
||||
ka-note/server/ka-note.db-wal
|
||||
ka-note/server/ka-note.db-shm
|
||||
ka-note/server/ka-note.db-shm
|
||||
ka-note/server/ka-note.db-wal
|
||||
ka-note/server/ka-note.db-shm
|
||||
ka-note/server/ka-note.db-wal
|
||||
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
1.1.85
|
||||
1.1.87
|
||||
|
|
@ -106,6 +106,22 @@ az webapp config appsettings set --name $APP --resource-group $RG --settings `
|
|||
AZURE_CLIENT_ID=$env:AZURE_CLIENT_ID `
|
||||
AZURE_TENANT_ID=$env:AZURE_TENANT_ID | Out-Null
|
||||
|
||||
Write-Host "=== Graceful DB shutdown ===" -ForegroundColor Cyan
|
||||
$AppUrl = "https://$APP.azurewebsites.net"
|
||||
if ($env:KA_NOTE_DEPLOY_API_KEY) {
|
||||
try {
|
||||
$shutdownResult = Invoke-RestMethod -Uri "$AppUrl/api/admin/shutdown" -Method POST `
|
||||
-Headers @{ Authorization = "Bearer $env:KA_NOTE_DEPLOY_API_KEY" } `
|
||||
-UseBasicParsing -TimeoutSec 10
|
||||
Write-Host " Shutdown response: $($shutdownResult.message)" -ForegroundColor DarkGray
|
||||
Start-Sleep -Seconds 3
|
||||
} catch {
|
||||
Write-Host " Shutdown call failed (continuing anyway): $_" -ForegroundColor Yellow
|
||||
}
|
||||
} else {
|
||||
Write-Host " KA_NOTE_DEPLOY_API_KEY not set, skipping graceful shutdown" -ForegroundColor Yellow
|
||||
}
|
||||
|
||||
Write-Host "=== Restart App Service ===" -ForegroundColor Cyan
|
||||
az webapp restart --name $APP --resource-group $RG
|
||||
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
|
|
@ -3,6 +3,7 @@ import { vacuumPurged } from '../lib/sync-service.js';
|
|||
import { checkIntegrity } from '../lib/backup-service.js';
|
||||
import { handle } from '../lib/route-utils.js';
|
||||
import type { AuthEnv } from '../middleware/auth.js';
|
||||
import { sqlite } from '../db/connection.js';
|
||||
|
||||
const admin = new Hono<AuthEnv>();
|
||||
|
||||
|
|
@ -18,4 +19,21 @@ admin.get('/integrity', handle('admin/integrity', async (c) => {
|
|||
return c.json(result, result.ok ? 200 : 500);
|
||||
}));
|
||||
|
||||
// Graceful shutdown: checkpoint WAL, close DB, exit.
|
||||
// Call from deploy pipeline before restarting the container.
|
||||
admin.post('/shutdown', handle('admin/shutdown', async (c) => {
|
||||
console.log('[admin] shutdown requested via API');
|
||||
setTimeout(() => {
|
||||
try {
|
||||
sqlite.pragma('wal_checkpoint(TRUNCATE)');
|
||||
sqlite.close();
|
||||
console.log('[admin] database closed cleanly, exiting');
|
||||
} catch (e) {
|
||||
console.error('[admin] error during shutdown:', e);
|
||||
}
|
||||
process.exit(0);
|
||||
}, 100);
|
||||
return c.json({ ok: true, message: 'shutting down' });
|
||||
}));
|
||||
|
||||
export default admin;
|
||||
|
|
|
|||
Loading…
Reference in New Issue