refactor(core): add headless run and auto-restart
- Run without console by default - Log to file once console hidden - Recover panics in background goroutines - Restart agent after unexpected errors - Use shared instance launch helper
This commit is contained in:
+3
-3
@@ -100,16 +100,16 @@ func (a *Agent) Serve() error {
|
||||
return fmt.Errorf("listen %s: %w", a.addr, err)
|
||||
}
|
||||
|
||||
fmt.Printf("win64_mp %s\nListening on http://%s\nPress Ctrl+C to stop.\n", config.Version, a.addr)
|
||||
helpers.Log.Printf("win64_mp %s listening on http://%s", config.Version, a.addr)
|
||||
|
||||
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt)
|
||||
defer stop()
|
||||
go func() {
|
||||
helpers.Go("shutdown", func() {
|
||||
<-ctx.Done()
|
||||
shutdownCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
_ = a.server.Shutdown(shutdownCtx)
|
||||
}()
|
||||
})
|
||||
|
||||
if err := a.server.Serve(listener); err != nil && !errors.Is(err, http.ErrServerClosed) {
|
||||
return fmt.Errorf("serve: %w", err)
|
||||
|
||||
Reference in New Issue
Block a user