This commit is contained in:
buanet
2021-08-30 19:20:17 +02:00
parent 904058c0f5
commit 97ca3aa72d
7 changed files with 124 additions and 120 deletions

View File

@@ -1,6 +1,17 @@
#!/bin/bash
# function to display help text
############################
##### default settings #####
############################
autoconfirm=no # yould be set to true by commandline option
####################################
##### declaration of functions #####
####################################
# display help text
display_help() {
echo "This script is build to manage your ioBroker container!"
echo "Usage: maintenance [ COMMAND ] [ OPTIONS ]"
@@ -21,32 +32,41 @@ display_help() {
exit 0
}
while getopts h opt
do
case $opt in
h | --help)
display_help ;;
esac
exit 0;
done
if [ "$1" == "status" ]
then
# checking maintenance mode status
check_status() {
if [ $(cat /opt/scripts/.docker_config/.healthcheck) == 'maintenance' ]
then
echo 'Maintenance mode is ON.'
exit 0
echo 'Maintenance mode is turned ON.'
elif [ $(cat /opt/scripts/.docker_config/.healthcheck) != 'maintenance' ]
then
echo 'Maintenance mode is OFF.'
exit 0
echo 'Maintenance mode is turned OFF.'
fi
elif [ "$1" == "on" ]
then
echo 'You are now going to stop ioBroker and activating maintenance mode for this container.'
read -p 'Do you want to continue [yes/no]? ' A
if [ "$A" == "y" ] || [ "$A" == "Y" ] || [ "$A" == "yes" ]
}
# turn maintenance mode ON
switch_on() {
if [ $(cat /opt/scripts/.docker_config/.healthcheck) != 'maintenance' ] && [ "$autoconfirm" == "no" ] # maintenance mode OFF / autoconfirm = no
then
echo 'You are now going to stop ioBroker and activating maintenance mode for this container.'
read -p 'Do you want to continue [yes/no]? ' A
if [ "$A" == "y" ] || [ "$A" == "Y" ] || [ "$A" == "yes" ]
then
echo 'Activating maintenance mode...'
echo "maintenance" > /opt/scripts/.docker_config/.healthcheck
sleep 1
echo 'Done.'
echo 'Stopping ioBroker...'
pkill -u iobroker
sleep 1
echo 'Done.'
exit 0
else
exit 0
fi
elif [ $(cat /opt/scripts/.docker_config/.healthcheck) != 'maintenance' ] && [ "$autoconfirm" == "yes" ] # maintenance mode OFF / autoconfirm = yes
then
echo 'You are now going to stop ioBroker and activating maintenance mode for this container.'
echo 'This command was already confirmed by -y or --yes option.'
echo 'Activating maintenance mode...'
echo "maintenance" > /opt/scripts/.docker_config/.healthcheck
sleep 1
@@ -57,10 +77,12 @@ then
echo 'Done.'
exit 0
else
exit 0
echo 'Maintenance mode is already turned ON.'
fi
elif [ "$1" == "off" ]
then
}
# turn maintenance mode OFF
switch_off() {
echo 'You are now going to deactivate maintenance mode for this container.'
echo 'Depending on the restart policy, your container will be stopped/ restarted immediately.'
read -p 'Do you want to continue [yes/no]? ' A
@@ -73,8 +95,10 @@ then
else
exit 0
fi
elif [ "$1" == "upgrade" ]
then
}
# upgrade js-controller
upgrade() {
echo 'You are now going to upgrade your js-controller.'
echo 'As this will change data in /opt/iobroker, make sure you have a backup!'
echo 'During the upgrade process the container will automatically switch into maintenance mode and stop ioBroker.'
@@ -103,8 +127,39 @@ then
else
exit 0
fi
else
echo 'Invalid command. Please try again.'
fi
}
##############################
##### parsing parameters #####
##############################
while :; do
case $1 in
-h|--help)
display_help # calling function to display help text
exit
;;
-y|--yes)
autoconfirm=yes # answers prompts with "yes"
;;
status)
check_status # calling function to check maintenance mode status
;;
on|-on)
switch_on # calling function to switch maintenance mode on
exit
;;
--) # End of all options.
shift
break
;;
-?*)
printf 'WARN: Unknown option (ignored): %s\n' "$1"
;;
*) # Default case: No more options, so break out of the loop.
break
esac
shift
done
exit 0