Files
CHORUS/cmd/chorus/main.go
anthonyrawlins 7c6cbd562a Initial CHORUS project setup
🎭 CHORUS - Container-First P2P Task Coordination System

- Docker-first architecture designed from ground up
- Environment variable-based configuration (no config files)
- Structured logging to stdout/stderr for container runtimes
- License validation required for operation
- Clean separation from BZZZ legacy systemd approach

Core features implemented:
- Container-optimized logging system
- Environment-based configuration management
- License validation with KACHING integration
- Basic HTTP API and health endpoints
- Docker build and deployment configuration

Ready for P2P protocol development and AI integration.

🤖 Generated with Claude Code
2025-09-02 19:53:33 +10:00

89 lines
2.5 KiB
Go

package main
import (
"context"
"fmt"
"os"
"os/signal"
"syscall"
"time"
"chorus.services/chorus/internal/agent"
"chorus.services/chorus/internal/config"
"chorus.services/chorus/internal/licensing"
"chorus.services/chorus/internal/logging"
)
const (
AppName = "CHORUS"
AppVersion = "0.1.0-dev"
)
func main() {
// Initialize container-optimized logger
logger := logging.NewContainerLogger(AppName)
logger.Info("🎭 Starting CHORUS v%s - Container-First P2P Task Coordination", AppVersion)
// Load configuration from environment
cfg, err := config.LoadFromEnvironment()
if err != nil {
logger.Error("❌ Configuration error: %v", err)
os.Exit(1)
}
// CRITICAL: Validate license before any P2P operations
logger.Info("🔐 Validating CHORUS license...")
licenseValidator := licensing.NewValidator(cfg.License)
if err := licenseValidator.Validate(); err != nil {
logger.Error("❌ License validation failed: %v", err)
logger.Error("💰 CHORUS requires a valid license to operate")
logger.Error("📞 Contact chorus.services for licensing information")
os.Exit(1)
}
logger.Info("✅ License validation successful")
// Create context for graceful shutdown
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
// Initialize CHORUS agent
agent, err := agent.New(ctx, cfg, logger)
if err != nil {
logger.Error("❌ Failed to create agent: %v", err)
os.Exit(1)
}
// Start agent services
if err := agent.Start(); err != nil {
logger.Error("❌ Failed to start agent: %v", err)
os.Exit(1)
}
logger.Info("✅ CHORUS agent started successfully")
logger.Info("🆔 Agent ID: %s", agent.ID())
logger.Info("🔗 P2P Address: %s", agent.P2PAddress())
logger.Info("🌐 API Endpoint: http://localhost:%d", cfg.Network.APIPort)
logger.Info("🏥 Health Endpoint: http://localhost:%d/health", cfg.Network.HealthPort)
// Set up graceful shutdown
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)
// Wait for shutdown signal
<-sigChan
logger.Info("🛑 Shutdown signal received, stopping CHORUS agent...")
// Cancel context to trigger graceful shutdown
cancel()
// Give services time to shut down gracefully
shutdownCtx, shutdownCancel := context.WithTimeout(context.Background(), 30*time.Second)
defer shutdownCancel()
if err := agent.Stop(shutdownCtx); err != nil {
logger.Error("⚠️ Error during agent shutdown: %v", err)
} else {
logger.Info("✅ CHORUS agent stopped gracefully")
}
}