From 8da9d5eefdc33aadc2e519215889eeb3416e0522 Mon Sep 17 00:00:00 2001 From: mmetc <92726601+mmetc@users.noreply.github.com> Date: Thu, 8 Jun 2023 15:04:48 +0200 Subject: [PATCH] don't log notification error if not running under systemd (#2274) --- cmd/crowdsec/serve.go | 7 ++----- go.mod | 4 ++-- go.sum | 4 ++-- pkg/setup/detect_test.go | 3 ++- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/cmd/crowdsec/serve.go b/cmd/crowdsec/serve.go index 5e2e8b720..789457246 100644 --- a/cmd/crowdsec/serve.go +++ b/cmd/crowdsec/serve.go @@ -6,11 +6,11 @@ import ( "syscall" "time" - "github.com/coreos/go-systemd/v22/daemon" "github.com/pkg/errors" log "github.com/sirupsen/logrus" "gopkg.in/tomb.v2" + "github.com/crowdsecurity/go-cs-lib/pkg/csdaemon" "github.com/crowdsecurity/go-cs-lib/pkg/trace" "github.com/crowdsecurity/crowdsec/pkg/csconfig" @@ -350,10 +350,7 @@ func Serve(cConfig *csconfig.Config, apiReady chan bool, agentReady chan bool) e } if cConfig.Common != nil && cConfig.Common.Daemonize { - sent, err := daemon.SdNotify(false, daemon.SdNotifyReady) - if !sent || err != nil { - log.Errorf("Failed to notify(sent: %v): %v", sent, err) - } + csdaemon.NotifySystemd(log.StandardLogger()) // wait for signals return HandleSignals(cConfig) } diff --git a/go.mod b/go.mod index d2874ad05..2b3840473 100644 --- a/go.mod +++ b/go.mod @@ -70,8 +70,7 @@ require ( github.com/blackfireio/osinfo v1.0.3 github.com/bluele/gcache v0.0.2 github.com/cespare/xxhash/v2 v2.1.2 - github.com/coreos/go-systemd/v22 v22.5.0 - github.com/crowdsecurity/go-cs-lib v0.0.0-20230531105801-4c1535c2b3bd + github.com/crowdsecurity/go-cs-lib v0.0.2 github.com/goccy/go-yaml v1.9.7 github.com/gofrs/uuid v4.0.0+incompatible github.com/golang-jwt/jwt/v4 v4.2.0 @@ -102,6 +101,7 @@ require ( github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect github.com/asaskevich/govalidator v0.0.0-20200907205600-7a23bdc65eef // indirect github.com/beorn7/perks v1.0.1 // indirect + github.com/coreos/go-systemd/v22 v22.5.0 // indirect github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect github.com/docker/distribution v2.8.2+incompatible // indirect github.com/docker/go-units v0.4.0 // indirect diff --git a/go.sum b/go.sum index 4a63b3839..3ec66178c 100644 --- a/go.sum +++ b/go.sum @@ -172,8 +172,8 @@ github.com/creack/pty v1.1.11 h1:07n33Z8lZxZ2qwegKbObQohDhXDQxiMMz1NOUGYlesw= github.com/creack/pty v1.1.11/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/crowdsecurity/dlog v0.0.0-20170105205344-4fb5f8204f26 h1:r97WNVC30Uen+7WnLs4xDScS/Ex988+id2k6mDf8psU= github.com/crowdsecurity/dlog v0.0.0-20170105205344-4fb5f8204f26/go.mod h1:zpv7r+7KXwgVUZnUNjyP22zc/D7LKjyoY02weH2RBbk= -github.com/crowdsecurity/go-cs-lib v0.0.0-20230531105801-4c1535c2b3bd h1:Y70ceDKAKYFXTnxEjXuBDSh07umvDhbX3PCCYhdtsZ0= -github.com/crowdsecurity/go-cs-lib v0.0.0-20230531105801-4c1535c2b3bd/go.mod h1:9JJLSpGj1ZXnROV3xAcJvS/HTaUvuA8K3gGOpO4tfVc= +github.com/crowdsecurity/go-cs-lib v0.0.2 h1:+Tjmf/IclOXNzU9sxKVQvUl9CkMfbM60xQ0zA05NWps= +github.com/crowdsecurity/go-cs-lib v0.0.2/go.mod h1:iznTJ19qLTYdZBcRb5RVDlcUdSlayBCivBkWsXlOY3g= github.com/crowdsecurity/grokky v0.2.1 h1:t4VYnDlAd0RjDM2SlILalbwfCrQxtJSMGdQOR0zwkE4= github.com/crowdsecurity/grokky v0.2.1/go.mod h1:33usDIYzGDsgX1kHAThCbseso6JuWNJXOzRQDGXHtWM= github.com/crowdsecurity/machineid v1.0.2 h1:wpkpsUghJF8Khtmn/tg6GxgdhLA1Xflerh5lirI+bdc= diff --git a/pkg/setup/detect_test.go b/pkg/setup/detect_test.go index 4f6ef0c33..1f3cf9eec 100644 --- a/pkg/setup/detect_test.go +++ b/pkg/setup/detect_test.go @@ -10,6 +10,7 @@ import ( "github.com/lithammer/dedent" "github.com/stretchr/testify/require" + "github.com/crowdsecurity/go-cs-lib/pkg/csstring" "github.com/crowdsecurity/go-cs-lib/pkg/cstest" "github.com/crowdsecurity/crowdsec/pkg/setup" @@ -1007,7 +1008,7 @@ func TestDetectDatasourceValidation(t *testing.T) { "DetectYaml": detectYaml, } - expectedErr, err := cstest.Interpolate(tc.expectedErr, data) + expectedErr, err := csstring.Interpolate(tc.expectedErr, data) require.NoError(err) detected, err := setup.Detect(detectYaml, setup.DetectOptions{})