File: //snap/docker/3613/meta/hooks/configure
#!/bin/bash
set -eux
HOOK_LOG="${SNAP_COMMON}/hooks/${SNAP_REVISION}/$(basename "$0").log" && mkdir -p "${HOOK_LOG%/*}"
exec &> >(tee -a "${HOOK_LOG}")
. "${SNAP}/usr/share/nvidia-container-toolkit/lib"
# If the user unset the data-root, set it to the default
data_root="$(snapctl get data-root)"
if [ -z "$data_root" ] ; then
snapctl set data-root="${DEFAULT_DATA_ROOT}"
fi
# Flag to trigger service restart if any condition requires it #
SVC_RESTART=false
if nvidia_support_disabled; then
# Remove nvidia runtime config, if it exists #
jq -r 'del(.runtimes.nvidia)' "${SNAP_DATA}/config/daemon.json" > "${SNAP_DATA}/config/daemon.json.new"
# If it was removed [ there was a change ], copy in the new config, remove CDI config, and set service restart flag #
if ! cmp "${SNAP_DATA}/config/daemon.json"{,.new} >/dev/null ; then
mv "${SNAP_DATA}/config/daemon.json"{.new,}
rm -f "${SNAP_DATA}/etc/cdi/nvidia.yaml"
rm -f "${SNAP_DATA}/etc/nvidia-container-runtime/config.toml"
SVC_RESTART=true
fi
fi
# Restart services if required #
# If oneshot services are inactive they don't respond to restart, so stop/start #
if $SVC_RESTART ; then
snapctl stop "${SNAP_NAME}"
snapctl start "${SNAP_NAME}"
# Otherwise, just restart the nvidia-container-toolkit #
else
snapctl stop "${SNAP_NAME}.nvidia-container-toolkit"
snapctl start "${SNAP_NAME}.nvidia-container-toolkit"
fi