Skip to content

Commit

Permalink
Merge pull request #340 from buanet/feature/issue-329/add-influx-repo
Browse files Browse the repository at this point in the history
Feature/issue 329/add influx repo
  • Loading branch information
buanet authored Apr 26, 2023
2 parents 0f59839 + 7a45595 commit 721c108
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 29 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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))
Expand Down
3 changes: 2 additions & 1 deletion debian/scripts/iobroker_startup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 19 additions & 6 deletions debian/scripts/maintenance.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
}
Expand Down
77 changes: 55 additions & 22 deletions debian/scripts/setup_packages.sh
Original file line number Diff line number Diff line change
@@ -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."
Expand All @@ -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

0 comments on commit 721c108

Please sign in to comment.