enhance startup script logging

This commit is contained in:
buanet
2022-06-14 09:20:14 +02:00
parent b8c67b7149
commit 2b3e6541cf
2 changed files with 53 additions and 69 deletions

View File

@@ -1,15 +1,16 @@
## Changelog
### v6.2.0-beta.1 (2022-06-13)
### v6.2.0-beta.1 (coming soon)
* rewrite maintenance script ([#243 by @agross](https://github.com/buanet/ioBroker.docker/pull/243))
* optimize container shutdown on SIGTERM ([as requested with #264 by @buzz0r](https://github.com/buanet/ioBroker.docker/pull/264))
* enhance container shutdown on SIGTERM ([as requested with #264 by @buzz0r](https://github.com/buanet/ioBroker.docker/pull/264))
* enhance startup script logging
### v6.1.0 (2022-03-01)
* v6.1.0-beta.2 (2022-02-11)
* fix -kbn option in maintenance script
* optimize shutdown/ prevent warnings on upgrade
* enhance shutdown/ prevent warnings on upgrade
* remove hostname check for multihost slave
* optimize startup script logging
* add breaks and optimize maintenance script (fixes [#233](https://github.com/buanet/ioBroker.docker/issues/233))
* enhance startup script logging
* add breaks and enhance maintenance script (fixes [#233](https://github.com/buanet/ioBroker.docker/issues/233))
* v6.1.0-beta.1 (2021-12-23)
* some more corrections in maintenance script ([#232 by @agross](https://github.com/buanet/ioBroker.docker/pull/232))
* add auto confirm parameter to upgrade function in maintenance script ([#229 by @thost96](https://github.com/buanet/ioBroker.docker/pull/229))
@@ -36,7 +37,7 @@
* v5.2.0-beta3 (2021-09-04)
* reducing layers in dockerfile
* making hostname check mandatory for startup
* optimize startup log
* enhance startup log
* v5.2.0-beta2 (2021-08-28)
* redesign maintenance script
* switching amd64 base image to debian bullseye slim
@@ -51,7 +52,7 @@
* added expose for default admin ui port (fixes [#172](https://github.com/buanet/ioBroker.docker/issues/172))
* added short form for maintenance script
* v5.2.0-beta (2021-04-02)
* some renaming to optimize automated build
* some renaming to enhance automated build
* changes in versioning
* delete travis for automated build
@@ -66,7 +67,7 @@
* fixing backup detection in startup script
* fixing permission issue on iobroker restored
* extended Logging
* optimize multihost support
* enhance multihost support
### v5.0.0 (2020-06-29)
* v4.2.4-beta (2020-06-23)

View File

@@ -58,7 +58,7 @@ if [ "$multihost" != "" ]; then echo -n "----- " && echo -n "
if [ "$objectsdbhost" != "" ]; then echo -n "----- " && echo -n "$(printf "%-20s %-28s" IOB_OBJECTSDB_HOST: $objectsdbhost)" && echo " -----"; fi
if [ "$objectsdbport" != "" ]; then echo -n "----- " && echo -n "$(printf "%-20s %-28s" IOB_OBJECTSDB_PORT: $objectsdbport)" && echo " -----"; fi
if [ "$objectsdbtype" != "" ]; then echo -n "----- " && echo -n "$(printf "%-20s %-28s" IOB_OBJECTSDB_TYPE: $objectsdbtype)" && echo " -----"; fi
if [ "$packages" != "" ]; then echo -n "----- " && echo -n "$(printf "%-20s %-28s" PACKAGES: $packages)" && echo " -----"; fi
if [ "$packages" != "" ]; then echo -n "----- " && echo -n "$(printf "%-20s %-28s" PACKAGES: "$packages")" && echo " -----"; fi
if [ "$setgid" != "" ]; then echo -n "----- " && echo -n "$(printf "%-20s %-28s" SETGID: $setgid)" && echo " -----"; fi
if [ "$setuid" != "" ]; then echo -n "----- " && echo -n "$(printf "%-20s %-28s" SETUID: $setuid)" && echo " -----"; fi
if [ "$statesdbhost" != "" ]; then echo -n "----- " && echo -n "$(printf "%-20s %-28s" IOB_STATESDB_HOST: $statesdbhost)" && echo " -----"; fi
@@ -95,7 +95,7 @@ then
fi
if [ "$packages" != "" ]
then
echo "Installing additional packages is set by ENV."
echo "Installing additional packages is set by ENV..."
echo "Checking the following Packages:" $packages"..."
echo $packages > /opt/scripts/.docker_config/.packages
bash /opt/scripts/setup_packages.sh -install
@@ -105,10 +105,10 @@ then
if [ $(cat /etc/group | grep 'iobroker:' | cut -d':' -f3) != $setgid ] || [ $(cat /etc/passwd | grep 'iobroker:' | cut -d':' -f3) != $setuid ]
then
echo "Different UID and/ or GID is set by ENV."
echo "Changing UID to "$setuid" and GID to "$setgid"..."
echo -n "Changing UID to "$setuid" and GID to "$setgid"... "
usermod -u $setuid iobroker
groupmod -g $setgid iobroker
echo "Done."
echo 'Done.'
echo ' '
fi
else
@@ -119,7 +119,6 @@ fi
# Change directory for next steps
cd /opt/iobroker
#####
# STEP 2 - Detecting ioBroker-Installation
#####
@@ -131,9 +130,9 @@ echo ' '
if [ `find /opt/iobroker -type f | wc -l` -lt 1 ]
then
echo "There is no data detected in /opt/iobroker."
echo "Restoring initial ioBroker installation..."
echo -n "Restoring initial ioBroker installation... "
tar -xf /opt/initial_iobroker.tar -C /
echo "Done."
echo 'Done.'
elif [ -f /opt/iobroker/iobroker ]
then
echo "Existing installation of ioBroker detected in /opt/iobroker."
@@ -147,17 +146,17 @@ then
exit 1
else
echo "IoBroker backup file detected in /opt/iobroker."
echo "Preparing restore..."
echo -n "Preparing restore... "
mv /opt/iobroker/*.tar.gz /opt/
tar -xf /opt/initial_iobroker.tar -C /
mkdir /opt/iobroker/backups
mv /opt/*.tar.gz /opt/iobroker/backups/
# fixing permission errors during restore
chown -R $setuid:$setgid /opt/iobroker
echo "Done."
echo "Restoring ioBroker..."
echo 'Done.'
echo -n "Restoring ioBroker... "
bash iobroker restore 0 > /opt/iobroker/log/restore.log 2>&1
echo "Done."
echo 'Done.'
echo ' '
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "!!!!! IMPORTANT NOTE !!!!!"
@@ -175,7 +174,6 @@ else
fi
echo ' '
#####
# STEP 3 - Checking ioBroker-Installation
#####
@@ -185,31 +183,30 @@ echo "$(printf -- '-%.0s' {1..80})"
echo ' '
# (Re)Setting permissions to "/opt/iobroker" and "/opt/scripts"
echo "(Re)Setting folder permissions (This might take a while! Please be patient!)..."
echo -n "(Re)Setting folder permissions (This might take a while! Please be patient!)... "
chown -R $setuid:$setgid /opt/iobroker
chown -R $setuid:$setgid /opt/scripts
echo "Done."
echo 'Done.'
echo ' '
# Backing up original iobroker-file and changing sudo to gosu
echo "Fixing \"sudo-bug\" by replacing sudo in iobroker with gosu..."
echo -n "Fixing \"sudo-bug\" by replacing sudo in iobroker with gosu... "
cp -a /opt/iobroker/iobroker /opt/iobroker/iobroker.bak
chmod 755 /opt/iobroker/iobroker
sed -i 's/sudo -H -u/gosu/g' /opt/iobroker/iobroker
echo "Done."
echo 'Done.'
echo ' '
# checking hostname in ioBroker to match container hostname
if [ $(bash iobroker object get system.adapter.admin.0 --pretty | grep -oP '(?<="host": ")[^"]*') != $(hostname) ] && [ "$multihost" != "slave" ]
then
echo "Hostname in ioBroker does not match the hostname of this container."
echo "Updating hostname to " $(hostname)"..."
echo -n "Updating hostname to " $(hostname)"... "
bash iobroker host $(iobroker object get system.adapter.admin.0 --pretty | grep -oP '(?<="host": ")[^"]*')
echo "Done."
echo 'Done.'
echo ' '
fi
#####
# STEP 4 - Setting up prerequisites for some ioBroker-adapters
#####
@@ -222,21 +219,19 @@ echo "Some adapters have special requirements/ settings which can be activated b
echo "For more information see ioBroker Docker Image Docs (https://docs.buanet.de/iobroker-docker-image/docs/)."
echo ' '
# Checking ENV for Adminport
if [ "$adminport" != "" ]
then
if [ "$adminport" != $(bash iobroker object get system.adapter.admin.0 --pretty | grep -oP '(?<="port": )[^,]*') ]
then
echo "Adminport set by ENV does not match port configured in ioBroker installation."
echo "Setting Adminport to \""$adminport"\"..."
echo -n "Setting Adminport to \""$adminport"\"... "
bash iobroker set admin.0 --port $adminport
echo "Done."
echo 'Done.'
echo ' '
fi
fi
# Checking ENV for AVAHI
if [ "$avahi" != "" ]
then
@@ -250,7 +245,6 @@ then
fi
fi
# Checking ENV for Z-WAVE
if [ "$zwave" != "" ]
then
@@ -264,7 +258,6 @@ then
fi
fi
# checking ENV for USBDEVICES
if [ "$usbdevices" != "" ]
then
@@ -274,29 +267,27 @@ then
IFS=';' read -ra devicearray <<< "$usbdevices"
for i in "${devicearray[@]}"
do
echo "Setting permissions for" $i"..."
echo -n "Setting permissions for" $i"... "
chown root:dialout $i
chmod g+rw $i
done
echo "Done."
echo 'Done.'
echo ' '
fi
fi
# Checking ENV for multihost setup
if [ "$multihost" != "" ]
then
echo "Checking Multihost Setup..."
echo ' '
echo "Checking multihost setup..."
# Configuring objects db host
if [ "$multihost" = "master" ] && [ "$objectsdbtype" = "" ] && [ "$objectsdbhost" = "" ] && [ "$objectsdbport" = "" ]
then
echo "Multihost is set as \"master\" by ENV and no external objects db is set."
echo "Setting host of objects db to \"0.0.0.0\" to allow external communication..."
echo -n "Setting host of objects db to \"0.0.0.0\" to allow external communication... "
jq --arg objectsdbhost "0.0.0.0" '.objects.host = $objectsdbhost' /opt/iobroker/iobroker-data/iobroker.json > /opt/iobroker/iobroker-data/iobroker.json.tmp && mv /opt/iobroker/iobroker-data/iobroker.json.tmp /opt/iobroker/iobroker-data/iobroker.json
chown -R $setuid:$setgid /opt/iobroker/iobroker-data/iobroker.json && chmod 674 /opt/iobroker/iobroker-data/iobroker.json
echo "Done."
echo 'Done.'
elif [ "$multihost" = "master" ] && [ "$objectsdbhost" = "127.0.0.1" ]
then
echo "Multihost is set as \"master\" by ENV. But objects db host is set to \"127.0.0.1\" by ENV too."
@@ -323,16 +314,15 @@ then
echo "For more information see ioBroker Docker Image Docs (https://docs.buanet.de/iobroker-docker-image/docs/)."
exit 1
fi
echo ' '
#Configuring states db host
# Configuring states db host
if [ "$multihost" = "master" ] && [ "$statesdbtype" = "" ] && [ "$statesdbhost" = "" ] && [ "$statesdbport" = "" ]
then
echo "Multihost is set as \"master\" by ENV and no external states db is set."
echo "Setting host of states db to \"0.0.0.0\" to allow external communication..."
echo -n "Setting host of states db to \"0.0.0.0\" to allow external communication... "
jq --arg statesdbhost "0.0.0.0" '.states.host = $statesdbhost' /opt/iobroker/iobroker-data/iobroker.json > /opt/iobroker/iobroker-data/iobroker.json.tmp && mv /opt/iobroker/iobroker-data/iobroker.json.tmp /opt/iobroker/iobroker-data/iobroker.json
chown -R $setuid:$setgid /opt/iobroker/iobroker-data/iobroker.json && chmod 674 /opt/iobroker/iobroker-data/iobroker.json
echo "Done."
echo 'Done.'
elif [ "$multihost" = "master" ] && [ "$statesdbhost" = "127.0.0.1" ]
then
echo "Multihost is set as \"master\" by ENV. But states db host is set to \"127.0.0.1\" by ENV too."
@@ -356,11 +346,10 @@ then
then
echo "Multihost is set but it seems like some configuration is missing."
echo "Please checke if you have configured the ENVs \"MULTIHOST\", \"IOB_STATESDB_TYPE\", \"IOB_STATESDB_HOST\" and \"IOB_STATESTDB_PORT\" correctly and start over."
echo "For more information see ioBroker Docker Image Docs (https://docs.buanet.de/iobroker-docker-image/docs/)."
echo "For more information see ioBroker Docker image Docs (https://docs.buanet.de/iobroker-docker-image/docs/)."
exit 1
fi
echo ' '
echo "Done."
echo 'Done.'
echo ' '
fi
@@ -368,92 +357,86 @@ fi
if [ "$objectsdbtype" != "" ] || [ "$objectsdbhost" != "" ] || [ "$objectsdbport" != "" ]
then
echo "Checking custom settings for objects db..."
echo ' '
if [ "$objectsdbtype" != $(jq -r '.objects.type' /opt/iobroker/iobroker-data/iobroker.json) ]
then
echo "IOB_OBJECTSDB_TYPE is set and value is different from detected ioBroker installation."
echo "Setting type of objects db to \""$objectsdbtype"\"..."
echo -n "Setting type of objects db to \""$objectsdbtype"\"... "
jq --arg objectsdbtype "$objectsdbtype" '.objects.type = $objectsdbtype' /opt/iobroker/iobroker-data/iobroker.json > /opt/iobroker/iobroker-data/iobroker.json.tmp && mv /opt/iobroker/iobroker-data/iobroker.json.tmp /opt/iobroker/iobroker-data/iobroker.json
chown -R $setuid:$setgid /opt/iobroker/iobroker-data/iobroker.json && chmod 674 /opt/iobroker/iobroker-data/iobroker.json
echo "Done."
echo 'Done.'
else
echo "IOB_OBJECTSDB_TYPE is set and value meets detected ioBroker installation."
fi
if [ "$objectsdbhost" != $(jq -r '.objects.host' /opt/iobroker/iobroker-data/iobroker.json) ]
then
echo "IOB_OBJECTSDB_HOST is set and value is different from detected ioBroker installation."
echo "Setting host of objects db to \""$objectsdbhost"\"..."
echo -n "Setting host of objects db to \""$objectsdbhost"\"... "
jq --arg objectsdbhost "$objectsdbhost" '.objects.host = $objectsdbhost' /opt/iobroker/iobroker-data/iobroker.json > /opt/iobroker/iobroker-data/iobroker.json.tmp && mv /opt/iobroker/iobroker-data/iobroker.json.tmp /opt/iobroker/iobroker-data/iobroker.json
chown -R $setuid:$setgid /opt/iobroker/iobroker-data/iobroker.json && chmod 674 /opt/iobroker/iobroker-data/iobroker.json
echo "Done."
echo 'Done.'
else
echo "IOB_OBJECTSDB_HOST is set and value meets detected ioBroker installation."
fi
if [ "$objectsdbport" != $(jq -r '.objects.port' /opt/iobroker/iobroker-data/iobroker.json) ]
then
echo "IOB_OBJECTSDB_PORT is set and value is different from detected ioBroker installation."
echo "Setting port of objects db to \""$objectsdbport"\"..."
echo -n "Setting port of objects db to \""$objectsdbport"\"... "
jq --arg objectsdbport $objectsdbport '.objects.port = $objectsdbport' /opt/iobroker/iobroker-data/iobroker.json > /opt/iobroker/iobroker-data/iobroker.json.tmp && mv /opt/iobroker/iobroker-data/iobroker.json.tmp /opt/iobroker/iobroker-data/iobroker.json
chown -R $setuid:$setgid /opt/iobroker/iobroker-data/iobroker.json && chmod 674 /opt/iobroker/iobroker-data/iobroker.json
echo "Done."
echo 'Done.'
else
echo "IOB_OBJECTSDB_PORT is set and value meets detected ioBroker installation."
fi
echo ' '
echo "Done."
echo ' '
fi
# Checking ENVs for custom setup of states db#
# Checking ENVs for custom setup of states db
if [ "$statesdbtype" != "" ] || [ "$statesdbhost" != "" ] || [ "$statesdbport" != "" ]
then
echo "Checking custom settings for states db..."
echo ' '
if [ "$statesdbtype" != $(jq -r '.states.type' /opt/iobroker/iobroker-data/iobroker.json) ]
then
echo "IOB_STATESDB_TYPE is set and value is different from detected ioBroker installation."
echo "Setting type of states db to \""$statesdbtype"\"..."
echo -n "Setting type of states db to \""$statesdbtype"\"... "
jq --arg statesdbtype "$statesdbtype" '.states.type = $statesdbtype' /opt/iobroker/iobroker-data/iobroker.json > /opt/iobroker/iobroker-data/iobroker.json.tmp && mv /opt/iobroker/iobroker-data/iobroker.json.tmp /opt/iobroker/iobroker-data/iobroker.json
chown -R $setuid:$setgid /opt/iobroker/iobroker-data/iobroker.json && chmod 674 /opt/iobroker/iobroker-data/iobroker.json
echo "Done."
echo 'Done.'
else
echo "IOB_STATESDB_TYPE is set and value meets detected ioBroker installation."
fi
if [ "$statesdbhost" != $(jq -r '.states.host' /opt/iobroker/iobroker-data/iobroker.json) ]
then
echo "IOB_STATESDB_HOST is set and value is different from detected ioBroker installation."
echo "Setting host of states db to \""$statesdbhost"\"..."
echo -n "Setting host of states db to \""$statesdbhost"\"... "
jq --arg statesdbhost "$statesdbhost" '.states.host = $statesdbhost' /opt/iobroker/iobroker-data/iobroker.json > /opt/iobroker/iobroker-data/iobroker.json.tmp && mv /opt/iobroker/iobroker-data/iobroker.json.tmp /opt/iobroker/iobroker-data/iobroker.json
chown -R $setuid:$setgid /opt/iobroker/iobroker-data/iobroker.json && chmod 674 /opt/iobroker/iobroker-data/iobroker.json
echo "Done."
echo 'Done.'
else
echo "IOB_STATESDB_HOST is set and value meets detected ioBroker installation."
fi
if [ "$statesdbport" != $(jq -r '.states.port' /opt/iobroker/iobroker-data/iobroker.json) ]
then
echo "IOB_STATESDB_PORT is set and value is different from detected ioBroker installation."
echo "Setting port of states db to \""$statesdbport"\"..."
echo -n "Setting port of states db to \""$statesdbport"\"... "
jq --arg statesdbport $statesdbport '.states.port = $statesdbport' /opt/iobroker/iobroker-data/iobroker.json > /opt/iobroker/iobroker-data/iobroker.json.tmp && mv /opt/iobroker/iobroker-data/iobroker.json.tmp /opt/iobroker/iobroker-data/iobroker.json
chown -R $setuid:$setgid /opt/iobroker/iobroker-data/iobroker.json && chmod 674 /opt/iobroker/iobroker-data/iobroker.json
echo "Done."
echo 'Done.'
else
echo "IOB_STATESDB_PORT is set and value meets detected ioBroker installation."
fi
echo ' '
echo "Done."
echo ' '
fi
# Checking for Userscripts in /opt/userscripts
if [ `find /opt/userscripts -type f | wc -l` -lt 1 ]
then
echo "There is no data detected in /opt/userscripts. Restoring exapmple userscripts..."
echo -n "There is no data detected in /opt/userscripts. Restoring exapmple userscripts... "
tar -xf /opt/initial_userscripts.tar -C /
chmod 755 /opt/userscripts/userscript_firststart_example.sh
chmod 755 /opt/userscripts/userscript_everystart_example.sh
echo "Done."
echo 'Done.'
echo ' '
elif [ -f /opt/userscripts/userscript_firststart.sh ] || [ -f /opt/userscripts/userscript_everystart.sh ]
then
@@ -499,7 +482,7 @@ echo "running" > /opt/scripts/.docker_config/.healthcheck
shut_down() {
echo ' '
echo "Recived termination signal (SIGTERM)."
echo -n "Shutting down ioBroker"
echo "Shutting down ioBroker..."
local status timeout