#!/bin/bash #================================================= # LXD HELPERS #================================================= ynh_lxc_stop () { local container_to_stop=$1 # (We also use timeout 30 in front of the command because sometime lxc # commands can hang forever despite the --timeout >_>...) timeout 30 lxc stop --timeout 15 $container_to_stop 2>/dev/null # If the command times out, then add the option --force if [ $? -eq 124 ]; then timeout 30 lxc stop --timeout 15 $container_to_stop --force 2>/dev/null fi } ynh_lxc_snapshot_exists () { local snapname=$1 lxc list --format json \ | jq -e --arg LXC_NAME $LXC_NAME --arg snapname $snapname \ '.[] | select(.name==$LXC_NAME) | .snapshots[] | select(.name==$snapname)' \ >/dev/null } ynh_lxc_snapshot_load () { local snapname=$1 log_debug "Loading snapshot $snapname ..." # Remove swap files before restoring the snapshot. CLEAN_SWAPFILES ynh_lxc_stop $LXC_NAME lxc restore $LXC_NAME $snapname lxc start $LXC_NAME _LXC_START_AND_WAIT $LXC_NAME }