From 49508e80925261e10bd1052cb20f7897d1eaeab2 Mon Sep 17 00:00:00 2001 From: Arthur She Date: Thu, 12 Jan 2023 04:35:11 +0000 Subject: post_servod.sh: waiting for the servod ready with wait-fot-it Signed-off-by: Arthur She --- src/dockerfiles/servod/Dockerfile | 8 ++++++-- src/dockerfiles/servod/post_servod.sh | 38 +++++++++++++++++++++++------------ src/dockerfiles/servod/stop_servod.sh | 20 ++++++++++++++++++ 3 files changed, 51 insertions(+), 15 deletions(-) create mode 100755 src/dockerfiles/servod/stop_servod.sh diff --git a/src/dockerfiles/servod/Dockerfile b/src/dockerfiles/servod/Dockerfile index 036ff9c..a0bde76 100644 --- a/src/dockerfiles/servod/Dockerfile +++ b/src/dockerfiles/servod/Dockerfile @@ -16,7 +16,8 @@ RUN apt-get update --no-install-recommends \ file \ bash-completion \ net-tools \ - tzdata + tzdata \ + wait-for-it # Avoid watchtower updating servod, it gets pulled before every start of the # container, we should not stop/start it in the case a new version is pushed. @@ -30,6 +31,9 @@ RUN ln -s /usr/bin/futility /usr/bin/gbb_utility # Add --log-dir parameter to servod RUN sed -i '$ s/$/ \\/' /start_servod.sh; \ - echo " --log-dir /var/log/servod" >> /start_servod.sh + echo " --log-dir /var/log/servod &" >> /start_servod.sh; \ + echo "echo \$! > /servod.pid" >> /start_servod.sh; \ + echo "\nwait \$(cat /servod.pid)" >> /start_servod.sh COPY post_servod.sh /post_servod.sh +COPY stop_servod.sh /stop_servod.sh diff --git a/src/dockerfiles/servod/post_servod.sh b/src/dockerfiles/servod/post_servod.sh index 2a87640..322af11 100755 --- a/src/dockerfiles/servod/post_servod.sh +++ b/src/dockerfiles/servod/post_servod.sh @@ -7,20 +7,32 @@ PTS_DIR="/run/pts" PORT_FLAG="--port ${PORT}" DATE="`date`" -/start_servod.sh & +create_uart_links() { + if [ -n "$LAVA_DEVICE" ]; then + CPU_UART="$(${DUT_CONTROL} ${PORT_FLAG} cpu_uart_pty | awk -F':' '{print $2}')" + [ -n "${CPU_UART}" ] && ln -fs "${CPU_UART}" "${PTS_DIR}/cpu_uart-${LAVA_DEVICE}" + CR50_UART="$(${DUT_CONTROL} ${PORT_FLAG} cr50_uart_pty | awk -F':' '{print $2}')" + [ -n "${CR50_UART}" ] && ln -fs "${CR50_UART}" "${PTS_DIR}/cr50_uart-${LAVA_DEVICE}" + EC_UART="$(${DUT_CONTROL} ${PORT_FLAG} ec_uart_pty | awk -F':' '{print $2}')" + [ -n "${EC_UART}" ] && ln -fs "${EC_UART}" "${PTS_DIR}/ec_uart-${LAVA_DEVICE}" + fi +} +/start_servod.sh & PID=$! -sleep 10 - -if [ -n "$LAVA_DEVICE" ]; then - CPU_UART="$(${DUT_CONTROL} ${PORT_FLAG} cpu_uart_pty | awk -F':' '{print $2}')" - [ -n "${CPU_UART}" ] && ln -fs "${CPU_UART}" "${PTS_DIR}/cpu_uart-${LAVA_DEVICE}" - CR50_UART="$(${DUT_CONTROL} ${PORT_FLAG} cr50_uart_pty | awk -F':' '{print $2}')" - [ -n "${CR50_UART}" ] && ln -fs "${CR50_UART}" "${PTS_DIR}/cr50_uart-${LAVA_DEVICE}" - EC_UART="$(${DUT_CONTROL} ${PORT_FLAG} ec_uart_pty | awk -F':' '{print $2}')" - [ -n "${EC_UART}" ] && ln -fs "${EC_UART}" "${PTS_DIR}/ec_uart-${LAVA_DEVICE}" + +/usr/bin/wait-for-it -t 120 localhost:${PORT} +if [ $? -eq 0 ]; then + sleep 5 + create_uart_links + echo "Started on ${DATE}" + wait ${PID} +else + echo "servod launch failed" + exit 1 fi -echo "Started on ${DATE}" -wait $PID -echo "servod has been terminated!!" +rm -f /servod.pid + +echo "servod has been terminated on `date`!!" + diff --git a/src/dockerfiles/servod/stop_servod.sh b/src/dockerfiles/servod/stop_servod.sh new file mode 100755 index 0000000..7a0aa78 --- /dev/null +++ b/src/dockerfiles/servod/stop_servod.sh @@ -0,0 +1,20 @@ +# Copyright 2021 The ChromiumOS Authors +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +#!/bin/bash + +set -x + +if [ -f "/servod.pid" ]; then + servod_pid=$(cat /servod.pid) + if $(kill -0 ${servod_pid}); then + dut-control -p $PORT "log_msg:Turning down servod." + + for CMD in iptables-legacy ip6tables-legacy ; do + $CMD -D INPUT -p tcp --dport $PORT -j ACCEPT || true + done + rm -f /servod.pid + kill -HUP ${servod_pid} + fi +fi -- cgit v1.2.3