summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@gmail.com>2021-06-26 07:00:45 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2021-06-26 07:00:45 +0000
commitfc8e4ea1f19934d4a1f1d1120e421359ac7c6f0d (patch)
tree9ebaf44b01b96ce77f0a2d93b7128df9767fc3cf
parent3c3b8e2b0622078a1c9e6d05a597b65ec39d8c23 (diff)
parenta3d0b96090409a7a6976319c60134f769959ebff (diff)
Merge "Honour {httpd,sshd}.gracefulStopTimeout in gerrit.sh" into stable-3.2
-rwxr-xr-xresources/com/google/gerrit/pgm/init/gerrit.sh43
1 files changed, 41 insertions, 2 deletions
diff --git a/resources/com/google/gerrit/pgm/init/gerrit.sh b/resources/com/google/gerrit/pgm/init/gerrit.sh
index ce858d5b80..61eb5294f1 100755
--- a/resources/com/google/gerrit/pgm/init/gerrit.sh
+++ b/resources/com/google/gerrit/pgm/init/gerrit.sh
@@ -96,6 +96,36 @@ get_config() {
fi
}
+# Limited support for Gerrit's getTimeUnit() limited from seconds to days
+# because having gerrit startup/shutdown that wait for weeks or years would
+# not make so much sense.
+get_time_unit_sec() {
+ TIME_LC=`echo $1 | tr '[:upper:]' '[:lower:]'`
+ if [[ "$TIME_LC" =~ ^(0|[1-9][0-9]*)$ ]]
+ then
+ echo $TIME_LC
+ elif [[ "$TIME_LC" =~ ^[1-9][0-9]*\ *(s|sec|second|seconds)$ ]]
+ then
+ echo "$TIME_LC" | tr -d -c 0-9
+ elif [[ "$TIME_LC" =~ ^[1-9][0-9]*\ *(m|min|minute|minutes)$ ]]
+ then
+ expr `echo "$TIME_LC" | tr -d -c 0-9` '*' 60
+ elif [[ "$TIME_LC" =~ ^[1-9][0-9]*\ *(h|hr|hour|hours)$ ]]
+ then
+ expr `echo "$TIME_LC" | tr -d -c 0-9` '*' 3600
+ elif [[ "$TIME_LC" =~ ^[1-9][0-9]*\ *(d|day|days)$ ]]
+ then
+ expr `echo "$TIME_LC" | tr -d -c 0-9` '*' 86400
+ else
+ >&2 echo "Unsupported time format $1"
+ exit 1
+ fi
+}
+
+max() {
+ echo $(( $1 > $2 ? $1 : $2 ))
+}
+
##################################################
# Get the action and options
##################################################
@@ -316,6 +346,15 @@ ulimit -v unlimited ; # virtual memory
ulimit -x >/dev/null 2>&1 && ulimit -x unlimited ; # file locks
#####################################################
+# Configure the maximum wait time for shutdown
+#####################################################
+EXTRA_STOP_TIMEOUT=30
+HTTPD_STOP_TIMEOUT=$(get_time_unit_sec "$(get_config --get httpd.gracefulStopTimeout || echo 0)")
+SSHD_STOP_TIMEOUT=$(get_time_unit_sec "$(get_config --get sshd.gracefulStopTimeout || echo 0)")
+
+STOP_TIMEOUT=`expr $(max $HTTPD_STOP_TIMEOUT $SSHD_STOP_TIMEOUT) '+' $EXTRA_STOP_TIMEOUT`
+
+#####################################################
# This is how the Gerrit server will be started
#####################################################
@@ -477,7 +516,7 @@ case "$ACTION" in
if running "$GERRIT_PID" ; then
sleep 3
if running "$GERRIT_PID" ; then
- sleep 30
+ sleep $STOP_TIMEOUT
if running "$GERRIT_PID" ; then
start-stop-daemon -K -p "$GERRIT_PID" -s KILL
fi
@@ -487,7 +526,7 @@ case "$ACTION" in
echo OK
else
PID=`cat "$GERRIT_PID" 2>/dev/null`
- TIMEOUT=30
+ TIMEOUT=$STOP_TIMEOUT
while running "$GERRIT_PID" && test $TIMEOUT -gt 0 ; do
kill $PID 2>/dev/null
sleep 1