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 66ef59b349ab..4ee5f6c2e5a8 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 2105d8de3d57..90d026dd0baa 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 add0928a0c1e..419cd10923ef 100644 --- a/dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl +++ b/dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl @@ -65,6 +65,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 c63b5981aefe..b0d5122adbe5 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 5fa0b1436b0b..c7aa5ac2a173 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 ab0d1bcab5f0..367f9e3532f6 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 54d26729a5d5..eb5a96e878d2 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 2f6dab67b283..bfdf44fff9c6 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