files:
plugin: dump
source-type: local
source: ./files
organize:
service-arguments: $SNAPCRAFT_PRIME/etc/default/polkadot
But the file ends up in ‘/snap/polkadot/current/root/parts/files/install/etc/default/polkadot’
I would like it to be found in a much better location. Like somewhere similar to /etc/default/polkadot which would make it easier to find for some poor bastard trying to understand the snap.
Even more generally, I would like to know how others, more experts, are producing startup-parameter handling such as to allow someone to reconfigure it dynamically. I feel I’m doing guess-work here (as usual with me snapping).
In the end, I ended up mimicking the LXD charm buy creating a wrapper script as part of the app start command for my service that looks for the existence of the service-arguments file, creates it or uses it as input for start-up parameters. The “parts” and “apps” looks something like this:
#!/bin/sh
set -eu
echo "=> Preparing the system (${SNAP_REVISION})"
# shellcheck disable=SC2155
export SNAP_CURRENT="$(realpath "${SNAP}/..")/current"
# Create a config if its missing.
if [ ! -f "${SNAP_COMMON}/service-arguments" ]; then
echo "==> Creating basic service argument file ${SNAP_COMMON}/service-arguments"
echo "--name=Dwellir" > "${SNAP_COMMON}/service-arguments"
chmod 0644 "${SNAP_COMMON}/service-arguments"
fi
# Read the system wide configuration file
echo "=> Using service argument file: ${SNAP_COMMON}/service-arguments"
SERVICE_ARGS_FILE="$SNAP_COMMON/service-arguments"
SERVICE_ARGS=$(cat "$SERVICE_ARGS_FILE")
# Start the service with the specified parameters
POLKADOT="${SNAP}/bin/polkadot"
exec "${POLKADOT}" $SERVICE_ARGS
The arguments in the “service-arguments” file are space separated.
Attribution to the LXD people that has a really good example of a snap. I will use that future reference.