From f18a460181f680ab4e3a70cd334ee03854e5c6ca Mon Sep 17 00:00:00 2001 From: Raphael Glon Date: Thu, 10 Oct 2024 18:26:20 +0200 Subject: [PATCH] propagate signal from entrypoint to tgi Signed-off-by: Raphael Glon --- tgi-entrypoint.sh | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/tgi-entrypoint.sh b/tgi-entrypoint.sh index ea94dcd9..94e292fc 100755 --- a/tgi-entrypoint.sh +++ b/tgi-entrypoint.sh @@ -1,5 +1,28 @@ #!/bin/bash +child_pid=0 + +cleanup () { + echo tgi interrupted, cleaning + sig=$(($? - 128)) + if [ $sig -le 0 ];then + sig=TERM + fi + echo signal $sig received + if [ $child_pid -gt 0 ] && ps -p $child_pid > /dev/null;then + echo kill child $child_pid + kill -$sig $child_pid + wait $child_pid + child_pid=0 + fi +} + +trap cleanup INT TERM HUP EXIT ERR + ldconfig 2>/dev/null || echo 'unable to refresh ld cache, not a big deal in most cases' -text-generation-launcher $@ +text-generation-launcher $@ & + +child_pid=$! + +wait $child_pid