Skip to content

Commit

Permalink
add version endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
ainghazal committed Apr 21, 2024
1 parent 76ac07e commit c6d080d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
17 changes: 17 additions & 0 deletions cmd/tt-server/internal/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net/http"
"os"
"os/signal"
"runtime/debug"
"time"

"github.com/ainghazal/tunnel-telemetry/internal/collector"
Expand All @@ -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 {
Expand All @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions scripts/systemd/ttserver.service
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit c6d080d

Please sign in to comment.