2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-09-05 04:27:55 +00:00

fix(remoteshell): wait for the ssh daemon to end before a new one starts

A kill only asks the kernel to end a process, so it returns before the process
is gone. The fallback started a new daemon on the next line, which could find
the port still held by the old one, fail to start, and leave the node with no
daemon at all.

Wait for the processes to end, for up to ten seconds, before the new daemon
starts. The test that a process is still there sends no signal.
This commit is contained in:
Vinícius Ferrão
2026-08-29 21:01:02 -03:00
parent 1f26a3b318
commit f23745d18b
+13 -1
View File
@@ -648,7 +648,19 @@ fi
#try to kill the process and start
if [ "$?" != "0" ];then
PIDLIST=`ps aux | grep -v grep | grep "/usr/sbin/sshd"|awk -F" " '{print $2}'|xargs`
[ -n "$PIDLIST" ] && kill -9 $PIDLIST
if [ -n "$PIDLIST" ]; then
kill -9 $PIDLIST
waited=0
while [ $waited -lt 10 ]; do
alive=0
for pid in $PIDLIST; do
if kill -0 $pid 2>/dev/null; then alive=1; fi
done
if [ $alive -eq 0 ]; then break; fi
sleep 1
waited=`expr $waited + 1`
done
fi
/usr/sbin/sshd
fi
kill -9 $CREDPID