Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@yehy4
Copy link
Contributor

@yehy4 yehy4 commented Aug 11, 2022

Before this PR, if ENABLE_IPv6 is set to 0 (which is the default), then the health check script always exits with code 1 (reporting an unhealthy state) regardless of whether the IPv4 check succeeds or not.

This happens because the check [ "$ENABLE_IPv6" = "1" ] is the last command that runs in the script (when ENABLE_IPv6=0), and since it evaluates to false (i.e., returns exit code 1), the entire script exits with exit code 1, indicating a failure.

In this PR, we explicitly use if statements (instead of command chaining using &&) to prevent this issue in check-servers.sh, and we use if statements in start-servers.sh to maintain consistency among all shell scripts in the repository.

@SaswatPadhi
Copy link
Member

Ah! This explains why the CI jobs on another repo that uses this tang image started failing.
I was being lazy and used a shorthand for if-then-else 😅 ... should have thought more carefully about the exit code.

Copy link
Member

@SaswatPadhi SaswatPadhi left a comment

Choose a reason for hiding this comment

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

I have one request on refactoring the conditional statement.

Also, we should make these fixes on the start-servers.sh script too.

check-servers.sh Outdated

[ "$ENABLE_IPv4" = "1" ] && wget -4qSO /dev/null http://127.0.0.1:8080/adv
[ "$ENABLE_IPv6" = "1" ] && wget -6qSO /dev/null http://[::1]:8080/adv
[ "$ENABLE_IPv4" = "1" ] && $(wget -4qSO /dev/null http://127.0.0.1:8080/adv || exit 1)
Copy link
Member

Choose a reason for hiding this comment

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

I think it might be cleaner to use an if-then-else block instead of using subshell expansions and exits.

Suggested change
[ "$ENABLE_IPv4" = "1" ] && $(wget -4qSO /dev/null http://127.0.0.1:8080/adv || exit 1)
if [ "$ENABLE_IPv4" = "1" ]; then
wget -4qSO /dev/null http://127.0.0.1:8080/adv
fi

(same comment on the ENABLE_IPv6 case below.

@yehy4
Copy link
Contributor Author

yehy4 commented Aug 11, 2022

Done. I agree that this looks much cleaner now without the explicit exit calls. Thanks for the suggestion!

I added another commit to use if statements in start-servers.sh for consistency and updated the PR description to reflect the new changes.

Copy link
Member

@SaswatPadhi SaswatPadhi left a comment

Choose a reason for hiding this comment

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

Looks great!

Thanks again 🎉

@SaswatPadhi SaswatPadhi merged commit 88d3045 into padhi-homelab:main Aug 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants