diff --git a/cmd/tt-server/internal/app/server.go b/cmd/tt-server/internal/app/server.go index fe5501b..713a357 100644 --- a/cmd/tt-server/internal/app/server.go +++ b/cmd/tt-server/internal/app/server.go @@ -6,6 +6,7 @@ import ( "net/http" "os" "os/signal" + "runtime/debug" "time" "github.com/ainghazal/tunnel-telemetry/internal/collector" @@ -17,6 +18,21 @@ import ( "golang.org/x/crypto/acme/autocert" ) +var commitInfo = func() string { + if info, ok := debug.ReadBuildInfo(); ok { + for _, setting := range info.Settings { + if setting.Key == "vcs.revision" { + return setting.Value[:12] + } + } + } + return "unknown" +}() + +func handleVersionInfo(c echo.Context) error { + return c.String(http.StatusOK, commitInfo) +} + func startEchoServer(cfg *config.Config) { e := server.NewEchoServer(cfg) if cfg.Debug { @@ -28,6 +44,7 @@ func startEchoServer(cfg *config.Config) { e.GET("/", server.HandleRootDecoy) e.POST("/report", h.CreateReport) + e.GET("/version", handleVersionInfo) ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt) defer stop() diff --git a/scripts/systemd/ttserver.service b/scripts/systemd/ttserver.service index daff9bb..a2a84dd 100644 --- a/scripts/systemd/ttserver.service +++ b/scripts/systemd/ttserver.service @@ -11,10 +11,10 @@ Restart=on-failure RestartSec=10 WorkingDirectory=/home/ttserver -ExecStart=/usr/bin/ttserver +ExecStart=/usr/bin/tt-server ExecStartPre=cp /home/ttserver/dist/tt-server /usr/bin -ExecStartPre=chmod +x /usr/bin/ttserver +ExecStartPre=chmod +x /usr/bin/tt-server [Install] WantedBy=multi-user.target