manual sync (beta branch)

This commit is contained in:
dontobi
2023-07-10 07:22:09 +02:00
parent 700d7609cc
commit 6af2d4879f
3 changed files with 41 additions and 57 deletions

View File

@@ -148,9 +148,9 @@ if [[ -f /opt/.first_run ]]; then
echo " " echo " "
# Register maintenance script # Register maintenance script
echo -n "Registering maintenance script as command... " echo -n "Registering maintenance script as command... "
echo "alias maintenance=\'/opt/scripts/maintenance.sh\'" >> /root/.bashrc echo "alias maintenance='/opt/scripts/maintenance.sh'" >> /etc/bash.bashrc
echo "alias maint=\'/opt/scripts/maintenance.sh\'" >> /root/.bashrc echo "alias maint='/opt/scripts/maintenance.sh'" >> /etc/bash.bashrc
echo "alias m=\'/opt/scripts/maintenance.sh\'" >> /root/.bashrc echo "alias m='/opt/scripts/maintenance.sh'" >> /etc/bash.bashrc
echo "Done." echo "Done."
else else
echo "This is not the first run of this container. Skipping first run preparation." echo "This is not the first run of this container. Skipping first run preparation."

View File

@@ -59,23 +59,9 @@ enable_maintenance() {
return return
fi fi
if [[ "$killbyname" == yes ]]; then
# undocumented option, only for use with backitup restore scripts
# stops iobroker by terminating js-controller process by name (the old way)
echo "This command will activate maintenance mode and stop js-controller."
echo -n "Activating maintenance mode... "
echo "maintenance" > "$healthcheck"
sleep 1
echo "Done."
echo -n 'Stopping ioBroker...'
pkill -u iobroker -f iobroker.js-controller
sleep 5
echo "Done."
return
fi
echo "You are now going to stop ioBroker and activate maintenance mode for this container." echo "You are now going to stop ioBroker and activate maintenance mode for this container."
if [[ "$killbyname" != yes ]]; then
if [[ "$autoconfirm" != yes ]]; then if [[ "$autoconfirm" != yes ]]; then
local reply local reply
@@ -85,15 +71,13 @@ enable_maintenance() {
else else
return 1 return 1
fi fi
else fi
echo "This command was already confirmed by the -y or --yes option."
fi fi
echo "Activating maintenance mode..." echo "Activating maintenance mode..."
echo "maintenance" > "$healthcheck" echo "maintenance" > "$healthcheck"
sleep 1 sleep 1
echo "Done." echo -n "Stopping ioBroker..."
echo -n 'Stopping ioBroker...'
stop_iob stop_iob
} }
@@ -116,13 +100,11 @@ disable_maintenance() {
else else
return 1 return 1
fi fi
else
echo "This command was already confirmed by the -y or --yes option."
fi fi
echo "Deactivating maintenance mode and forcing container to stop or restart..." echo "Deactivating maintenance mode and forcing container to stop or restart..."
echo "stopping" > "$healthcheck" echo "stopping" > "$healthcheck"
pkill -u root gosu root pkill -u root
echo "Done." echo "Done."
} }
@@ -142,8 +124,6 @@ upgrade_jscontroller() {
else else
return 1 return 1
fi fi
else
echo "This command was already confirmed by the -y or --yes option."
fi fi
if ! maintenance_enabled > /dev/null; then if ! maintenance_enabled > /dev/null; then
@@ -161,7 +141,7 @@ upgrade_jscontroller() {
echo "Container will be stopped or restarted in 5 seconds..." echo "Container will be stopped or restarted in 5 seconds..."
sleep 5 sleep 5
echo "stopping" > "$healthcheck" echo "stopping" > "$healthcheck"
pkill -u root gosu root pkill -u root
} }
# stop iobroker and wait until all processes stopped or pkill_timeout is reached # stop iobroker and wait until all processes stopped or pkill_timeout is reached
@@ -169,7 +149,7 @@ stop_iob() {
local status timeout local status timeout
timeout="$(date --date="now + $pkill_timeout sec" +%s)" timeout="$(date --date="now + $pkill_timeout sec" +%s)"
pkill -u iobroker -f iobroker.js-controller pkill -u iobroker -f 'iobroker.js-controller[^/]*$'
status=$? status=$?
if (( status >= 2 )); then # syntax error or fatal error if (( status >= 2 )); then # syntax error or fatal error
return 1 return 1
@@ -179,19 +159,25 @@ stop_iob() {
return return
fi fi
if [[ "$killbyname" != yes ]]; then
# pgrep exits with status 1 when there are no matches # pgrep exits with status 1 when there are no matches
while pgrep -u iobroker > /dev/null; (( $? != 1 )); do while pgrep -u iobroker -f 'io.' > /dev/null; (( $? != 1 )); do
if (($(date +%s) > timeout)); then if (($(date +%s) > timeout)); then
echo -e "\nTimeout reached. Killing remaining processes..." echo -e "\nTimeout reached. Killing remaining processes..."
pgrep --list-full -u iobroker pgrep --list-full -u iobroker
pkill --signal SIGKILL -u iobroker pkill --signal SIGKILL -u iobroker -f 'io.'
echo "Done." echo "Done."
return return
fi fi
echo -n "." echo -n "."
sleep 1 sleep 1
done done
else
for ((i=0; i<3; i++)); do
sleep 1
echo -n "."
done
fi
echo -e "\nDone." echo -e "\nDone."
} }
@@ -210,17 +196,17 @@ restart_container() {
else else
return 1 return 1
fi fi
else
echo "This command was already confirmed by the -y or --yes option."
fi fi
if ! maintenance_enabled > /dev/null; then
echo -n "Stopping ioBroker..." echo -n "Stopping ioBroker..."
stop_iob stop_iob
fi
echo "Container will be stopped or restarted in 5 seconds..." echo "Container will be stopped or restarted in 5 seconds..."
sleep 5 sleep 5
echo "stopping" > "$healthcheck" echo "stopping" > "$healthcheck"
pkill -u root gosu root pkill -u root
} }
# restore iobroker # restore iobroker
@@ -238,8 +224,6 @@ restore_iobroker() {
else else
return 1 return 1
fi fi
else
echo "This command was already confirmed by the -y or --yes option."
fi fi
if check_starting > /dev/null; then if check_starting > /dev/null; then
@@ -279,7 +263,7 @@ restore_iobroker() {
echo "Container will be stopped or restarted in 10 seconds..." echo "Container will be stopped or restarted in 10 seconds..."
sleep 10 sleep 10
echo "stopping" > "$healthcheck" echo "stopping" > "$healthcheck"
pkill -u root gosu root pkill -u root
} }
# parsing commands and options # parsing commands and options