#!/bin/bash # MongoDB Migration Web Interface # Serves migration progress at ROOT_URL/migration-progress using Node.js # Source settings source $SNAP/bin/wekan-read-settings # Set up Node.js environment like wekan-control export NODE_PATH=$SNAP/bin # Configuration MIGRATION_STATUS="${SNAP_COMMON}/mongodb-migration-status.json" MIGRATION_LOG="${SNAP_COMMON}/mongodb-migration-log.txt" MIGRATION_PROGRESS="${SNAP_COMMON}/mongodb-migration-progress.html" # Use same PORT as wekan-control, but add 1 to avoid conflicts MIGRATION_PORT=$((PORT + 1)) # Create Node.js HTTP server script create_node_server() { cat > "${SNAP_COMMON}/migration-web-server.js" << 'EOF' const http = require('http'); const fs = require('fs'); const path = require('path'); const PORT = process.env.MIGRATION_PORT || 8081; const SNAP_COMMON = process.env.SNAP_COMMON; const ROOT_URL = process.env.ROOT_URL || 'http://127.0.0.1'; const MIGRATION_STATUS = path.join(SNAP_COMMON, 'mongodb-migration-status.json'); const MIGRATION_LOG = path.join(SNAP_COMMON, 'mongodb-migration-log.txt'); function readFileSafe(filePath) { try { return fs.readFileSync(filePath, 'utf8'); } catch (error) { return null; } } function getMigrationStatus() { const statusContent = readFileSafe(MIGRATION_STATUS); if (!statusContent) { return null; } try { return JSON.parse(statusContent); } catch (error) { return null; } } function getMigrationLog() { const logContent = readFileSafe(MIGRATION_LOG); if (!logContent) { return 'No log available'; } const lines = logContent.split('\n'); return lines.slice(-20).join('\n'); } function generateHTML(status) { if (!status) { return `
No migration in progress.
This page will refresh automatically every 5 seconds.
Migrating from MongoDB 3 to MongoDB 7
Status: ${statusValue}
Progress: ${step} of ${total_steps} steps
Current Step: ${description}
Last Updated: ${timestamp}
${logContent}
This page will refresh automatically every 5 seconds.
Migration URL: ${ROOT_URL}/migration-progress