Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Ingest Manager] Fix DEB\RPM packages #20986

Merged
merged 1 commit into from
Sep 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions dev-tools/packaging/packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,17 @@ shared:
source: build/golang-crossbuild/god-{{.GOOS}}-{{.Platform.Arch}}
mode: 0755
/usr/bin/{{.BeatName}}:
template: '{{ elastic_beats_dir }}/dev-tools/packaging/templates/linux/beatname.sh.tmpl'
template: '{{ elastic_beats_dir }}/dev-tools/packaging/templates/linux/elastic-agent.sh.tmpl'
mode: 0755
/lib/systemd/system/{{.BeatServiceName}}.service:
template: '{{ elastic_beats_dir }}/dev-tools/packaging/templates/linux/systemd.unit.tmpl'
template: '{{ elastic_beats_dir }}/dev-tools/packaging/templates/linux/elastic-agent.unit.tmpl'
mode: 0644
/etc/init.d/{{.BeatServiceName}}:
template: '{{ elastic_beats_dir }}/dev-tools/packaging/templates/{{.PackageType}}/init.sh.tmpl'
mode: 0755
/var/lib/{{.BeatName}}/data/{{.BeatName}}-{{ commit_short }}/{{.BeatName}}{{.BinaryExt}}:
source: build/golang-crossbuild/{{.BeatName}}-{{.GOOS}}-{{.Platform.Arch}}{{.BinaryExt}}
mode: 0644
mode: 0755
/var/lib/{{.BeatName}}/data/{{.BeatName}}-{{ commit_short }}/downloads/filebeat-{{ beat_version }}{{if .Snapshot}}-SNAPSHOT{{end}}-{{.GOOS}}-{{.AgentArchName}}.tar.gz:
source: '{{.AgentDropPath}}/filebeat-{{ beat_version }}{{if .Snapshot}}-SNAPSHOT{{end}}-{{.GOOS}}-{{.AgentArchName}}.tar.gz'
mode: 0644
Expand Down Expand Up @@ -806,6 +806,7 @@ specs:
'{{.BeatName}}{{.BinaryExt}}':
source: data/{{.BeatName}}-{{ commit_short }}/{{.BeatName}}{{.BinaryExt}}
symlink: true
mode: 0755

- os: darwin
types: [dmg]
Expand Down Expand Up @@ -838,6 +839,7 @@ specs:
/usr/share/{{.BeatName}}/bin/{{.BeatName}}{{.BinaryExt}}:
source: /var/lib/{{.BeatName}}/data/{{.BeatName}}-{{ commit_short }}/{{.BeatName}}{{.BinaryExt}}
symlink: true
mode: 0755

- os: linux
types: [docker]
Expand Down
11 changes: 11 additions & 0 deletions dev-tools/packaging/templates/linux/elastic-agent.sh.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

# Script to run {{.BeatName | title}} in foreground with the same path settings that
# the init script / systemd unit file would do.

exec /usr/share/{{.BeatName}}/bin/{{.BeatName}} \
--path.home /var/lib/{{.BeatName}} \
--path.config /etc/{{.BeatName}} \
--path.data /var/lib/{{.BeatName}}/data \
--path.logs /var/log/{{.BeatName}} \
"$@"
19 changes: 19 additions & 0 deletions dev-tools/packaging/templates/linux/elastic-agent.unit.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[Unit]
Description={{.Description}}
Documentation={{.URL}}
Wants=network-online.target
After=network-online.target

[Service]
{{ if ne .BeatUser "root" -}}
User={{ .BeatUser }}
Group={{ .BeatUser }}
{{- end }}
Environment="BEAT_LOG_OPTS="
Environment="BEAT_CONFIG_OPTS=-c /etc/{{.BeatName}}/{{.BeatName}}.yml"
Environment="BEAT_PATH_OPTS=--path.home /var/lib/{{.BeatName}} --path.config /etc/{{.BeatName}} --path.data /var/lib/{{.BeatName}}/data --path.logs /var/log/{{.BeatName}}"
ExecStart=/usr/share/{{.BeatName}}/bin/{{.BeatName}} --environment systemd $BEAT_LOG_OPTS $BEAT_CONFIG_OPTS $BEAT_PATH_OPTS
Restart=always

[Install]
WantedBy=multi-user.target
28 changes: 14 additions & 14 deletions x-pack/elastic-agent/pkg/agent/application/paths/paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"os"
"path/filepath"
"runtime"
"sync"

"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/config"
)
Expand All @@ -19,26 +20,18 @@ var (
dataPath string
logsPath string
serviceName string

overridesLoader sync.Once
)

func init() {
initialHome := initialHome()

var homePathVar, configPathVar, dataPathVar, logsPathVar string

fs := flag.CommandLine
fs.StringVar(&homePathVar, "path.home", initialHome, "Agent root path")
fs.StringVar(&configPathVar, "path.config", initialHome, "Config path is the directory Agent looks for its config file")
fs.StringVar(&dataPathVar, "path.data", filepath.Join(initialHome, "data"), "Data path contains Agent managed binaries")
fs.StringVar(&logsPathVar, "path.logs", initialHome, "Logs path contains Agent log output")

// avoid rewriting initialized values by flagSet later
homePath = homePathVar
configPath = configPathVar
dataPath = dataPathVar
logsPath = logsPathVar

getOverrides()
fs.StringVar(&homePath, "path.home", initialHome, "Agent root path")
fs.StringVar(&configPath, "path.config", initialHome, "Config path is the directory Agent looks for its config file")
fs.StringVar(&dataPath, "path.data", filepath.Join(initialHome, "data"), "Data path contains Agent managed binaries")
fs.StringVar(&logsPath, "path.logs", initialHome, "Logs path contains Agent log output")
}

// UpdatePaths update paths based on changes in paths file.
Expand Down Expand Up @@ -78,27 +71,34 @@ func getOverrides() {

// ServiceName return predefined service name if defined by initial call.
func ServiceName() string {
// needs to do this at this place because otherwise it will
// get overwritten by flags behavior.
overridesLoader.Do(getOverrides)
return serviceName
}

// Home returns a directory where binary lives
// Executable is not supported on nacl.
func Home() string {
overridesLoader.Do(getOverrides)
return homePath
}

// Config returns a directory where configuration file lives
func Config() string {
overridesLoader.Do(getOverrides)
return configPath
}

// Data returns the data directory for Agent
func Data() string {
overridesLoader.Do(getOverrides)
return dataPath
}

// Logs returns a the log directory for Agent
func Logs() string {
overridesLoader.Do(getOverrides)
return logsPath
}

Expand Down