diff --git a/Dockerfile b/Dockerfile index b2e558d..3e24dfd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,6 +12,8 @@ RUN apt-get install -y wget RUN apt-get install -y git make gcc RUN apt-get install -y icewm RUN apt-get install -y x11-apps +RUN apt-get install -y bc +RUN apt-get install -y net-tools socat python3-numpy FROM base as build ADD https://github.com/TurboVNC/turbovnc/releases/download/3.1.1/turbovnc_3.1.1_amd64.deb /tmp/ @@ -24,9 +26,6 @@ RUN dpkg -i turbovnc_3.1.1_amd64.deb WORKDIR "/tmp/websockify" RUN make -j4 -# develop only -RUN apt-get install -y net-tools socat python3-numpy - ENV PATH=$PATH:/opt/TurboVNC/bin RUN mkdir ~/.vnc/ RUN echo $PASSWORD | vncpasswd -f > ~/.vnc/passwd diff --git a/app/app.sh b/app/app.sh index a5aac13..373cdb7 100755 --- a/app/app.sh +++ b/app/app.sh @@ -1,18 +1,33 @@ #!/usr/bin/env bash set -x +# Signal helper source /app/signals.sh -signals_trap_with_arg func_trap TERM +PID=0 +TERM_handler() { + SIGNAME="$1" + echo "Killing ${PID}" + echo "Signal ${SIGNAME}" + if [ ${PID} -ne 0 ]; then + ps -ef --forest + CHILDS=$(pgrep -P "${PID}") + kill -"${SIGNAME}" -"${PID}" + for i in $CHILDS; do + wait $i + done + fi + ps -ef --forest + ret=$(signal_return_val ${SIGNAME}) + exit $ret +} +signals_trap_with_arg TERM_handler SIGTERM /app/server.sh & -PID=-1 +PID=$$ # wait forever -while true -do - tail -f /dev/null & wait ${!} -done +signals_wait_forever # https://docs.docker.com/compose/faq/ # https://medium.com/@gchudnov/trapping-signals-in-docker-containers-7a57fdda7d86 \ No newline at end of file diff --git a/app/signals.sh b/app/signals.sh index 0e01957..bd48be3 100644 --- a/app/signals.sh +++ b/app/signals.sh @@ -1,5 +1,3 @@ -PID=0 - signals_trap_with_arg() { func="$1" ; shift for sig ; do @@ -8,14 +6,20 @@ signals_trap_with_arg() { done } -func_trap() { - echo "Trapped: $1" - echo "Killing ${PID}" - if [ ${PID} -ne 0 ]; then - kill -SIGTERM "${PID}" - wait "${PID}" - fi - ps -ef --forest +signals_wait_forever() { + while true + do + tail -f /dev/null & wait ${!} + done +} - exit 143 +signal_name_to_number() { + SIGNAME="$1" + trap -l | sed -nr "s/.*\b([0-9]+)\) $SIGNAME.*/\1/p" +} + +signal_return_val() { + SIGNAME="$1" + SIGNUM=$(signal_name_to_number ${SIGNAME}) + echo "128 + $SIGNUM" | bc }