From b30745f16635b149e56881aaf44aa07ec8d7d440 Mon Sep 17 00:00:00 2001 From: sed-i <82407168+sed-i@users.noreply.github.com> Date: Thu, 14 Nov 2024 16:33:19 -0500 Subject: [PATCH 1/3] Refactor to reduce errors --- make-classic.sh | 6 +----- snap/local/agent-wrapper.classic | 12 ++++++++++++ snap/local/{agent-wrapper => agent-wrapper.strict} | 0 snap/snapcraft.yaml | 2 +- 4 files changed, 14 insertions(+), 6 deletions(-) create mode 100755 snap/local/agent-wrapper.classic rename snap/local/{agent-wrapper => agent-wrapper.strict} (100%) diff --git a/make-classic.sh b/make-classic.sh index 99bf427..b85dbda 100755 --- a/make-classic.sh +++ b/make-classic.sh @@ -6,8 +6,4 @@ sed -i 's/CRAFT_PART_INSTALL/SNAPCRAFT_PART_INSTALL/g' snap/snapcraft.yaml sed -i '/libbpfcc/d' snap/snapcraft.yaml sed -i '/bpfcc-tools/d' snap/snapcraft.yaml yq -i 'del(.apps.grafana-agent.plugs) | del(.plugs)' snap/snapcraft.yaml -cat << "EOF" > snap/local/agent-wrapper -#!/bin/sh - -exec "${SNAP}/agent" -config.expand-env -config.file "/etc/grafana-agent.yaml" -EOF +sed -i 's/agent-wrapper.strict/agent-wrapper.classic/g' snap/snapcraft.yaml diff --git a/snap/local/agent-wrapper.classic b/snap/local/agent-wrapper.classic new file mode 100755 index 0000000..b92c7eb --- /dev/null +++ b/snap/local/agent-wrapper.classic @@ -0,0 +1,12 @@ +#!/bin/sh + +if [ "$(snapctl get reporting-enabled)" = "0" ] +then + echo "Launched with reporting disabled" | systemd-cat + REPORTING_ARG="-disable-reporting" +else + echo "Launched with reporting enabled" | systemd-cat + REPORTING_ARG="" +fi + +exec "${SNAP}/agent" -config.expand-env -config.file "${CONFIG_FILE}" "${REPORTING_ARG}" diff --git a/snap/local/agent-wrapper b/snap/local/agent-wrapper.strict similarity index 100% rename from snap/local/agent-wrapper rename to snap/local/agent-wrapper.strict diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 89ab43a..657e43b 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -51,7 +51,7 @@ parts: source: ./snap/local source-type: local override-build: | - cp agent-wrapper $CRAFT_PART_INSTALL/ + cp agent-wrapper.strict $CRAFT_PART_INSTALL/agent-wrapper grafana-agent: plugin: go source: https://github.com/grafana/agent From a6528beadf34359f33d908e04d2726df6c343ce8 Mon Sep 17 00:00:00 2001 From: sed-i <82407168+sed-i@users.noreply.github.com> Date: Thu, 14 Nov 2024 17:09:27 -0500 Subject: [PATCH 2/3] Fixes --- make-classic.sh | 4 ---- snap/local/agent-wrapper.classic | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/make-classic.sh b/make-classic.sh index b85dbda..ad4ea18 100755 --- a/make-classic.sh +++ b/make-classic.sh @@ -1,9 +1,5 @@ #!/bin/sh -sed -i 's/base: core22/base: core20/g' snap/snapcraft.yaml sed -i 's/confinement: strict/confinement: classic/g' snap/snapcraft.yaml -sed -i 's/CRAFT_PART_INSTALL/SNAPCRAFT_PART_INSTALL/g' snap/snapcraft.yaml -sed -i '/libbpfcc/d' snap/snapcraft.yaml -sed -i '/bpfcc-tools/d' snap/snapcraft.yaml yq -i 'del(.apps.grafana-agent.plugs) | del(.plugs)' snap/snapcraft.yaml sed -i 's/agent-wrapper.strict/agent-wrapper.classic/g' snap/snapcraft.yaml diff --git a/snap/local/agent-wrapper.classic b/snap/local/agent-wrapper.classic index b92c7eb..b4d7907 100755 --- a/snap/local/agent-wrapper.classic +++ b/snap/local/agent-wrapper.classic @@ -9,4 +9,4 @@ else REPORTING_ARG="" fi -exec "${SNAP}/agent" -config.expand-env -config.file "${CONFIG_FILE}" "${REPORTING_ARG}" +exec "${SNAP}/agent" -config.expand-env -config.file "/etc/grafana-agent.yaml" "${REPORTING_ARG}" From cfd219997f7fcbde139812c351cd30b47cff7ee5 Mon Sep 17 00:00:00 2001 From: sed-i <82407168+sed-i@users.noreply.github.com> Date: Fri, 15 Nov 2024 00:48:05 -0500 Subject: [PATCH 3/3] Revert to building classic on core20 --- make-classic.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/make-classic.sh b/make-classic.sh index ad4ea18..22f3f6e 100755 --- a/make-classic.sh +++ b/make-classic.sh @@ -1,5 +1,11 @@ #!/bin/sh +# The classic snap needs to be built on core20 because of libc6 dependency: +# A core22 snap needs glibc 2.32+, but in a 20.04 charm we have glibc 2.31. +sed -i 's/base: core22/base: core20/g' snap/snapcraft.yaml sed -i 's/confinement: strict/confinement: classic/g' snap/snapcraft.yaml +sed -i 's/CRAFT_PART_INSTALL/SNAPCRAFT_PART_INSTALL/g' snap/snapcraft.yaml +sed -i '/libbpfcc/d' snap/snapcraft.yaml +sed -i '/bpfcc-tools/d' snap/snapcraft.yaml yq -i 'del(.apps.grafana-agent.plugs) | del(.plugs)' snap/snapcraft.yaml sed -i 's/agent-wrapper.strict/agent-wrapper.classic/g' snap/snapcraft.yaml