This repository was archived by the owner on Aug 29, 2018. It is now read-only.
Commit b6765ea
committed
cartridge control scripts: Fix exit value handling
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.1 parent dce7c14 commit b6765ea
File tree
10 files changed
+46
-46
lines changed- cartridges
- openshift-origin-cartridge-haproxy/bin
- openshift-origin-cartridge-mariadb/bin
- openshift-origin-cartridge-mongodb/bin
- openshift-origin-cartridge-mysql/bin
- openshift-origin-cartridge-nodejs/bin
- openshift-origin-cartridge-perl/bin
- openshift-origin-cartridge-php/bin
- openshift-origin-cartridge-postgresql/bin
- openshift-origin-cartridge-ruby/bin
10 files changed
+46
-46
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
134 | 134 | | |
135 | 135 | | |
136 | 136 | | |
137 | | - | |
138 | | - | |
139 | | - | |
| 137 | + | |
140 | 138 | | |
141 | 139 | | |
142 | 140 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
68 | | - | |
69 | | - | |
70 | | - | |
| 68 | + | |
71 | 69 | | |
72 | 70 | | |
73 | 71 | | |
| |||
Lines changed: 12 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
42 | | - | |
43 | | - | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
44 | 45 | | |
45 | 46 | | |
46 | 47 | | |
| |||
84 | 85 | | |
85 | 86 | | |
86 | 87 | | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
| 88 | + | |
92 | 89 | | |
93 | 90 | | |
94 | | - | |
95 | 91 | | |
96 | | - | |
97 | 92 | | |
98 | 93 | | |
99 | 94 | | |
| |||
125 | 120 | | |
126 | 121 | | |
127 | 122 | | |
128 | | - | |
129 | | - | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
130 | 127 | | |
131 | 128 | | |
132 | 129 | | |
| |||
187 | 184 | | |
188 | 185 | | |
189 | 186 | | |
190 | | - | |
191 | | - | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
192 | 191 | | |
193 | 192 | | |
194 | 193 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
83 | | - | |
84 | | - | |
85 | | - | |
| 83 | + | |
86 | 84 | | |
87 | 85 | | |
88 | 86 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
126 | 126 | | |
127 | 127 | | |
128 | 128 | | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
| 129 | + | |
133 | 130 | | |
134 | 131 | | |
135 | 132 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| 31 | + | |
31 | 32 | | |
32 | | - | |
| 33 | + | |
33 | 34 | | |
34 | | - | |
| 35 | + | |
35 | 36 | | |
36 | 37 | | |
37 | 38 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
| 29 | + | |
28 | 30 | | |
29 | 31 | | |
30 | 32 | | |
31 | 33 | | |
32 | 34 | | |
33 | 35 | | |
34 | | - | |
| 36 | + | |
35 | 37 | | |
36 | | - | |
| 38 | + | |
| 39 | + | |
37 | 40 | | |
38 | 41 | | |
39 | 42 | | |
| 43 | + | |
| 44 | + | |
40 | 45 | | |
41 | 46 | | |
42 | 47 | | |
43 | | - | |
44 | | - | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
45 | 51 | | |
46 | 52 | | |
47 | 53 | | |
| 54 | + | |
| 55 | + | |
48 | 56 | | |
49 | 57 | | |
50 | 58 | | |
51 | 59 | | |
52 | 60 | | |
53 | | - | |
| 61 | + | |
54 | 62 | | |
55 | | - | |
| 63 | + | |
56 | 64 | | |
57 | 65 | | |
58 | | - | |
| 66 | + | |
59 | 67 | | |
60 | 68 | | |
61 | 69 | | |
| |||
69 | 77 | | |
70 | 78 | | |
71 | 79 | | |
| 80 | + | |
| 81 | + | |
72 | 82 | | |
73 | | - | |
74 | | - | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
75 | 86 | | |
76 | 87 | | |
77 | 88 | | |
| |||
185 | 196 | | |
186 | 197 | | |
187 | 198 | | |
188 | | - | |
189 | | - | |
| |||
Lines changed: 1 addition & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
163 | 163 | | |
164 | 164 | | |
165 | 165 | | |
166 | | - | |
167 | | - | |
168 | | - | |
| 166 | + | |
169 | 167 | | |
170 | 168 | | |
171 | 169 | | |
| |||
Lines changed: 3 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
| 71 | + | |
71 | 72 | | |
72 | | - | |
| 73 | + | |
73 | 74 | | |
74 | | - | |
| 75 | + | |
75 | 76 | | |
76 | 77 | | |
77 | 78 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| 44 | + | |
44 | 45 | | |
45 | | - | |
| 46 | + | |
46 | 47 | | |
47 | | - | |
| 48 | + | |
48 | 49 | | |
49 | 50 | | |
50 | 51 | | |
| |||
0 commit comments