Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added check if there is already a running instance of health-check.sh #30

Merged
merged 1 commit into from
Oct 17, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/health-check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,17 @@ CONFIGTYPE="${CONFIGTYPE:-"fhem.cfg"}"
TELNETPORT="${TELNETPORT:-7072}"
STATE=0

if [ "${CONFIGTYPE}" != "configDB" ] && [ -s ${FHEM_DIR}/${CONFIGTYPE} ] && [ -z "$(cat ${FHEM_DIR}/${CONFIGTYPE} | grep -P "^define .* telnet ${TELNETPORT}")" ]; then
RUNNING_INSTANCES=$(pgrep -f "/bin/sh -c /health-check.sh" | wc -l)

if [ "${RUNNING_INSTANCES}" -gt "1" ]; then
echo "Instance already running, aborting another one"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

echoing here does not make sense as it will replace status appearance of the existing instance in docker status overview.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the docs

To help debug failing probes, any output text (UTF-8 encoded) that the command writes on stdout or stderr will be stored in the health status and can be queried with docker inspect. Such output should be kept short (only the first 4096 bytes are stored currently).

This output should help, if there is already a running instance of the health check to report this, that something isn't correct at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jpawlowski

How we can proceed here?

exit 1
fi

if [ "${CONFIGTYPE}" != "configDB" ] && [ -s "${FHEM_DIR}/${CONFIGTYPE}" ] && [ -z "$(cat ${FHEM_DIR}/${CONFIGTYPE} | grep -P "^define .* telnet ${TELNETPORT}")" ]; then
TELNETPORT="$(cat ${FHEM_DIR}/${CONFIGTYPE} | grep -P '^define .* telnet ' | head -1 | cut -d ' ' -f 4)"

if [ -z "${TELNETPORT}"]; then
if [ -z "${TELNETPORT}" ]; then
echo "Telnet(undefined): FAILED;"
exit 1
fi
Expand Down