Prechádzať zdrojové kódy

don't log notification error if not running under systemd (#2274)

mmetc 2 rokov pred
rodič
commit
8da9d5eefd
4 zmenil súbory, kde vykonal 8 pridanie a 10 odobranie
  1. 2 5
      cmd/crowdsec/serve.go
  2. 2 2
      go.mod
  3. 2 2
      go.sum
  4. 2 1
      pkg/setup/detect_test.go

+ 2 - 5
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)
 	}

+ 2 - 2
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

+ 2 - 2
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=

+ 2 - 1
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{})