All checks were successful
Test Asgard Runner / test (push) Successful in 3s
Frontend: - Add Companion Agent card to ServerView (status, download links, setup instructions) - Shows agent connection status, last heartbeat, license key for copy - Download buttons for Linux/Windows amd64 from Gitea releases CI/CD: - Fix build-companion.yml: replace actions/github-script with Gitea API curl - Inject version from git tag via ldflags (-X main.version) - Add VERSION variable to Makefile with ldflags injection - Change main.go version from const to var for ldflags compatibility Deployment: - Add systemd service file (deployment/corrosion-companion.service) - Add .gitignore for bin/ (binaries should come from CI, not repo) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
93 lines
2.6 KiB
Go
93 lines
2.6 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"log"
|
|
"os"
|
|
"os/signal"
|
|
"syscall"
|
|
"time"
|
|
|
|
"github.com/kelseyhightower/envconfig"
|
|
"github.com/vigilcyber/corrosion-companion/internal/app"
|
|
"github.com/vigilcyber/corrosion-companion/internal/client"
|
|
)
|
|
|
|
// Config holds all environment-based configuration
|
|
type Config struct {
|
|
// NATS connection
|
|
NATSUrl string `envconfig:"NATS_URL" required:"true"`
|
|
NATSToken string `envconfig:"NATS_TOKEN" required:"true"`
|
|
|
|
// License identification
|
|
LicenseID string `envconfig:"LICENSE_ID" required:"true"`
|
|
|
|
// Game server configuration
|
|
SteamCMDPath string `envconfig:"STEAMCMD_PATH" default:"/usr/games/steamcmd"`
|
|
GameServerPath string `envconfig:"GAME_SERVER_PATH" required:"true"`
|
|
GameServerArgs string `envconfig:"GAME_SERVER_ARGS" default:"-batchmode"`
|
|
|
|
// Optional settings
|
|
HeartbeatInterval int `envconfig:"HEARTBEAT_INTERVAL" default:"60"`
|
|
LogLevel string `envconfig:"LOG_LEVEL" default:"info"`
|
|
}
|
|
|
|
var version = "dev"
|
|
|
|
func main() {
|
|
log.SetFlags(log.LstdFlags | log.Lshortfile)
|
|
log.Printf("Corrosion Companion Agent v%s starting...", version)
|
|
|
|
// Load configuration from environment
|
|
var cfg Config
|
|
if err := envconfig.Process("", &cfg); err != nil {
|
|
log.Fatalf("Failed to load configuration: %v", err)
|
|
}
|
|
|
|
log.Printf("Configuration loaded:")
|
|
log.Printf(" NATS URL: %s", cfg.NATSUrl)
|
|
log.Printf(" License ID: %s", cfg.LicenseID)
|
|
log.Printf(" Game Server Path: %s", cfg.GameServerPath)
|
|
log.Printf(" SteamCMD Path: %s", cfg.SteamCMDPath)
|
|
log.Printf(" Heartbeat Interval: %ds", cfg.HeartbeatInterval)
|
|
|
|
// Create context with signal handling for graceful shutdown
|
|
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
|
|
defer cancel()
|
|
|
|
// Connect to NATS
|
|
log.Println("Connecting to NATS...")
|
|
nc, err := client.Connect(cfg.NATSUrl, cfg.NATSToken)
|
|
if err != nil {
|
|
log.Fatalf("Failed to connect to NATS: %v", err)
|
|
}
|
|
defer nc.Close()
|
|
|
|
log.Println("NATS connection established")
|
|
|
|
// Initialize daemon configuration
|
|
daemonCfg := &app.DaemonConfig{
|
|
LicenseID: cfg.LicenseID,
|
|
HeartbeatInterval: time.Duration(cfg.HeartbeatInterval) * time.Second,
|
|
SteamCMDPath: cfg.SteamCMDPath,
|
|
GameServerPath: cfg.GameServerPath,
|
|
GameServerArgs: cfg.GameServerArgs,
|
|
Version: version,
|
|
}
|
|
|
|
// Start daemon
|
|
daemon, err := app.NewDaemon(nc, daemonCfg)
|
|
if err != nil {
|
|
log.Fatalf("Failed to initialize daemon: %v", err)
|
|
}
|
|
|
|
log.Println("Daemon initialized, starting main loop...")
|
|
|
|
// Run daemon until context is cancelled
|
|
if err := daemon.Run(ctx); err != nil {
|
|
log.Fatalf("Daemon error: %v", err)
|
|
}
|
|
|
|
log.Println("Companion agent shutdown complete")
|
|
}
|