import "./loadEnv.js"; // Before anything opens the database: puts a restore that was staged from Settings → Data → Backup in place. import "./db/applyRestore.js"; import { env, warnIfAuthNotConfigured, checkSessionSecret } from "./env.js"; import { createApp } from "./app.js"; import { runMigrations } from "./db/migrate.js"; import { encryptStoredSettingsSecrets } from "./services/settingsStore.js"; import { initSecretExpiryScheduler } from "./services/secretExpiryScheduler.js"; import { initTailscaleKeyExpiryScheduler } from "./services/tailscaleKeyExpiryScheduler.js"; import { initLogRetentionScheduler } from "./services/logRetentionScheduler.js"; import { initDockerUpdateScheduler } from "./services/dockerUpdateScheduler.js"; import { initProxmoxBackupScheduler } from "./services/proxmoxBackupScheduler.js"; import { initPbsVerificationScheduler } from "./services/pbsVerificationScheduler.js"; import { initQuietHoursScheduler } from "./services/quietHoursScheduler.js"; import { initWeeklyDigestScheduler } from "./services/weeklyDigestScheduler.js"; import { initMonthlyReportScheduler } from "./services/monthlyReportScheduler.js"; import { initMaintenanceEvents } from "./services/maintenanceEvents.js"; import { initHealthScheduler } from "./services/healthScheduler.js"; import { initAlertTicketScheduler } from "./services/alertTicketScheduler.js"; import { initKumaMaintenanceScheduler } from "./services/kumaMaintenanceScheduler.js"; import { initMaintenanceScheduleScheduler } from "./services/maintenanceScheduleScheduler.js"; import { initUpdateRuns } from "./services/updateRuns.js"; import { initEscalation } from "./services/escalation.js"; import { initEndpointMonitor } from "./services/endpointMonitor.js"; import { initPatchPlans } from "./services/patchPlans.js"; import { initFlapMonitor } from "./services/flapMonitor.js"; import { initUnifiSync } from "./services/unifiSync.js"; import { initHomeAssistantSync } from "./services/homeAssistantSync.js"; import { backfillMetricRollups } from "./services/serverMetrics.js"; import { backfillEndpointHourly } from "./services/endpointChecks.js"; import { initSelfBackupScheduler } from "./services/selfBackupScheduler.js"; import { initIncidentRecorder } from "./services/incidents.js"; import { getAlerts } from "./services/alerts.js"; { // Sessions are signed with this secret. Without one, the app would sign them with a value that's in the source code. const secret = checkSessionSecret(process.env.SESSION_SECRET, env.nodeEnv); if (secret.fatal) { console.error(secret.fatal); process.exit(1); } if (secret.warning) console.warn(secret.warning); } warnIfAuthNotConfigured(); if (env.environmentWarning) console.warn(env.environmentWarning); if (env.environment) console.log(`Environment: ${env.environment.name || "(unnamed)"} (${env.environment.color})`); await runMigrations(); { const converted = await encryptStoredSettingsSecrets(); if (converted > 0) console.log(`Encrypted the stored credentials of ${converted} notification channel${converted === 1 ? "" : "s"}.`); } await initSecretExpiryScheduler(); await initTailscaleKeyExpiryScheduler(); await initLogRetentionScheduler(); await initDockerUpdateScheduler(); await initProxmoxBackupScheduler(); await initPbsVerificationScheduler(); await initQuietHoursScheduler(); await initWeeklyDigestScheduler(); await initMonthlyReportScheduler(); initMaintenanceEvents(); await initHealthScheduler(); await initAlertTicketScheduler(); await initKumaMaintenanceScheduler(); await initMaintenanceScheduleScheduler(); initUpdateRuns(); await initSelfBackupScheduler(); initIncidentRecorder(() => getAlerts(false)); initEscalation(); initEndpointMonitor(); initPatchPlans(); initFlapMonitor(); initUnifiSync(); initHomeAssistantSync(); // The hourly and daily figures are built from what is already kept, once, the first time after they were added (in the background: nothing waits for it). void Promise.all([backfillMetricRollups(), backfillEndpointHourly()]).catch((err) => console.error("[history] couldn't build the hourly and daily figures:", err)); createApp().listen(env.port, () => { console.log(`homelab-manager listening on port ${env.port}`); });