diff --git a/CHANGELOG.md b/CHANGELOG.md index b92969d5..60d227df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ ## Changelog ### v8.1.0-beta.2 (coming soon) +* prohibit restore when startup script is still running +* extend time before restart after restore is done * v8.1.0-beta.1 (14.04.2023) * enhance github actions * enhance log output of maintenance script on restore ([#333](https://github.com/buanet/ioBroker.docker/issues/333)) diff --git a/debian/scripts/iobroker_startup.sh b/debian/scripts/iobroker_startup.sh index 1ef3bdc9..2005c62c 100644 --- a/debian/scripts/iobroker_startup.sh +++ b/debian/scripts/iobroker_startup.sh @@ -143,9 +143,10 @@ if [[ -f /opt/.first_run ]]; then echo "PACKAGES is set, but OFFLINE_MODE is \"true\". Skipping Linux package installation." elif [[ "$packages" != "" ]]; then echo "PACKAGES is set. Installing the following additional Linux packages: ""$packages" - echo "$packages" > /opt/scripts/.docker_config/.packages +# echo "$packages" > /opt/scripts/.docker_config/.packages bash /opt/scripts/setup_packages.sh -install fi + echo ' ' # Register maintenance script echo -n 'Registering maintenance script as command... ' echo "alias maintenance=\'/opt/scripts/maintenance.sh\'" >> /root/.bashrc diff --git a/debian/scripts/maintenance.sh b/debian/scripts/maintenance.sh index 13f133d6..dc423bc3 100644 --- a/debian/scripts/maintenance.sh +++ b/debian/scripts/maintenance.sh @@ -38,6 +38,11 @@ maintenance_enabled() { [[ -f "$healthcheck" && "$(cat "$healthcheck")" == maintenance ]] } +# check status starting +check_starting() { + [[ -f "$healthcheck" && "$(cat "$healthcheck")" == starting ]] +} + # display maintenance status maintenance_status() { if maintenance_enabled; then @@ -221,6 +226,8 @@ restart_container() { # restore iobroker restore_iobroker() { echo 'You are now going to perform a restore of your iobroker.' + echo 'During the restore process, the container will automatically switch into maintenance mode and stop ioBroker.' + echo 'Depending on the restart policy, your container will be stopped or restarted automatically after the restore.' if [[ "$autoconfirm" != yes ]]; then local reply @@ -235,11 +242,17 @@ restore_iobroker() { echo 'This command was already confirmed by the -y or --yes option.' fi - echo -n 'Stopping ioBroker...' - stop_iob + if check_starting > /dev/null; then + echo "Startup script is still running." + echo "Please check container log and wait until ioBroker is sucessfully started." + echo "Then try again." + return 1 + fi - # fixing permission errors during restore - #chown -R $setuid:$setgid /opt/iobroker/backup + if ! maintenance_enabled > /dev/null; then + autoconfirm=yes + enable_maintenance + fi echo -n "Restoring ioBroker... " set +e @@ -263,8 +276,8 @@ restore_iobroker() { echo "!!!! You can view installation process by taking a look at ioBroker log. !!!!" echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" sleep 10 - echo 'Container will be stopped or restarted in 5 seconds...' - sleep 5 + echo 'Container will be stopped or restarted in 10 seconds...' + sleep 10 echo 'stopping' > "$healthcheck" pkill -u root } diff --git a/debian/scripts/setup_packages.sh b/debian/scripts/setup_packages.sh index 48fcd66e..4d6ddb6a 100644 --- a/debian/scripts/setup_packages.sh +++ b/debian/scripts/setup_packages.sh @@ -1,36 +1,69 @@ #!/bin/bash +# bash strict mode +set -euo pipefail + +# Reading ENV +set +u +packages=$PACKAGES +debug=$DEBUG +set -u + export DEBIAN_FRONTEND=noninteractive -if [ "$1" == "-install" ] -then - apt-get -q update >> /opt/scripts/setup_packages.log 2>&1 - packages=$(cat /opt/scripts/.docker_config/.packages) +check_package_preq() { + # check for influx packages + if [[ "$i" == "influxdb" || "$i" == "influxdb2-cli" ]]; then + # add influxdata repo keys + wget -qO- https://repos.influxdata.com/influxdata-archive_compat.key | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/influxdata-archive_compat.gpg > /dev/null + echo 'deb [signed-by=/etc/apt/trusted.gpg.d/influxdata-archive_compat.gpg] https://repos.influxdata.com/debian stable main' | sudo tee /etc/apt/sources.list.d/influxdata.list + apt-get -q update >> /opt/scripts/setup_packages.log 2>&1 + fi +} +check_package_validity() { + # check string for double spaces + while echo "$packages" | grep -q ' '; do + packages=$(echo "$packages" | sed 's/ / /g') + done + # remove packages when "influxdb" AND "influxdb2-cli" + if echo "$packages" | grep -qw "influxdb" && echo "$packages" | grep -qw "influxdb2-cli"; then + echo "PACKAGES includes influxdb AND influxdb2-cli." + echo "As installing both packages together is not possible, they will be skipped." + packages=$(echo "$packages" | sed 's/influxdb2-cli//g;s/influxdb//g') + # check string for double spaces again + while echo "$packages" | grep -q ' '; do + packages=$(echo "$packages" | sed 's/ / /g') + done + if [[ $debug == "true" ]]; then echo "[DEBUG] New list of packages: ""$packages"; fi + echo ' ' + fi +} + +if [[ "$1" == "-install" ]]; then echo ' ' + apt-get -q update >> /opt/scripts/setup_packages.log 2>&1 + check_package_validity for i in $packages; do - if [ "$(dpkg-query -W -f='${Status}' "$i" 2>/dev/null | grep -c "ok installed")" -eq 0 ]; - then - echo -n "$i is not installed. Installing... " - DEBIAN_FRONTEND=noninteractive apt-get -q -y install "$i" >> /opt/scripts/setup_packages.log 2>&1 - return=$? - if [[ "$return" -ne 0 ]]; then - echo "Failed." - echo "For more details see \"/opt/scripts/setup_packages.log\"." - echo ' ' - else - echo "Done." - fi + if ! dpkg -s "$i" >/dev/null 2>&1; then + echo -n "$i is not installed. Installing... " + check_package_preq >> /opt/scripts/setup_packages.log 2>&1 + if ! apt-get -q -y install "$i" >> /opt/scripts/setup_packages.log 2>&1; then + echo "Failed." + echo "For more details see \"/opt/scripts/setup_packages.log\"." else - echo "$i is already installed." + echo "Done." fi + else + echo "$i is already installed." + fi done -elif [ "$1" == "-update" ]; then +elif [[ "$1" == "-update" ]]; then echo -n "Updating Linux packages on first run... " apt-get -q update >> /opt/scripts/setup_packages.log 2>&1 - return=$? - apt-get -q -y upgrade >> /opt/scripts/setup_packages.log 2>&1 return1=$? - if [[ "$return" -ne 0 || "$return1" -ne 0 ]]; then + apt-get -q -y upgrade >> /opt/scripts/setup_packages.log 2>&1 + return2=$? + if [[ "$return1" -ne 0 || "$return2" -ne 0 ]]; then echo "Failed." echo "For more details see \"/opt/scripts/setup_packages.log\"." echo "Make sure the container has internet access to get the latest package updates." @@ -47,4 +80,4 @@ fi apt-get -qq autoclean -y && apt-get -qq autoremove && apt-get -qq clean rm -rf /tmp/* /var/tmp/* && rm -rf /root/.cache/* && rm -rf /var/lib/apt/lists/* && rm -f /opt/scripts/.docker_config/.packages -exit 0 +exit 0 \ No newline at end of file