2019-11-25 13:11:18 +01:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2020-03-26 17:50:12 +01:00
|
|
|
current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
2020-05-26 19:32:46 +02:00
|
|
|
source $current_dir/prints.sh
|
2020-03-26 17:50:12 +01:00
|
|
|
source $current_dir/utils.sh # Get utils functions.
|
2019-11-25 13:11:18 +01:00
|
|
|
|
|
|
|
set -eo pipefail
|
|
|
|
|
|
|
|
# trap any error, and mark it as a system failure.
|
|
|
|
trap "exit $SYSTEM_FAILURE_EXIT_CODE" ERR
|
|
|
|
|
|
|
|
start_container () {
|
2023-05-16 15:54:24 +02:00
|
|
|
if ! lxc info "$CONTAINER_IMAGE" >/dev/null 2>/dev/null ; then
|
|
|
|
warn 'Container not found, copying it from the prebuilt image'
|
2023-05-17 20:18:34 +02:00
|
|
|
if ! lxc info "$BASE_IMAGE" &>/dev/null || ! lxc info "$BASE_IMAGE" | grep -q "$CURRENT_VERSION-$SNAPSHOT_NAME"
|
2023-05-16 15:54:24 +02:00
|
|
|
then
|
|
|
|
error "$BASE_IMAGE not found, please rebuild with rebuild_all.sh"
|
|
|
|
# Inform GitLab Runner that this is a system failure, so it
|
|
|
|
# should be retried.
|
|
|
|
exit $SYSTEM_FAILURE_EXIT_CODE
|
|
|
|
fi
|
|
|
|
lxc copy "$BASE_IMAGE" "$CONTAINER_IMAGE"
|
2019-11-26 14:15:34 +01:00
|
|
|
fi
|
2023-05-17 20:18:34 +02:00
|
|
|
# Stop the container if it's running
|
|
|
|
if [ "$(lxc info $CONTAINER_IMAGE | grep Status | awk '{print tolower($2)}')" == "running" ]; then
|
|
|
|
lxc stop $CONTAINER_IMAGE
|
|
|
|
fi
|
2019-11-26 14:01:29 +01:00
|
|
|
|
2023-05-16 15:54:24 +02:00
|
|
|
info "Debian version: $DEBIAN_VERSION, YunoHost version: $CURRENT_VERSION, Image used: $BASE_IMAGE, Snapshot: $SNAPSHOT_NAME"
|
2021-03-10 10:43:18 +01:00
|
|
|
|
2023-05-17 15:10:29 +02:00
|
|
|
restore_snapshot "$CONTAINER_IMAGE" "$CURRENT_VERSION" "$SNAPSHOT_NAME"
|
2020-03-19 23:52:39 +01:00
|
|
|
|
2023-05-22 12:57:17 +02:00
|
|
|
# Unset the mac address to ensure the copy will get a new one and will be able to get new IP
|
|
|
|
lxc config unset "$CONTAINER_IMAGE" volatile.eth0.hwaddr 2> /dev/null
|
|
|
|
|
2023-05-16 18:11:52 +02:00
|
|
|
lxc start $CONTAINER_IMAGE
|
2019-12-23 11:36:31 +01:00
|
|
|
|
2023-05-16 15:54:24 +02:00
|
|
|
wait_container $CONTAINER_IMAGE
|
2019-11-25 13:11:18 +01:00
|
|
|
}
|
|
|
|
|
2023-05-16 15:54:24 +02:00
|
|
|
info "Starting $CONTAINER_IMAGE"
|
2019-11-25 13:11:18 +01:00
|
|
|
|
|
|
|
start_container
|
2020-05-26 19:36:55 +02:00
|
|
|
|
2023-05-16 15:54:24 +02:00
|
|
|
info "$CONTAINER_IMAGE started properly"
|