Add systemd activation sockets for downtime-free deploys

This commit is contained in:
Eli Ribble 2026-04-28 23:24:19 +00:00
parent bd3d3881f5
commit f3af19f03a
No known key found for this signature in database
4 changed files with 11 additions and 2 deletions

View file

@ -24,7 +24,7 @@ pkgs.buildGoModule rec {
src = ./.; src = ./.;
subPackages = []; subPackages = [];
version = "0.0.12"; version = "0.0.12";
vendorHash = "sha256-IkoFGy5ky/00UFhrBXkrAgulxTjoQqciQ8tRcdz8l2o="; vendorHash = "sha256-d2cTpzEtUmxAKPKmM0zeKhW4nbLnI08X8lm2yayl+NA=";
buildInputs = [ pkgs.proj ]; buildInputs = [ pkgs.proj ];

1
go.mod
View file

@ -47,6 +47,7 @@ require (
github.com/beevik/etree v1.1.0 // indirect github.com/beevik/etree v1.1.0 // indirect
github.com/buger/jsonparser v1.1.1 // indirect github.com/buger/jsonparser v1.1.1 // indirect
github.com/chromedp/sysutil v1.1.0 // indirect github.com/chromedp/sysutil v1.1.0 // indirect
github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf // indirect
github.com/dustin/go-humanize v1.0.1 // indirect github.com/dustin/go-humanize v1.0.1 // indirect
github.com/go-ini/ini v1.67.0 // indirect github.com/go-ini/ini v1.67.0 // indirect
github.com/go-json-experiment/json v0.0.0-20250725192818-e39067aee2d2 // indirect github.com/go-json-experiment/json v0.0.0-20250725192818-e39067aee2d2 // indirect

2
go.sum
View file

@ -48,6 +48,8 @@ github.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I=
github.com/containerd/log v0.1.0/go.mod h1:VRRf09a7mHDIRezVKTRCrOq78v577GXq3bSa3EhrzVo= github.com/containerd/log v0.1.0/go.mod h1:VRRf09a7mHDIRezVKTRCrOq78v577GXq3bSa3EhrzVo=
github.com/containerd/platforms v0.2.1 h1:zvwtM3rz2YHPQsF2CHYM8+KtB5dvhISiXh5ZpSBQv6A= github.com/containerd/platforms v0.2.1 h1:zvwtM3rz2YHPQsF2CHYM8+KtB5dvhISiXh5ZpSBQv6A=
github.com/containerd/platforms v0.2.1/go.mod h1:XHCb+2/hzowdiut9rkudds9bE5yJ7npe7dG/wG+uFPw= github.com/containerd/platforms v0.2.1/go.mod h1:XHCb+2/hzowdiut9rkudds9bE5yJ7npe7dG/wG+uFPw=
github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf h1:iW4rZ826su+pqaw19uhpSCzhj44qo35pNgKFGqzDKkU=
github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/cpuguy83/dockercfg v0.3.2 h1:DlJTyZGBDlXqUZ2Dk2Q3xHs/FtnooJJVaad2S9GKorA= github.com/cpuguy83/dockercfg v0.3.2 h1:DlJTyZGBDlXqUZ2Dk2Q3xHs/FtnooJJVaad2S9GKorA=
github.com/cpuguy83/dockercfg v0.3.2/go.mod h1:sugsbF4//dDlL/i+S+rtpIWp+5h0BHJHfjj5/jFyUJc= github.com/cpuguy83/dockercfg v0.3.2/go.mod h1:sugsbF4//dDlL/i+S+rtpIWp+5h0BHJHfjj5/jFyUJc=

View file

@ -22,6 +22,7 @@ import (
"github.com/Gleipnir-Technology/nidus-sync/rmo" "github.com/Gleipnir-Technology/nidus-sync/rmo"
nidussync "github.com/Gleipnir-Technology/nidus-sync/sync" nidussync "github.com/Gleipnir-Technology/nidus-sync/sync"
"github.com/Gleipnir-Technology/nidus-sync/version" "github.com/Gleipnir-Technology/nidus-sync/version"
"github.com/coreos/go-systemd/activation"
"github.com/getsentry/sentry-go" "github.com/getsentry/sentry-go"
sentryhttp "github.com/getsentry/sentry-go/http" sentryhttp "github.com/getsentry/sentry-go/http"
"github.com/getsentry/sentry-go/zerolog" "github.com/getsentry/sentry-go/zerolog"
@ -145,13 +146,18 @@ func main() {
log.Error().Err(err).Msg("Failed to start openAI client") log.Error().Err(err).Msg("Failed to start openAI client")
os.Exit(8) os.Exit(8)
} }
listeners, _ := activation.Listeners()
if len(listeners) != 1 {
log.Error().Int("len", len(listeners)).Msg("Unexpected number of socket activation FDs")
os.Exit(1)
}
server := &http.Server{ server := &http.Server{
Addr: config.Bind, Addr: config.Bind,
Handler: r, Handler: r,
} }
go func() { go func() {
log.Info().Str("address", config.Bind).Msg("Serving HTTP requests") log.Info().Str("address", config.Bind).Msg("Serving HTTP requests")
if err := server.ListenAndServe(); err != nil && err != http.ErrServerClosed { if err := server.Serve(listeners[0]); err != nil && err != http.ErrServerClosed {
log.Error().Str("err", err.Error()).Msg("HTTP Server Error") log.Error().Str("err", err.Error()).Msg("HTTP Server Error")
} }
log.Debug().Msg("Exiting listen-and-serve goroutine") log.Debug().Msg("Exiting listen-and-serve goroutine")