generated from snapcrafters/snap-repo-template
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* use core22 and patchelf * Consolidate agent wrapper script
- Loading branch information
Showing
5 changed files
with
54 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,9 @@ | ||
#!/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 | ||
|
||
# With the classic snap we need to patchelf for the core22 snap to run on a 20.04 charm, | ||
# because of the libc6 dependency, otherwise the app will fail to start, complaining | ||
# about needing glibc 2.32+. | ||
yq -i '.parts.grafana-agent."build-attributes" += ["enable-patchelf"]' snap/snapcraft.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/bin/sh | ||
|
||
# Get config option | ||
if [ "$(snapctl get reporting-enabled)" = "0" ] | ||
then | ||
echo "Launching with reporting disabled" | systemd-cat | ||
REPORTING_ARG="-disable-reporting" | ||
else | ||
echo "Launching with reporting enabled" | systemd-cat | ||
REPORTING_ARG="" | ||
fi | ||
|
||
|
||
launch_classic() { | ||
|
||
echo "Launching with config from the host filesystem" | systemd-cat | ||
exec "${SNAP}/agent" -config.expand-env -config.file "/etc/grafana-agent.yaml" "${REPORTING_ARG}" | ||
|
||
} | ||
|
||
|
||
launch_strict() { | ||
|
||
IS_CONNECTED=$(snapctl is-connected etc-grafana-agent; echo $?) | ||
|
||
if [ "${IS_CONNECTED}" = "0" ] && [ -r /etc/grafana-agent.yaml ] | ||
then | ||
echo "Launching with config from the host filesystem" | systemd-cat | ||
CONFIG_FILE="/etc/grafana-agent.yaml" | ||
else | ||
echo "Launching with minimal default config from the snap" | systemd-cat | ||
CONFIG_FILE="$SNAP_DATA/etc/grafana-agent.yaml" | ||
fi | ||
|
||
exec "${SNAP}/agent" -config.expand-env -config.file "${CONFIG_FILE}" "${REPORTING_ARG}" | ||
|
||
} | ||
|
||
|
||
# Detect confinement type | ||
# https://forum.snapcraft.io/t/reliable-way-of-detecting-snap-confinement-mode/8896/4 | ||
IS_CLASSIC=$(grep -qxF "confinement: classic" "$SNAP/meta/snap.yaml"; echo $?) | ||
if [ "${IS_CLASSIC}" = "0" ] | ||
then | ||
launch_classic | ||
else | ||
launch_strict | ||
fi |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters