diff --git a/amd64/scripts/iobroker_startup.sh b/amd64/scripts/iobroker_startup.sh index fff9550..d437bf9 100644 --- a/amd64/scripts/iobroker_startup.sh +++ b/amd64/scripts/iobroker_startup.sh @@ -90,7 +90,7 @@ echo "$(printf -- '-%.0s' {1..60})" echo ' ' # Installing additional packages and setting uid/gid -if [ "$packages" != "" ] || [ $(cat /etc/group | grep 'iobroker:' | cut -d':' -f3) != $setgid ] || [ $(cat /etc/passwd | grep 'iobroker:' | cut -d':' -f3) != $setuid ] +if [ "$packages" != "" ] || [ $(cat /etc/group | grep 'iobroker:' | cut -d':' -f3) != $setgid ] || [ $(cat /etc/passwd | grep 'iobroker:' | cut -d':' -f3) != $setuid ] || [ -f /opt/.firstrun ] then if [ "$packages" != "" ] then @@ -110,6 +110,13 @@ then echo "Done." echo ' ' fi + if [ -f /opt/.firstrun ] + then + echo "Registering maintenance-mode script as command." + echo "alias maintenance-mode=\'/opt/scripts/maintenance-mode.sh\'" >> /root/.bashrc + echo "Done." + echo ' ' + fi else echo "Nothing to do here." echo ' ' diff --git a/amd64/scripts/maintenance-mode.sh b/amd64/scripts/maintenance-mode.sh new file mode 100644 index 0000000..a1a9d86 --- /dev/null +++ b/amd64/scripts/maintenance-mode.sh @@ -0,0 +1,49 @@ +#!/bin/bash + +if [ "$1" == "status" ] +then + if [ "$cat /opt/iobroker/.docker_config/.healthcheck" == "maintenance" ] + then + echo 'Maintenance mode is ON.' + exit 0 + elif [ "$cat /opt/iobroker/.docker_config/.healthcheck" != "maintenance" ] + then + echo 'Maintenance mode is OFF.' + exit 0 + fi +elif [ "$1" == "on" ] +then + echo 'This will stop ioBroker and enable maintenance mode for this container.' + read -p 'Continue? Type yes or no: ' A + if [ "$A" == "y" ] || [ "$A" == "yes" ] + then + echo 'Enabling maintenance mode...' + echo "maintenance" > /opt/iobroker/.docker_config/.healthcheck + echo 'Done.' + sleep 2 + echo 'Stopping ioBroker...' + pkill -u iobroker + echo 'Done.' + exit 0 + else + exit 0 + fi +elif [ "$1" == "off" ] +then + echo 'Depending of the restart policy of this container, this will force it to stop (and restart) immediately.' + echo 'Maintenance mode will be disabled after the restart.' + read -p 'Continue? Type yes or no: ' A + if [ "$A" == "y" ] || [ "$A" == "yes" ] + then + echo "Disabling maintenance mode and forcing container to stop/ restart..." + echo "maintenance" > /opt/iobroker/.docker_config/.healthcheck + pkill -u root + exit 0 + else + exit 0 + fi +else + echo 'Invalid command. Please try again.' +fi + +exit 0