From 71a2e6c1ed3ff80ebcbc7b1206c43e9eda1bbf55 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Thu, 30 May 2024 18:47:32 +0300 Subject: [PATCH] add wait for script --- kasmvnc/main.tf | 7 +++++++ kasmvnc/run.sh | 10 ++++++++++ 2 files changed, 17 insertions(+) diff --git a/kasmvnc/main.tf b/kasmvnc/main.tf index 02ee451..38a3ae5 100644 --- a/kasmvnc/main.tf +++ b/kasmvnc/main.tf @@ -26,12 +26,19 @@ variable "kasm_version" { default = "1.3.1" } +variable "wait_for_script" { + type = string + description = "The script to wait for before running the KasmVNC script." + default = "" +} + resource "coder_script" "kasm_vnc" { agent_id = var.agent_id display_name = "KasmVNC" icon = "/icon/kasmvnc.svg" script = templatefile("${path.module}/run.sh", { PORT : var.port, + WAIT_FOR_SCRIPT : var.wait_for_script, VERSION : var.kasm_version }) run_on_start = true diff --git a/kasmvnc/run.sh b/kasmvnc/run.sh index 37153d5..eb8f830 100644 --- a/kasmvnc/run.sh +++ b/kasmvnc/run.sh @@ -1,5 +1,15 @@ #!/usr/bin/env bash +# check if there is a WAIT_FOR_SCRIPT env variable and if so, wait for it to be available + +# Wait for the startup script to complete +if [ -n "$WAIT_FOR_SCRIPT" ]; then + # This assumes that the script will create a file called /tmp/.coder-${WAIT_FOR_SCRIPT}.done + while [ ! -f /tmp/.coder-${WAIT_FOR_SCRIPT}.done ]; do + sleep 1 + done +fi + # Check if desktop environment is installed if ! dpkg -s $PACKAGES &> /dev/null; then sudo apt-get update