Skip to content

Commit

Permalink
optimize iob shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
buanet committed Jun 13, 2022
1 parent 3957414 commit b8c67b7
Show file tree
Hide file tree
Showing 4 changed files with 193 additions and 167 deletions.
2 changes: 1 addition & 1 deletion .VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v6.1.0
v6.2.0-beta.1
13 changes: 8 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
## Changelog
### v6.2.0-beta.1 (2022-06-13)
* 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))

### v6.1.0 (2022-03-01)
* v6.1.0-beta.2 (2022-02-11)
Expand All @@ -8,8 +11,8 @@
* optimize startup script logging
* add breaks and optimize 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 @agross](https://github.com/buanet/ioBroker.docker/pull/232))
* add auto confirm parameter to upgrade function in maintenance script ([#229 @thost96](https://github.com/buanet/ioBroker.docker/pull/229))
* 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))
* add alias "m" for maintenance script

### v6.0.0 (2021-12-09)
Expand Down Expand Up @@ -96,7 +99,7 @@
### v4.1.0 (2020-01-17)
* improved readme.md
* v4.0.3-beta (2020-01-06)
* added support to restore backup on startup ([#56 @duffbeer2000](https://github.com/buanet/ioBroker.docker/pull/56))
* added support to restore backup on startup ([#56 by @duffbeer2000](https://github.com/buanet/ioBroker.docker/pull/56))
* small fixes according to "docker best practices"
* v4.0.2-beta (2019-12-10)
* ~~added env for activating redis~~
Expand All @@ -116,13 +119,13 @@
* v3.1.2-beta (2019-09-03)
* using node 10 instead of node 8
* v3.1.1-beta (2019-09-02)
* adding env for setting uid/ gid for iobroker-user ([#33 @mplogas](https://github.com/buanet/ioBroker.docker/pull/33))
* adding env for setting uid/ gid for iobroker-user ([#33 by @mplogas](https://github.com/buanet/ioBroker.docker/pull/33))

### v3.1.0 (2019-08-21)
* v3.0.3-beta (2019-08-21)
* switching base image from "debian:latest" to "debian:stretch"
* v3.0.2-beta (2019-06-13)
* using gosu instead of sudo ([#26 @SchumyHao](https://github.com/buanet/ioBroker.docker/pull/26))
* using gosu instead of sudo ([#26 by @SchumyHao](https://github.com/buanet/ioBroker.docker/pull/26))
* changing output of ioBroker logging
* v3.0.1-beta (2019-05-18)
* ~~switching back to iobroker-daemon for startup~~
Expand Down
33 changes: 31 additions & 2 deletions debian/scripts/iobroker_startup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ statesdbtype=$IOB_STATESDB_TYPE
usbdevices=$USBDEVICES
zwave=$ZWAVE

pkill_timeout=10 # timeout for iobroker shutdown in seconds

# Getting date and time for logging
dati=`date '+%Y-%m-%d %H:%M:%S'`

Expand Down Expand Up @@ -497,8 +499,35 @@ echo "running" > /opt/scripts/.docker_config/.healthcheck
shut_down() {
echo ' '
echo "Recived termination signal (SIGTERM)."
echo "Shutting down ioBroker..."
pkill -SIGTERM -u iobroker -f iobroker.js-controller
echo -n "Shutting down ioBroker"

local status timeout

timeout="$(date --date="now + $pkill_timeout sec" +%s)"
pkill -u iobroker -f iobroker.js-controller
status=$?
if (( status >= 2 )); then # syntax error or fatal error
return 1
fi

if (( status == 1 )); then # no processes matched
return
fi

# pgrep exits with status 1 when there are no matches
while pgrep -u iobroker > /dev/null; (( $? != 1 )); do
if (($(date +%s) > timeout)); then
echo -e '\nTimeout reached. Killing remaining processes...'
pkill --signal SIGKILL -u iobroker
echo 'Done.'
exit
fi

echo -n '.'
sleep 1
done

echo -e '\nDone.'
exit
}

Expand Down
Loading

0 comments on commit b8c67b7

Please sign in to comment.