From 8437095445979156f54ecd9448e69d5c5e002a4f Mon Sep 17 00:00:00 2001 From: Alex K <8418476+fearful-symmetry@users.noreply.github.com> Date: Wed, 16 Dec 2020 08:29:55 -0800 Subject: [PATCH] [build] add MADVDONTNEED to builds (#23001) * add MADVDONTNEED to builds * delay setting godebug in init scripts (cherry picked from commit 8a68dc9f5843911832caae8f724c446f9ac688d6) --- dev-tools/packaging/templates/deb/elastic-agent.init.sh.tmpl | 4 ++++ dev-tools/packaging/templates/deb/init.sh.tmpl | 4 ++++ .../packaging/templates/docker/Dockerfile.elastic-agent.tmpl | 1 + dev-tools/packaging/templates/docker/Dockerfile.tmpl | 1 + dev-tools/packaging/templates/linux/elastic-agent.unit.tmpl | 1 + dev-tools/packaging/templates/linux/systemd.unit.tmpl | 1 + dev-tools/packaging/templates/rpm/elastic-agent.init.sh.tmpl | 2 ++ dev-tools/packaging/templates/rpm/init.sh.tmpl | 2 ++ 8 files changed, 16 insertions(+) diff --git a/dev-tools/packaging/templates/deb/elastic-agent.init.sh.tmpl b/dev-tools/packaging/templates/deb/elastic-agent.init.sh.tmpl index 66ef59b349a..4ee5f6c2e5a 100644 --- a/dev-tools/packaging/templates/deb/elastic-agent.init.sh.tmpl +++ b/dev-tools/packaging/templates/deb/elastic-agent.init.sh.tmpl @@ -24,12 +24,16 @@ BEAT_USER="{{.BeatUser}}" WRAPPER_ARGS="-r / -n -p $PIDFILE" SCRIPTNAME=/etc/init.d/{{.ServiceName}} + # Exit if the package is not installed [ -x "$DAEMON" ] || exit 0 # Read configuration variable file if it is present [ -r /etc/default/{{.ServiceName}} ] && . /etc/default/{{.ServiceName}} +DEFAULT_GODEBUG="madvdontneed=1" +export GODEBUG=${GODEBUG-$DEFAULT_GODEBUG} + [ "$BEAT_USER" != "root" ] && WRAPPER_ARGS="$WRAPPER_ARGS -u $BEAT_USER" USER_WRAPPER="su" USER_WRAPPER_ARGS="$BEAT_USER -c" diff --git a/dev-tools/packaging/templates/deb/init.sh.tmpl b/dev-tools/packaging/templates/deb/init.sh.tmpl index 2105d8de3d5..90d026dd0ba 100644 --- a/dev-tools/packaging/templates/deb/init.sh.tmpl +++ b/dev-tools/packaging/templates/deb/init.sh.tmpl @@ -25,12 +25,16 @@ BEAT_USER="{{.BeatUser}}" WRAPPER_ARGS="-r / -n -p $PIDFILE" SCRIPTNAME=/etc/init.d/{{.ServiceName}} + # Exit if the package is not installed [ -x "$DAEMON" ] || exit 0 # Read configuration variable file if it is present [ -r /etc/default/{{.ServiceName}} ] && . /etc/default/{{.ServiceName}} +DEFAULT_GODEBUG="madvdontneed=1" +export GODEBUG=${GODEBUG-$DEFAULT_GODEBUG} + [ "$BEAT_USER" != "root" ] && WRAPPER_ARGS="$WRAPPER_ARGS -u $BEAT_USER" USER_WRAPPER="su" USER_WRAPPER_ARGS="$BEAT_USER -c" diff --git a/dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl b/dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl index b171d0c08a0..508cbd09da2 100644 --- a/dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl +++ b/dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl @@ -67,6 +67,7 @@ LABEL \ ENV ELASTIC_CONTAINER "true" ENV PATH={{ $beatHome }}:$PATH +ENV GODEBUG="madvdontneed=1" # Add an init process, check the checksum to make sure it's a match RUN set -e ; \ diff --git a/dev-tools/packaging/templates/docker/Dockerfile.tmpl b/dev-tools/packaging/templates/docker/Dockerfile.tmpl index c63b5981aef..b0d5122adbe 100644 --- a/dev-tools/packaging/templates/docker/Dockerfile.tmpl +++ b/dev-tools/packaging/templates/docker/Dockerfile.tmpl @@ -59,6 +59,7 @@ LABEL \ ENV ELASTIC_CONTAINER "true" ENV PATH={{ $beatHome }}:$PATH +ENV GODEBUG="madvdontneed=1" # Add an init process, check the checksum to make sure it's a match RUN set -e ; \ diff --git a/dev-tools/packaging/templates/linux/elastic-agent.unit.tmpl b/dev-tools/packaging/templates/linux/elastic-agent.unit.tmpl index 5fa0b1436b0..c7aa5ac2a17 100644 --- a/dev-tools/packaging/templates/linux/elastic-agent.unit.tmpl +++ b/dev-tools/packaging/templates/linux/elastic-agent.unit.tmpl @@ -9,6 +9,7 @@ After=network-online.target User={{ .BeatUser }} Group={{ .BeatUser }} {{- end }} +Environment="GODEBUG='madvdontneed=1'" Environment="BEAT_CONFIG_OPTS=-c /etc/{{.BeatName}}/{{.BeatName}}.yml" ExecStart=/usr/bin/{{.BeatName}} run --environment systemd $BEAT_CONFIG_OPTS Restart=always diff --git a/dev-tools/packaging/templates/linux/systemd.unit.tmpl b/dev-tools/packaging/templates/linux/systemd.unit.tmpl index ab0d1bcab5f..367f9e3532f 100644 --- a/dev-tools/packaging/templates/linux/systemd.unit.tmpl +++ b/dev-tools/packaging/templates/linux/systemd.unit.tmpl @@ -9,6 +9,7 @@ After=network-online.target User={{ .BeatUser }} Group={{ .BeatUser }} {{- end }} +Environment="GODEBUG='madvdontneed=1'" Environment="BEAT_LOG_OPTS=" Environment="BEAT_CONFIG_OPTS=-c /etc/{{.BeatName}}/{{.BeatName}}.yml" Environment="BEAT_PATH_OPTS=--path.home /usr/share/{{.BeatName}} --path.config /etc/{{.BeatName}} --path.data /var/lib/{{.BeatName}} --path.logs /var/log/{{.BeatName}}" diff --git a/dev-tools/packaging/templates/rpm/elastic-agent.init.sh.tmpl b/dev-tools/packaging/templates/rpm/elastic-agent.init.sh.tmpl index 54d26729a5d..eb5a96e878d 100644 --- a/dev-tools/packaging/templates/rpm/elastic-agent.init.sh.tmpl +++ b/dev-tools/packaging/templates/rpm/elastic-agent.init.sh.tmpl @@ -32,6 +32,8 @@ wrapperopts="-r / -n -p $pidfile" user_wrapper="su" user_wrapperopts="$beat_user -c" RETVAL=0 +DEFAULT_GODEBUG="madvdontneed=1" +export GODEBUG=${GODEBUG-$DEFAULT_GODEBUG} # Source function library. . /etc/rc.d/init.d/functions diff --git a/dev-tools/packaging/templates/rpm/init.sh.tmpl b/dev-tools/packaging/templates/rpm/init.sh.tmpl index 2f6dab67b28..bfdf44fff9c 100644 --- a/dev-tools/packaging/templates/rpm/init.sh.tmpl +++ b/dev-tools/packaging/templates/rpm/init.sh.tmpl @@ -33,6 +33,8 @@ wrapperopts="-r / -n -p $pidfile" user_wrapper="su" user_wrapperopts="$beat_user -c" RETVAL=0 +DEFAULT_GODEBUG="madvdontneed=1" +export GODEBUG=${GODEBUG-$DEFAULT_GODEBUG} # Source function library. . /etc/rc.d/init.d/functions