Skip to content

Commit

Permalink
Disable lockfile under fleet mode (#33988)
Browse files Browse the repository at this point in the history
* diable lockfile under fleet mode

* update docs

* add changelog
  • Loading branch information
fearful-symmetry authored and chrisberkhout committed Jun 1, 2023
1 parent 2d8e5c8 commit e40f777
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Expand Up @@ -45,6 +45,7 @@ https://github.com/elastic/beats/compare/v8.2.0\...main[Check the HEAD diff]
- Fix Windows service install/uninstall when Win32_Service returns error, add logic to wait until the Windows Service is stopped before proceeding. {pull}33322[33322]
- Support for multiline zookeeper logs {issue}2496[2496]
- Allow `clock_nanosleep` in the default seccomp profiles for amd64 and 386. Newer versions of glibc (e.g. 2.31) require it. {issue}33792[33792]
- Disable lockfile when running under elastic-agent. {pull}33988[33988]

*Auditbeat*

Expand Down
24 changes: 15 additions & 9 deletions libbeat/cmd/instance/beat.go
Expand Up @@ -46,6 +46,7 @@ import (
"github.com/elastic/beats/v7/libbeat/cloudid"
"github.com/elastic/beats/v7/libbeat/cmd/instance/locks"
"github.com/elastic/beats/v7/libbeat/common"
"github.com/elastic/beats/v7/libbeat/common/fleetmode"
"github.com/elastic/beats/v7/libbeat/common/reload"
"github.com/elastic/beats/v7/libbeat/common/seccomp"
"github.com/elastic/beats/v7/libbeat/dashboards"
Expand Down Expand Up @@ -386,15 +387,19 @@ func (b *Beat) launch(settings Settings, bt beat.Creator) error {
defer svc.NotifyTermination()

// Try to acquire exclusive lock on data path to prevent another beat instance
// sharing same data path.
bl := locks.New(b.Info)
err := bl.Lock()
if err != nil {
return err
// sharing same data path. This is disabled under elastic-agent.
if !fleetmode.Enabled() {
bl := locks.New(b.Info)
err := bl.Lock()
if err != nil {
return err
}
defer func() {
_ = bl.Unlock()
}()
} else {
logp.Info("running under elastic-agent, per-beat lockfiles disabled")
}
defer func() {
_ = bl.Unlock()
}()

svc.BeforeRun()
defer svc.Cleanup()
Expand All @@ -405,6 +410,7 @@ func (b *Beat) launch(settings Settings, bt beat.Creator) error {
// set the appropriate permission on the unix domain file without having to whitelist anything
// that would be set at runtime.
if b.Config.HTTP.Enabled() {
var err error
b.API, err = api.NewWithDefaultRoutes(logp.NewLogger(""), b.Config.HTTP, monitoring.GetNamespace)
if err != nil {
return fmt.Errorf("could not start the HTTP server for the API: %w", err)
Expand All @@ -422,7 +428,7 @@ func (b *Beat) launch(settings Settings, bt beat.Creator) error {
}
}

if err = seccomp.LoadFilter(b.Config.Seccomp); err != nil {
if err := seccomp.LoadFilter(b.Config.Seccomp); err != nil {
return err
}

Expand Down

0 comments on commit e40f777

Please sign in to comment.