package main import ( "context" "os" "os/signal" "syscall" "nettool/internal/config" "nettool/internal/deviceinfo" "nettool/internal/discovery" "nettool/internal/httpserver" "nettool/internal/logger" applyexecsvc "nettool/internal/network/applyexec" configreadersvc "nettool/internal/network/configreader" interfacesvc "nettool/internal/network/interfaces" netplansvc "nettool/internal/network/netplan" validatorsvc "nettool/internal/network/validator" "nettool/internal/systemaction" "nettool/internal/tasks" ) func main() { ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) defer stop() log := logger.New() cfg := config.Load(os.Args[1:]) log.Info("server starting", "version", cfg.ServerVersion) if os.Geteuid() != 0 { log.Warn("server is not running as root; netplan write/apply and system actions will fail") } deviceSvc := deviceinfo.New(cfg) interfaceSvc := interfacesvc.New(cfg) configSvc := configreadersvc.New() validatorSvc := validatorsvc.New() netplanSvc := netplansvc.New() applySvc := applyexecsvc.New() taskSvc := tasks.New() systemSvc := systemaction.New() httpSrv := httpserver.New(cfg, log, deviceSvc, interfaceSvc, configSvc, validatorSvc, netplanSvc, applySvc, taskSvc, systemSvc) udpSrv := discovery.New(cfg, log, deviceSvc) errCh := make(chan error, 2) go func() { errCh <- httpSrv.Run(ctx) }() go func() { errCh <- udpSrv.Run(ctx) }() select { case <-ctx.Done(): log.Info("server shutting down") case err := <-errCh: if err != nil { log.Error("server stopped with error", "error", err.Error()) } } }