Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: elastic/elastic-agent
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: f3425f787003b826199c2e87fc24a43072de8cc9
Choose a base ref
..
head repository: elastic/elastic-agent
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: cebefe57b36e61e2e8633d1760ef4c30db741e68
Choose a head ref
4 changes: 2 additions & 2 deletions NOTICE.txt
Original file line number Diff line number Diff line change
@@ -12445,11 +12445,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

--------------------------------------------------------------------------------
Dependency : golang.org/x/sys
Version: v0.20.0
Version: v0.21.0
Licence type (autodetected): BSD-3-Clause
--------------------------------------------------------------------------------

Contents of probable licence file $GOMODCACHE/golang.org/x/sys@v0.20.0/LICENSE:
Contents of probable licence file $GOMODCACHE/golang.org/x/sys@v0.21.0/LICENSE:

Copyright (c) 2009 The Go Authors. All rights reserved.

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -65,7 +65,7 @@ require (
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616
golang.org/x/sync v0.7.0
golang.org/x/sys v0.20.0
golang.org/x/sys v0.21.0
golang.org/x/term v0.20.0
golang.org/x/text v0.15.0
golang.org/x/time v0.5.0
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -2545,8 +2545,8 @@ golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
Original file line number Diff line number Diff line change
@@ -12,8 +12,9 @@ import (

"gopkg.in/ini.v1"

"github.com/elastic/elastic-agent/internal/pkg/agent/application/paths"
"github.com/elastic/go-service"

"github.com/elastic/elastic-agent/internal/pkg/agent/application/paths"
)

// EnsureServiceConfigUpToDate modifies, if necessary, Elastic Agent's service
3 changes: 2 additions & 1 deletion internal/pkg/agent/install/install.go
Original file line number Diff line number Diff line change
@@ -16,14 +16,15 @@ import (
"github.com/otiai10/copy"
"github.com/schollz/progressbar/v3"

"github.com/elastic/go-service"

"github.com/elastic/elastic-agent-libs/logp"
"github.com/elastic/elastic-agent/internal/pkg/agent/application/paths"
"github.com/elastic/elastic-agent/internal/pkg/agent/errors"
"github.com/elastic/elastic-agent/internal/pkg/agent/perms"
"github.com/elastic/elastic-agent/internal/pkg/cli"
v1 "github.com/elastic/elastic-agent/pkg/api/v1"
"github.com/elastic/elastic-agent/pkg/utils"
"github.com/elastic/go-service"
)

const (
3 changes: 2 additions & 1 deletion internal/pkg/agent/install/installed.go
Original file line number Diff line number Diff line change
@@ -8,9 +8,10 @@ import (
"os"
"path/filepath"

"github.com/elastic/go-service"

"github.com/elastic/elastic-agent/internal/pkg/agent/application/paths"
"github.com/elastic/elastic-agent/internal/pkg/agent/install/pkgmgr"
"github.com/elastic/go-service"
)

// StatusType is the return status types.
99 changes: 4 additions & 95 deletions internal/pkg/agent/install/svc.go
Original file line number Diff line number Diff line change
@@ -5,12 +5,12 @@
package install

import (
"fmt"
"path/filepath"
"runtime"

"github.com/elastic/elastic-agent/internal/pkg/agent/application/paths"
"github.com/elastic/go-service"

"github.com/elastic/elastic-agent/internal/pkg/agent/application/paths"
)

const (
@@ -84,11 +84,6 @@ func newService(topPath string, opt ...serviceOpt) (service.Service, error) {
}

if runtime.GOOS == "linux" {
// The github.com/kardianos/service library doesn't support KillMode in their prebuilt template.
// This option allows to pass our own template for the systemd unit configuration, which is a copy
// of the prebuilt template with added KillMode option
cfg.Option["SystemdScript"] = linuxSystemdScript

// By setting KillMode=process in Elastic Agent's systemd unit configuration file, we ensure
// that in a scenario where the upgraded Agent's process is repeatedly crashing, systemd keeps
// the Upgrade Watcher process running so it can monitor the Agent process for long enough to
@@ -98,98 +93,12 @@ func newService(topPath string, opt ...serviceOpt) (service.Service, error) {
}

if runtime.GOOS == "darwin" {
// The github.com/kardianos/service library doesn't support ExitTimeOut in their prebuilt template.
// This option allows to pass our own template for the launch daemon plist, which is a copy
// of the prebuilt template with added ExitTimeOut option
cfg.Option["LaunchdConfig"] = darwinLaunchdConfig
cfg.Option["ExitTimeOut"] = darwinServiceExitTimeout

// Set the stdout and stderr logs to be inside the installation directory, ensures that the
// Set log directory to be inside the installation directory, ensures that the
// executing user for the service can write to the directory for the logs.
cfg.Option["StandardOutPath"] = filepath.Join(topPath, fmt.Sprintf("%s.out.log", paths.ServiceName))
cfg.Option["StandardErrorPath"] = filepath.Join(topPath, fmt.Sprintf("%s.err.log", paths.ServiceName))
cfg.Option["LogDirectory"] = topPath
}

return service.New(nil, cfg)
}

// A copy of the launchd plist template from github.com/kardianos/service
// with added .Config.Option.ExitTimeOut option
const darwinLaunchdConfig = `<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd" >
<plist version='1.0'>
<dict>
<key>Label</key>
<string>{{html .Name}}</string>
<key>ProgramArguments</key>
<array>
<string>{{html .Path}}</string>
{{range .Config.Arguments}}
<string>{{html .}}</string>
{{end}}
</array>
{{if .UserName}}<key>UserName</key>
<string>{{html .UserName}}</string>{{end}}
{{if .Config.Option.GroupName -}}
<key>GroupName</key>
<string>{{html .Config.Option.GroupName}}</string>
{{- end}}
{{if .ChRoot}}<key>RootDirectory</key>
<string>{{html .ChRoot}}</string>{{end}}
{{if .Config.Option.ExitTimeOut}}<key>ExitTimeOut</key>
<integer>{{html .Config.Option.ExitTimeOut}}</integer>{{end}}
{{if .WorkingDirectory}}<key>WorkingDirectory</key>
<string>{{html .WorkingDirectory}}</string>{{end}}
<key>SessionCreate</key>
<{{bool .SessionCreate}}/>
<key>KeepAlive</key>
<{{bool .KeepAlive}}/>
<key>RunAtLoad</key>
<{{bool .RunAtLoad}}/>
<key>Disabled</key>
<false/>
<key>StandardOutPath</key>
<string>{{html .Config.Option.StandardOutPath}}</string>
<key>StandardErrorPath</key>
<string>{{html .Config.Option.StandardErrorPath}}</string>
</dict>
</plist>
`

// A copy of the systemd config template from github.com/kardianos/service
// with added .Config.Option.KillMode option
const linuxSystemdScript = `[Unit]
Description={{.Description}}
ConditionFileIsExecutable={{.Path|cmdEscape}}
{{range $i, $dep := .Dependencies}}
{{$dep}} {{end}}
[Service]
StartLimitInterval=5
StartLimitBurst=10
ExecStart={{.Path|cmdEscape}}{{range .Arguments}} {{.|cmd}}{{end}}
{{if .ChRoot}}RootDirectory={{.ChRoot|cmd}}{{end}}
{{if .WorkingDirectory}}WorkingDirectory={{.WorkingDirectory|cmdEscape}}{{end}}
{{if .UserName}}User={{.UserName}}{{end}}
{{if .Config.Option.GroupName -}}
Group={{.Config.Option.GroupName}}
{{- end}}
{{if .ReloadSignal}}ExecReload=/bin/kill -{{.ReloadSignal}} "$MAINPID"{{end}}
{{if .PIDFile}}PIDFile={{.PIDFile|cmd}}{{end}}
{{if and .LogOutput .HasOutputFileSupport -}}
StandardOutput=file:/var/log/{{.Name}}.out
StandardError=file:/var/log/{{.Name}}.err
{{- end}}
{{if gt .LimitNOFILE -1 }}LimitNOFILE={{.LimitNOFILE}}{{end}}
{{if .Restart}}Restart={{.Restart}}{{end}}
{{if .SuccessExitStatus}}SuccessExitStatus={{.SuccessExitStatus}}{{end}}
{{if .Config.Option.KillMode}}KillMode={{.Config.Option.KillMode}}{{end}}
RestartSec=120
EnvironmentFile=-/etc/sysconfig/{{.Name}}
[Install]
WantedBy=multi-user.target
`
3 changes: 2 additions & 1 deletion internal/pkg/agent/install/uninstall.go
Original file line number Diff line number Diff line change
@@ -17,6 +17,8 @@ import (

"github.com/schollz/progressbar/v3"

"github.com/elastic/go-service"

"github.com/elastic/elastic-agent-libs/logp"
"github.com/elastic/elastic-agent/internal/pkg/agent/application/paths"
"github.com/elastic/elastic-agent/internal/pkg/agent/application/secret"
@@ -32,7 +34,6 @@ import (
"github.com/elastic/elastic-agent/pkg/core/logger"
"github.com/elastic/elastic-agent/pkg/features"
"github.com/elastic/elastic-agent/pkg/utils"
"github.com/elastic/go-service"
)

// Uninstall uninstalls persistently Elastic Agent on the system.