- Implemented gitzone services command for managing MongoDB and MinIO containers - Added smart port assignment (20000-30000 range) to avoid conflicts - Project-specific container names for complete isolation - Data persistence in .nogit/ directories - MongoDB Compass connection string generation with network IP detection - Auto-configuration via .nogit/env.json with secure defaults - Commands: start, stop, restart, status, config, compass, logs, remove, clean - Interactive confirmations for destructive operations - Comprehensive documentation and Task Venture Capital GmbH legal update
218 lines
6.9 KiB
TypeScript
218 lines
6.9 KiB
TypeScript
import * as plugins from './mod.plugins.js';
|
|
import * as helpers from './helpers.js';
|
|
import { ServiceManager } from './classes.servicemanager.js';
|
|
|
|
export const run = async (argvArg: any) => {
|
|
const serviceManager = new ServiceManager();
|
|
await serviceManager.init();
|
|
|
|
const command = argvArg._[1] || 'help';
|
|
const service = argvArg._[2] || 'all';
|
|
|
|
switch (command) {
|
|
case 'start':
|
|
await handleStart(serviceManager, service);
|
|
break;
|
|
|
|
case 'stop':
|
|
await handleStop(serviceManager, service);
|
|
break;
|
|
|
|
case 'restart':
|
|
await handleRestart(serviceManager, service);
|
|
break;
|
|
|
|
case 'status':
|
|
await serviceManager.showStatus();
|
|
break;
|
|
|
|
case 'config':
|
|
await serviceManager.showConfig();
|
|
break;
|
|
|
|
case 'compass':
|
|
await serviceManager.showCompassConnection();
|
|
break;
|
|
|
|
case 'logs':
|
|
const lines = parseInt(argvArg._[3]) || 20;
|
|
await serviceManager.showLogs(service, lines);
|
|
break;
|
|
|
|
case 'remove':
|
|
await handleRemove(serviceManager);
|
|
break;
|
|
|
|
case 'clean':
|
|
await handleClean(serviceManager);
|
|
break;
|
|
|
|
case 'help':
|
|
default:
|
|
showHelp();
|
|
break;
|
|
}
|
|
};
|
|
|
|
async function handleStart(serviceManager: ServiceManager, service: string) {
|
|
helpers.printHeader('Starting Services');
|
|
|
|
switch (service) {
|
|
case 'mongo':
|
|
case 'mongodb':
|
|
await serviceManager.startMongoDB();
|
|
break;
|
|
|
|
case 'minio':
|
|
case 's3':
|
|
await serviceManager.startMinIO();
|
|
break;
|
|
|
|
case 'all':
|
|
case '':
|
|
await serviceManager.startMongoDB();
|
|
console.log();
|
|
await serviceManager.startMinIO();
|
|
break;
|
|
|
|
default:
|
|
helpers.printMessage(`Unknown service: ${service}`, 'red');
|
|
helpers.printMessage('Use: mongo, s3, or all', 'yellow');
|
|
break;
|
|
}
|
|
}
|
|
|
|
async function handleStop(serviceManager: ServiceManager, service: string) {
|
|
helpers.printHeader('Stopping Services');
|
|
|
|
switch (service) {
|
|
case 'mongo':
|
|
case 'mongodb':
|
|
await serviceManager.stopMongoDB();
|
|
break;
|
|
|
|
case 'minio':
|
|
case 's3':
|
|
await serviceManager.stopMinIO();
|
|
break;
|
|
|
|
case 'all':
|
|
case '':
|
|
await serviceManager.stopMongoDB();
|
|
console.log();
|
|
await serviceManager.stopMinIO();
|
|
break;
|
|
|
|
default:
|
|
helpers.printMessage(`Unknown service: ${service}`, 'red');
|
|
helpers.printMessage('Use: mongo, s3, or all', 'yellow');
|
|
break;
|
|
}
|
|
}
|
|
|
|
async function handleRestart(serviceManager: ServiceManager, service: string) {
|
|
helpers.printHeader('Restarting Services');
|
|
|
|
switch (service) {
|
|
case 'mongo':
|
|
case 'mongodb':
|
|
await serviceManager.stopMongoDB();
|
|
await plugins.smartdelay.delayFor(2000);
|
|
await serviceManager.startMongoDB();
|
|
break;
|
|
|
|
case 'minio':
|
|
case 's3':
|
|
await serviceManager.stopMinIO();
|
|
await plugins.smartdelay.delayFor(2000);
|
|
await serviceManager.startMinIO();
|
|
break;
|
|
|
|
case 'all':
|
|
case '':
|
|
await serviceManager.stopMongoDB();
|
|
await serviceManager.stopMinIO();
|
|
await plugins.smartdelay.delayFor(2000);
|
|
await serviceManager.startMongoDB();
|
|
console.log();
|
|
await serviceManager.startMinIO();
|
|
break;
|
|
|
|
default:
|
|
helpers.printMessage(`Unknown service: ${service}`, 'red');
|
|
break;
|
|
}
|
|
}
|
|
|
|
async function handleRemove(serviceManager: ServiceManager) {
|
|
helpers.printHeader('Removing Containers');
|
|
helpers.printMessage('⚠️ This will remove containers but preserve data', 'yellow');
|
|
|
|
const shouldContinue = await plugins.smartinteract.SmartInteract.getCliConfirmation('Continue?', false);
|
|
|
|
if (shouldContinue) {
|
|
await serviceManager.removeContainers();
|
|
} else {
|
|
helpers.printMessage('Cancelled', 'yellow');
|
|
}
|
|
}
|
|
|
|
async function handleClean(serviceManager: ServiceManager) {
|
|
helpers.printHeader('Clean All');
|
|
helpers.printMessage('⚠️ WARNING: This will remove all containers and data!', 'red');
|
|
helpers.printMessage('This action cannot be undone!', 'red');
|
|
|
|
const smartinteraction = new plugins.smartinteract.SmartInteract();
|
|
const confirmAnswer = await smartinteraction.askQuestion({
|
|
name: 'confirm',
|
|
type: 'input',
|
|
message: 'Type "yes" to confirm:',
|
|
default: 'no'
|
|
});
|
|
|
|
if (confirmAnswer.value === 'yes') {
|
|
await serviceManager.removeContainers();
|
|
console.log();
|
|
await serviceManager.cleanData();
|
|
helpers.printMessage('All cleaned ✓', 'green');
|
|
} else {
|
|
helpers.printMessage('Cancelled', 'yellow');
|
|
}
|
|
}
|
|
|
|
function showHelp() {
|
|
helpers.printHeader('GitZone Services Manager');
|
|
|
|
helpers.printMessage('Usage: gitzone services [command] [options]', 'green');
|
|
console.log();
|
|
|
|
helpers.printMessage('Commands:', 'yellow');
|
|
helpers.printMessage(' start [service] Start services (mongo|s3|all)', undefined);
|
|
helpers.printMessage(' stop [service] Stop services (mongo|s3|all)', undefined);
|
|
helpers.printMessage(' restart [service] Restart services (mongo|s3|all)', undefined);
|
|
helpers.printMessage(' status Show service status', undefined);
|
|
helpers.printMessage(' config Show current configuration', undefined);
|
|
helpers.printMessage(' compass Show MongoDB Compass connection string', undefined);
|
|
helpers.printMessage(' logs [service] Show logs (mongo|s3|all) [lines]', undefined);
|
|
helpers.printMessage(' remove Remove all containers', undefined);
|
|
helpers.printMessage(' clean Remove all containers and data ⚠️', undefined);
|
|
helpers.printMessage(' help Show this help message', undefined);
|
|
console.log();
|
|
|
|
helpers.printMessage('Features:', 'yellow');
|
|
helpers.printMessage(' • Auto-creates .nogit/env.json with smart defaults', undefined);
|
|
helpers.printMessage(' • Random ports (20000-30000) to avoid conflicts', undefined);
|
|
helpers.printMessage(' • Project-specific containers for multi-project support', undefined);
|
|
helpers.printMessage(' • Preserves custom configuration values', undefined);
|
|
helpers.printMessage(' • MongoDB Compass connection support', undefined);
|
|
console.log();
|
|
|
|
helpers.printMessage('Examples:', 'yellow');
|
|
helpers.printMessage(' gitzone services start # Start all services', undefined);
|
|
helpers.printMessage(' gitzone services start mongo # Start only MongoDB', undefined);
|
|
helpers.printMessage(' gitzone services stop # Stop all services', undefined);
|
|
helpers.printMessage(' gitzone services status # Check service status', undefined);
|
|
helpers.printMessage(' gitzone services config # Show configuration', undefined);
|
|
helpers.printMessage(' gitzone services compass # Get MongoDB Compass connection', undefined);
|
|
helpers.printMessage(' gitzone services logs mongo 50 # Show last 50 lines of MongoDB logs', undefined);
|
|
} |