Service Controls Feature
This document describes the service start/stop/restart controls feature in the create-polyglot admin dashboard.
Overview
The service controls feature provides a web-based interface for managing service lifecycle operations (start, stop, restart) directly from the admin dashboard. This complements the existing service logs feature to provide comprehensive service management capabilities.
Features
Web UI Controls
- Start Button: Start a stopped service
- Stop Button: Stop a running service
- Restart Button: Restart a running service
- Intelligent Button States: Buttons are enabled/disabled based on current service status
- Real-time Feedback: Visual feedback with temporary status messages
- Auto-refresh: Service status automatically updates after operations
Backend API
- RESTful Endpoints: Standard HTTP endpoints for service operations
- Process Management: Spawns and manages service processes using Node.js child_process
- Service Detection: Automatically detects service types and uses appropriate start commands
- Status Monitoring: Tracks process IDs, uptime, and health status
Architecture
Frontend Components
The admin dashboard (/admin) includes:
- Service Status Table: Enhanced with control buttons for each service
- Action Buttons: Start/Stop/Restart buttons with conditional visibility
- Status Indicators: Visual indicators for service state (running/stopped/error)
- Feedback System: Temporary messages showing operation results
Backend Components
Service Manager (
bin/lib/service-manager.js):startService(serviceName): Start a service processstopService(serviceName): Stop a running servicerestartService(serviceName): Restart a servicegetServiceStatus(serviceName): Get detailed service status
Admin API (
bin/lib/admin.js):POST /api/services/start: Start a servicePOST /api/services/stop: Stop a servicePOST /api/services/restart: Restart a serviceGET /api/services/status: Get service status
Service Type Support
The service manager supports all create-polyglot service types:
Node.js Services
- Start Command:
npm startornode src/index.js - Working Directory: Service root directory
- Environment: Inherits parent environment with service-specific variables
Python Services
- Start Command:
uvicorn app.main:app --reload --host 0.0.0.0 --port {port} - Working Directory: Service root directory
- Environment: Python path and service-specific variables
Go Services
- Start Command:
go run main.go - Working Directory: Service root directory
- Environment: Go-specific environment variables
Java Services (Spring Boot)
- Start Command:
./mvnw spring-boot:runormvn spring-boot:run - Working Directory: Service root directory
- Environment: Java and Maven environment variables
Usage
Via Admin Dashboard
Start the admin dashboard:
bashcreate-polyglot adminNavigate to
http://localhost:8080(or your configured port)Use the control buttons in the service status table:
- Click Start to start a stopped service
- Click Stop to stop a running service
- Click Restart to restart a running service
API Usage
You can also control services programmatically via the REST API:
# Start a service
curl -X POST http://localhost:8080/api/services/start \
-H "Content-Type: application/json" \
-d '{"service": "api"}'
# Stop a service
curl -X POST http://localhost:8080/api/services/stop \
-H "Content-Type: application/json" \
-d '{"service": "api"}'
# Restart a service
curl -X POST http://localhost:8080/api/services/restart \
-H "Content-Type: application/json" \
-d '{"service": "api"}'
# Get service status
curl http://localhost:8080/api/services/statusError Handling
Common Scenarios
- Service Not Found: Returns 404 if service doesn't exist in polyglot.json
- Already Running: Start operation returns success if service already running
- Not Running: Stop operation returns success if service already stopped
- Permission Errors: Returns 500 with error details for permission issues
- Command Failures: Returns 500 with stderr output for command failures
Frontend Error Display
- Failed Operations: Red error messages with specific failure reasons
- Success Operations: Green success messages with operation confirmation
- Automatic Cleanup: Status messages auto-hide after 3 seconds
Configuration
Default Ports
Services use ports from polyglot.json configuration. The service manager reads port information to properly configure service startup.
Process Management
- Process Tracking: PIDs stored in memory for stop/restart operations
- Cleanup: Processes are properly terminated on service stop
- Health Checks: Status endpoints verify service health
Integration with Logs Feature
The service controls work seamlessly with the existing logs feature:
- Log Generation: Started services automatically generate logs
- Real-time Streaming: Log streaming continues during service operations
- Operation Logging: Service start/stop operations are logged
- Status Correlation: Service status affects log display and streaming
Security Considerations
Process Isolation
- Services run as separate processes with isolated environments
- No privileged operations required
- Standard user permissions sufficient
API Security
- Admin dashboard runs on localhost only by default
- No authentication required for local development
- Consider adding authentication for production deployments
Development and Extension
Adding New Service Types
To add support for a new service type:
- Update
getServiceCommands()inservice-manager.js - Add service type detection logic
- Define appropriate start commands and environment
- Test with sample service of that type
Customizing Commands
Service start commands can be customized by:
- Modifying the command mapping in
service-manager.js - Adding environment-specific logic
- Supporting custom npm scripts or package.json configurations
Testing
Manual Testing
- Create test workspace with multiple service types
- Start admin dashboard
- Verify all control buttons work correctly
- Test error scenarios (invalid services, permission issues)
- Verify status updates and log integration
Integration Testing
The feature integrates with existing test suites in:
tests/admin-command.test.js: Admin dashboard functionalitytests/dev-command.test.js: Service process management
Future Enhancements
Potential improvements for this feature:
- Bulk Operations: Start/stop multiple services simultaneously
- Service Dependencies: Respect service startup order and dependencies
- Health Monitoring: Advanced health checks beyond process existence
- Resource Monitoring: CPU/memory usage for running services
- Service Logs Integration: Direct log tailing from control interface
- Configuration Management: Edit service configuration from UI
- Deployment Controls: Build, test, and deploy operations
Related Documentation
- Service Logs Feature - Log viewing and streaming
- Admin Command - Admin dashboard usage
- Getting Started Guide - Basic create-polyglot usage
Changelog
- v1.11.1: Initial service controls implementation
- Added service start/stop/restart functionality
- Enhanced admin dashboard with control buttons
- Integrated with existing service status monitoring
- Added comprehensive error handling and user feedback