-
Notifications
You must be signed in to change notification settings - Fork 516
cartridge control scripts: Fix exit value handling #6274
base: master
Are you sure you want to change the base?
cartridge control scripts: Fix exit value handling #6274
Conversation
@Miciah this all makes sense. Can't find any issues with your changes. LGTM. Thanks for fixing this. |
Thanks, Tim! @VojtechVitek, would you be able to double-check this PR? I saw your name on some related changes in the Git log. |
LGTM // Disclaimer: I'm ex Red Hatter :) |
echo "Restarting PHP ${OPENSHIFT_PHP_VERSION} cartridge (Apache+mod_php)" | ||
ensure_httpd_restart_succeed "$HTTPD_PID_FILE" "$HTTPD_CFG_FILE" | ||
if [ -f "$HTTPD_PID_FILE" ]; then | ||
ensure_httpd_restart_succeed "$HTTPD_PID_FILE" "$HTTPD_CFG_FILE" || ret=$? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On second thought, maybe we expect this always to succeed and would rather the script fail loudly if it does not.
Fix some problems with how we handle exit values in control scripts. Most control scripts have `#!/bin/bash -e` or `set -e` so that they exit immediately if a command exits with a non-zero return value if that command is not part of a compound command or conditional statement. Thus if we anticipate that a command may fail, we must put it in a compound command or a conditional statement. This commit makes the following changes: • Replace `foo; [ $? -eq 0 ] && bar` with `local rc=0; foo || rc=$?; [[ "$rc" = 0 ]] && bar` where foo is an especially long command. • Replace `foo; [ $? -eq 0 ] || bar` with `if ! foo; then bar; fi`. • Replace `foo; ret=$?; if [ $ret -eq 0 ]; then` with `if foo; then`. • Replace `foo; ret=$?; if [ $ret -ne 0 ]; then` with `if ! foo; then`. • Replace `foo; bar $?` with `local rc=0; foo || rc=$?; bar "$rc"`. • Replace `foo; return $?` with `local ret=0; foo || ret=$?; return $ret`. • If a script runs with `/bin/bash -e` and ends with `exit $?`, delete the `exit $?` because it is redundant. Moreover, several control scripts had inverted logic around the /bin/kill command: These scripts would run /bin/kill, check its exit value, and retry /bin/kill if the first attempt returned 0. However, an exit value of 0 from /bin/kill means that it succeeded, so this code was retrying exactly when it did not need to do so. This commit fixes this logic.
a20fb19
to
b6765ea
Compare
Sorry for pinging you, Vojtech, and thanks for graciously providing a review! I updated the PR not to modify [test] [extended:cartridge,gear] |
Blocked by failures in the gear extended tests, which will be fixed by #6291. |
[test] again, please! |
Failed because of EC2 timeouts. [test] again, please! |
Lets try to [test] again, its been awhile. |
Cartridge group 4 tests appear to be failing:
|
[test] again, please! |
Please [test] again! |
[test] again, please! |
Evaluated for online test up to b6765ea |
Online Test Results: FAILURE (https://ci.dev.openshift.redhat.com/jenkins/job/test_pull_requests/9344/) (Extended Tests: cartridge, gear) |
Fix some problems with how we handle exit values in control scripts.
Most control scripts have
#!/bin/bash -e
orset -e
so that they exit immediately if a command exits with a non-zero return value if that command is not part of a compound command or conditional statement. Thus if we anticipate that a command may fail, we must put it in a compoundcommand or a conditional statement. This commit makes the following changes:
• Replace
foo; [ $? -eq 0 ] && bar
withlocal rc=0; foo || rc=$?; [[ "$rc" = 0 ]] && bar
where foo is an especially long command.• Replace
foo; [ $? -eq 0 ] || bar
withif ! foo; then bar; fi
.• Replace
foo; ret=$?; if [ $ret -eq 0 ]; then
withif foo; then
.• Replace
foo; ret=$?; if [ $ret -ne 0 ]; then
withif ! foo; then
.• Replace
foo; bar $?
withlocal rc=0; foo || rc=$?; bar "$rc"
.• Replace
foo; return $?
withlocal ret=0; foo || ret=$?; return $ret
.• If a script runs with
/bin/bash -e
and ends withexit $?
, delete theexit $?
because it is redundant.Moreover, several control scripts had inverted logic around the
/bin/kill
command: These scripts would run/bin/kill
, check its exit value, and retry/bin/kill
if the first attempt returned 0. However, an exit value of 0 from /bin/kill means that it succeeded, so this code was retrying exactly when it did not need to do so. This commit fixes this logic.@tiwillia, @dobbymoodge, does this make sense, or am I silly?