From 78c7096f2713d47cd28445e99532804713368576 Mon Sep 17 00:00:00 2001 From: Mariusz Marciniak Date: Fri, 29 Dec 2023 18:35:27 +0100 Subject: [PATCH 01/12] KASM-5378 Abort session if the recording service is not running or was not started by the correct user --- .../kasm_recorder_lifecycle_root.sh | 31 ----------------- .../kasm_recorder_startup.sh | 18 ---------- src/common/startup_scripts/vnc_startup.sh | 34 +++++++++++++++++++ 3 files changed, 34 insertions(+), 49 deletions(-) delete mode 100644 src/common/scripts/kasm_hook_scripts/kasm_recorder_lifecycle_root.sh delete mode 100755 src/common/scripts/kasm_hook_scripts/kasm_recorder_startup.sh diff --git a/src/common/scripts/kasm_hook_scripts/kasm_recorder_lifecycle_root.sh b/src/common/scripts/kasm_hook_scripts/kasm_recorder_lifecycle_root.sh deleted file mode 100644 index 80a3603..0000000 --- a/src/common/scripts/kasm_hook_scripts/kasm_recorder_lifecycle_root.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/bash - -action=$1 - -pid=$(pgrep -f '^/dockerstartup/recorder/kasm_recorder_service') - -case $action in - "stop"|"pause") - if [ -z "$pid" ]; then - echo "No recording process found." - exit 0 - fi - - kill -s SIGINT $pid - while [ ! -f "/tmp/kasm_recorder.ack" ]; do - sleep 1 - done - ;; - "resume") - if [ ! -z "$pid" ]; then - echo "Recording process already running." - exit 0 - fi - kill `pgrep -f "kasm_recorder_startup.sh"` - /dockerstartup/kasm_recorder_startup.sh & - ;; - *) - echo "Usage: $0 {stop|pause|resume}" - exit 1 - ;; -esac \ No newline at end of file diff --git a/src/common/scripts/kasm_hook_scripts/kasm_recorder_startup.sh b/src/common/scripts/kasm_hook_scripts/kasm_recorder_startup.sh deleted file mode 100755 index 7a71b15..0000000 --- a/src/common/scripts/kasm_hook_scripts/kasm_recorder_startup.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash -set -e - -mkdir -p /opt/kasm/recordings -sudo chown kasm-recorder:kasm-recorder /opt/kasm/recordings -sudo chmod 700 /opt/kasm/recordings - -# wait until X display is avaiable and allow the recorder to connect to it -while ! xhost +SI:localuser:kasm-recorder 2>/dev/null; do - sleep 1 -done - -rm -rf /tmp/kasm_recorder.ack - -while [ ! -f "/tmp/kasm_recorder.ack" ]; do - runuser -m kasm-recorder -c "$STARTUPDIR/recorder/kasm_recorder_service --debug 1 --directory /opt/kasm/recordings/ --log /tmp/recorder.log" || true - sleep 1 -done diff --git a/src/common/startup_scripts/vnc_startup.sh b/src/common/startup_scripts/vnc_startup.sh index 633b866..df88380 100755 --- a/src/common/startup_scripts/vnc_startup.sh +++ b/src/common/startup_scripts/vnc_startup.sh @@ -313,6 +313,37 @@ function custom_startup (){ fi } +function ensure_recorder_running () { + kasm_recorder_process="/dockerstartup/recorder/kasm_recorder_service" + + if [[ ${KASM_SVC_RECORDER:-1} != 1 ]]; then + return + fi + + recorder_pid=$(pgrep -f "^$kasm_recorder_process") || true + + if [[ -z $kasm_recorder_pid ]]; then + if [[ -z $recorder_pid ]] && (( $SECONDS > 15 )); then + echo "$kasm_recorder_process: not started, exiting" + exit 0 + fi + + kasm_recorder_pid=$recorder_pid + else + if [[ -z $recorder_pid ]]; then + echo "$kasm_recorder_process: not running, exiting" + exit 0 + fi + + recorder_user=$(ps -p $recorder_pid -o user=) + if [[ $recorder_user != "kasm-recorder" ]]; then + echo "$kasm_recorder_process: not running as kasm-recorder, exiting" + exit 0 + fi + fi +} + + ############ END FUNCTION DECLARATIONS ########### if [[ $1 =~ -h|--help ]]; then @@ -457,6 +488,9 @@ do esac fi done + + ensure_recorder_running + sleep 3 done From 395f8536ab2d0d0bab3077e1d86878d81115c199 Mon Sep 17 00:00:00 2001 From: Mariusz Marciniak Date: Sun, 31 Dec 2023 17:05:43 +0100 Subject: [PATCH 02/12] KASM-5378 Improve container pausing --- src/common/startup_scripts/vnc_startup.sh | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/common/startup_scripts/vnc_startup.sh b/src/common/startup_scripts/vnc_startup.sh index df88380..03bea21 100755 --- a/src/common/startup_scripts/vnc_startup.sh +++ b/src/common/startup_scripts/vnc_startup.sh @@ -314,13 +314,22 @@ function custom_startup (){ } function ensure_recorder_running () { - kasm_recorder_process="/dockerstartup/recorder/kasm_recorder_service" - if [[ ${KASM_SVC_RECORDER:-1} != 1 ]]; then return fi - recorder_pid=$(pgrep -f "^$kasm_recorder_process") || true + local kasm_recorder_process="/dockerstartup/recorder/kasm_recorder_service" + local kasm_recorder_ack="/tmp/kasm_recorder.ack" + + if [[ -f "$kasm_recorder_ack" ]]; then + local ack_user=$(stat -c '%U' $kasm_recorder_ack) + if [[ "$ack_user" == "kasm-recorder" ]]; then + SECONDS=0 + kasm_recorder_pid="" + fi + fi + + local recorder_pid=$(pgrep -f "^$kasm_recorder_process") || true if [[ -z $kasm_recorder_pid ]]; then if [[ -z $recorder_pid ]] && (( $SECONDS > 15 )); then From 5c8e3b9e928c89336f6518fa8d005b79d89496c1 Mon Sep 17 00:00:00 2001 From: Mariusz Marciniak Date: Tue, 2 Jan 2024 13:37:51 +0100 Subject: [PATCH 03/12] KASM-5378 Update kasm-recorder-service commit --- src/ubuntu/install/recorder/install_recorder.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ubuntu/install/recorder/install_recorder.sh b/src/ubuntu/install/recorder/install_recorder.sh index 6bc0f0d..da6e190 100644 --- a/src/ubuntu/install/recorder/install_recorder.sh +++ b/src/ubuntu/install/recorder/install_recorder.sh @@ -2,8 +2,8 @@ ### every exit != 0 fails the script set -e -COMMIT_ID="b9f195d8aac56b3127be9083470bddc360e30377" -BRANCH="main" +COMMIT_ID="2ffd3da2a103e3838ab3e5573bd7610546691218" +BRANCH="feature_KASM-5378_recording_errata" COMMIT_ID_SHORT=$(echo "${COMMIT_ID}" | cut -c1-6) ARCH=$(arch | sed 's/aarch64/arm64/g' | sed 's/x86_64/amd64/g') From 2892f64b84579becf02b1b405cf6ab44a57ad7dc Mon Sep 17 00:00:00 2001 From: Richard Koliser Date: Tue, 9 Jan 2024 12:33:25 -0500 Subject: [PATCH 04/12] KASM-5378 Add while loop to wait the 15 seconds --- src/common/startup_scripts/vnc_startup.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/common/startup_scripts/vnc_startup.sh b/src/common/startup_scripts/vnc_startup.sh index 03bea21..1b6ef95 100755 --- a/src/common/startup_scripts/vnc_startup.sh +++ b/src/common/startup_scripts/vnc_startup.sh @@ -324,13 +324,19 @@ function ensure_recorder_running () { if [[ -f "$kasm_recorder_ack" ]]; then local ack_user=$(stat -c '%U' $kasm_recorder_ack) if [[ "$ack_user" == "kasm-recorder" ]]; then - SECONDS=0 + SECONDS=0 #SECONDS is a built in bash variable that is incremented approximately every second kasm_recorder_pid="" fi fi local recorder_pid=$(pgrep -f "^$kasm_recorder_process") || true + while [ $SECONDS -lt 16 ] && [[ -z $recorder_pid ]] + do + local recorder_pid=$(pgrep -f "^$kasm_recorder_process") || true + sleep 1 + done + if [[ -z $kasm_recorder_pid ]]; then if [[ -z $recorder_pid ]] && (( $SECONDS > 15 )); then echo "$kasm_recorder_process: not started, exiting" From 104458fbd1676b2b9e00905942e6300dabf0ebb2 Mon Sep 17 00:00:00 2001 From: Justin Travis Date: Fri, 12 Jan 2024 08:10:32 -0500 Subject: [PATCH 05/12] KASM-5378 Rev Recording Service Commit --- src/ubuntu/install/recorder/install_recorder.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ubuntu/install/recorder/install_recorder.sh b/src/ubuntu/install/recorder/install_recorder.sh index da6e190..56b5d11 100644 --- a/src/ubuntu/install/recorder/install_recorder.sh +++ b/src/ubuntu/install/recorder/install_recorder.sh @@ -2,7 +2,7 @@ ### every exit != 0 fails the script set -e -COMMIT_ID="2ffd3da2a103e3838ab3e5573bd7610546691218" +COMMIT_ID="e19fbc6d8c6bd0eea88dd20be20e016e1be7024d" BRANCH="feature_KASM-5378_recording_errata" COMMIT_ID_SHORT=$(echo "${COMMIT_ID}" | cut -c1-6) From 07a282c010c1bab619595b7286c15b2c0791f3c5 Mon Sep 17 00:00:00 2001 From: Richard Koliser Date: Tue, 16 Jan 2024 13:07:46 -0500 Subject: [PATCH 06/12] KASM-5378 update recorder service commit. --- src/ubuntu/install/recorder/install_recorder.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ubuntu/install/recorder/install_recorder.sh b/src/ubuntu/install/recorder/install_recorder.sh index 56b5d11..a83e529 100644 --- a/src/ubuntu/install/recorder/install_recorder.sh +++ b/src/ubuntu/install/recorder/install_recorder.sh @@ -2,8 +2,8 @@ ### every exit != 0 fails the script set -e -COMMIT_ID="e19fbc6d8c6bd0eea88dd20be20e016e1be7024d" -BRANCH="feature_KASM-5378_recording_errata" +COMMIT_ID="c1fb295699b044a731e4ef3369808cbd39da1567" +BRANCH="feature_KASM-5446-refactor-kasm-recorder-service-to-attempt-to-eliminate-deadlocks-and-corrupt-videos" COMMIT_ID_SHORT=$(echo "${COMMIT_ID}" | cut -c1-6) ARCH=$(arch | sed 's/aarch64/arm64/g' | sed 's/x86_64/amd64/g') From 40ea60d229830d0ed717bda34c63624792626761 Mon Sep 17 00:00:00 2001 From: Richard Koliser Date: Tue, 16 Jan 2024 13:13:53 -0500 Subject: [PATCH 07/12] KASM-5378 remove redundant while loop. --- src/common/startup_scripts/vnc_startup.sh | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/common/startup_scripts/vnc_startup.sh b/src/common/startup_scripts/vnc_startup.sh index 1b6ef95..f0b7281 100755 --- a/src/common/startup_scripts/vnc_startup.sh +++ b/src/common/startup_scripts/vnc_startup.sh @@ -331,13 +331,8 @@ function ensure_recorder_running () { local recorder_pid=$(pgrep -f "^$kasm_recorder_process") || true - while [ $SECONDS -lt 16 ] && [[ -z $recorder_pid ]] - do - local recorder_pid=$(pgrep -f "^$kasm_recorder_process") || true - sleep 1 - done - if [[ -z $kasm_recorder_pid ]]; then + # This leverages the outside while loop that calls this function to provider checking ever x seconds. if [[ -z $recorder_pid ]] && (( $SECONDS > 15 )); then echo "$kasm_recorder_process: not started, exiting" exit 0 From bc933d9187a790b9b819ee8e44aab4ca000115a7 Mon Sep 17 00:00:00 2001 From: Richard Koliser Date: Tue, 16 Jan 2024 21:31:53 -0500 Subject: [PATCH 08/12] KASM-5378 merge of develop left an empty file that should be deleted. --- src/common/scripts/kasm_hook_scripts/kasm_recorder_startup.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100755 src/common/scripts/kasm_hook_scripts/kasm_recorder_startup.sh diff --git a/src/common/scripts/kasm_hook_scripts/kasm_recorder_startup.sh b/src/common/scripts/kasm_hook_scripts/kasm_recorder_startup.sh deleted file mode 100755 index e69de29..0000000 From a054d3b6890e63627f8194ac30040af1507dca49 Mon Sep 17 00:00:00 2001 From: Mariusz Marciniak Date: Wed, 17 Jan 2024 13:02:37 +0100 Subject: [PATCH 09/12] KASM-5378 Update vnc_startup.sh to wait until recorder service terminates in case of Xvnc being killed --- src/common/startup_scripts/vnc_startup.sh | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/common/startup_scripts/vnc_startup.sh b/src/common/startup_scripts/vnc_startup.sh index f0b7281..8db804d 100755 --- a/src/common/startup_scripts/vnc_startup.sh +++ b/src/common/startup_scripts/vnc_startup.sh @@ -353,6 +353,19 @@ function ensure_recorder_running () { fi } +function ensure_recorder_terminates_gracefully () { + local kasm_recorder_process="/dockerstartup/recorder/kasm_recorder_service" + + while true + do + recorder_pid=$(pgrep -f "$kasm_recorder_process") || true + if [[ -z $recorder_pid ]]; then + break + fi + + sleep 1 + done +} ############ END FUNCTION DECLARATIONS ########### @@ -452,6 +465,14 @@ do ;; window_manager) echo "Window manager crashed, restarting" + + if [[ ${KASM_SVC_RECORDER:-1} == 1 ]]; then + echo "Waiting for recorder service to upload all pending recordings" + ensure_recorder_terminates_gracefully + echo "Recorder service has terminated, exiting container" + exit 1 + fi + start_window_manager ;; kasm_audio_out_websocket) From 52b6ca192153de7bcd5a730b95a9e9b8ef554f6e Mon Sep 17 00:00:00 2001 From: Mariusz Marciniak Date: Thu, 18 Jan 2024 13:22:57 +0100 Subject: [PATCH 10/12] KASM-5378 Use the latest (6.1) static build of FFMPEG --- dockerfile-kasm-core | 7 +++++++ src/ubuntu/install/recorder/install_recorder.sh | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/dockerfile-kasm-core b/dockerfile-kasm-core index 1d30b0b..e3d5480 100644 --- a/dockerfile-kasm-core +++ b/dockerfile-kasm-core @@ -93,6 +93,13 @@ RUN bash $INST_SCRIPTS/printer/install_printer.sh && rm -rf $INST_SCRIPTS/printe COPY ./src/ubuntu/install/printer/resources/*.ppd /etc/cups/ppd/ ### Install Recorder Service + +RUN apt-get remove -y ffmpeg +RUN wget -q "https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-amd64-static.tar.xz" +RUN tar -xf ffmpeg-release-amd64-static.tar.xz -C . +RUN cp ./ffmpeg-6.1-amd64-static/ffmpeg /usr/local/bin +RUN rm -rf ./ffmpeg-* + COPY ./src/ubuntu/install/recorder $INST_SCRIPTS/recorder/ RUN bash $INST_SCRIPTS/recorder/install_recorder.sh && rm -rf $INST_SCRIPTS/recorder diff --git a/src/ubuntu/install/recorder/install_recorder.sh b/src/ubuntu/install/recorder/install_recorder.sh index 93af307..15fc4fe 100644 --- a/src/ubuntu/install/recorder/install_recorder.sh +++ b/src/ubuntu/install/recorder/install_recorder.sh @@ -12,7 +12,7 @@ elif [ "${DISTRO}" == "opensuse" ]; then zypper install -ny xhost fi -COMMIT_ID="c1fb295699b044a731e4ef3369808cbd39da1567" +COMMIT_ID="3bfd31d0a88c4d74ace9d7c7d12a95bc7f8ce7b7" BRANCH="feature_KASM-5446-refactor-kasm-recorder-service-to-attempt-to-eliminate-deadlocks-and-corrupt-videos" COMMIT_ID_SHORT=$(echo "${COMMIT_ID}" | cut -c1-6) From 3a790f352d0f92ebe10736c82920ca6a0501c384 Mon Sep 17 00:00:00 2001 From: Mariusz Marciniak Date: Tue, 23 Jan 2024 07:58:36 +0000 Subject: [PATCH 11/12] KASM-5458 Use local, static build of FFMPEG --- dockerfile-kasm-core | 7 ------- src/ubuntu/install/recorder/install_recorder.sh | 4 ++-- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/dockerfile-kasm-core b/dockerfile-kasm-core index e3d5480..1d30b0b 100644 --- a/dockerfile-kasm-core +++ b/dockerfile-kasm-core @@ -93,13 +93,6 @@ RUN bash $INST_SCRIPTS/printer/install_printer.sh && rm -rf $INST_SCRIPTS/printe COPY ./src/ubuntu/install/printer/resources/*.ppd /etc/cups/ppd/ ### Install Recorder Service - -RUN apt-get remove -y ffmpeg -RUN wget -q "https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-amd64-static.tar.xz" -RUN tar -xf ffmpeg-release-amd64-static.tar.xz -C . -RUN cp ./ffmpeg-6.1-amd64-static/ffmpeg /usr/local/bin -RUN rm -rf ./ffmpeg-* - COPY ./src/ubuntu/install/recorder $INST_SCRIPTS/recorder/ RUN bash $INST_SCRIPTS/recorder/install_recorder.sh && rm -rf $INST_SCRIPTS/recorder diff --git a/src/ubuntu/install/recorder/install_recorder.sh b/src/ubuntu/install/recorder/install_recorder.sh index 15fc4fe..a553a49 100644 --- a/src/ubuntu/install/recorder/install_recorder.sh +++ b/src/ubuntu/install/recorder/install_recorder.sh @@ -12,8 +12,8 @@ elif [ "${DISTRO}" == "opensuse" ]; then zypper install -ny xhost fi -COMMIT_ID="3bfd31d0a88c4d74ace9d7c7d12a95bc7f8ce7b7" -BRANCH="feature_KASM-5446-refactor-kasm-recorder-service-to-attempt-to-eliminate-deadlocks-and-corrupt-videos" +COMMIT_ID="85891331d5c6942b1471055803f3af25d722c699" +BRANCH="feature_KASM-5458-fix-ffmpeg-video-corruption-when-container-is-killed" COMMIT_ID_SHORT=$(echo "${COMMIT_ID}" | cut -c1-6) ARCH=$(arch | sed 's/aarch64/arm64/g' | sed 's/x86_64/amd64/g') From c3a0005bf74e81c8f7f7ebb07ebf351d871d56f5 Mon Sep 17 00:00:00 2001 From: Richard Koliser Date: Tue, 23 Jan 2024 13:22:50 -0500 Subject: [PATCH 12/12] KASM-5458 Update branch/commit for kasm-recorder-service --- src/ubuntu/install/recorder/install_recorder.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ubuntu/install/recorder/install_recorder.sh b/src/ubuntu/install/recorder/install_recorder.sh index a553a49..1696b52 100644 --- a/src/ubuntu/install/recorder/install_recorder.sh +++ b/src/ubuntu/install/recorder/install_recorder.sh @@ -12,8 +12,8 @@ elif [ "${DISTRO}" == "opensuse" ]; then zypper install -ny xhost fi -COMMIT_ID="85891331d5c6942b1471055803f3af25d722c699" -BRANCH="feature_KASM-5458-fix-ffmpeg-video-corruption-when-container-is-killed" +COMMIT_ID="bf2696c063b307591483a21693542dd360a3baa6" +BRANCH="main" COMMIT_ID_SHORT=$(echo "${COMMIT_ID}" | cut -c1-6) ARCH=$(arch | sed 's/aarch64/arm64/g' | sed 's/x86_64/amd64/g')