From d98d8500aee720fb03465938e7a4a263d62ebd2c Mon Sep 17 00:00:00 2001 From: rodion Date: Thu, 11 Jan 2024 01:36:28 +0000 Subject: [PATCH] feat: refactor and allow running in background --- start.sh | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/start.sh b/start.sh index 6a6547cb..da7199fb 100755 --- a/start.sh +++ b/start.sh @@ -1,5 +1,7 @@ #!/bin/bash -# export FORCE_REINSTALL_TURBOVNC=1 to reinstall turbovnc to the latest version +# Sample usage: RUN_IN_BACKGROUND=1 ./start.sh +# set FORCE_REINSTALL_TURBOVNC=1 to reinstall turbovnc to the latest version +# set RUN_IN_BACKGROUND=1 to start proxy and vnc client in background set -e @@ -9,6 +11,7 @@ cd "$SCRIPT_DIR" . ./utils/shell-logger hasUpdated=0 +NOVNC_PORT=6080 # desktop environment installation if ! dpkg-query -W -f='${Status}' xfce4 2>/dev/null | grep -q "install ok installed"; then @@ -44,21 +47,35 @@ startxfce4 & EOF display=$(/opt/TurboVNC/bin/vncserver -list | grep -E "^:" | awk '{print $1}') +displayNumber=${display/:} +info "previous display number $displayNumber" if [ ! -z $display ]; then info "restarting vnc server on display $display" /opt/TurboVNC/bin/vncserver -kill $display +else + info "no display found" fi /opt/TurboVNC/bin/vncserver -localhost -depth 24 -geometry 3440x1440 +display=$(/opt/TurboVNC/bin/vncserver -list | grep -E "^:" | awk '{print $1}') +displayNumber=${display/:} +displayPort=$((5900+$displayNumber)) +info "display number $displayNumber, display port $displayPort" cd utils # Start noVNC info "starting vnc client and forwarder" -if lsof -t -i:6080; then - kill -9 $(lsof -t -i:6080) +if lsof -t -i:$NOVNC_PORT>/dev/null; then + info "previous novnc client detected, killing process now" + kill -9 $(lsof -t -i:$NOVNC_PORT) fi -echo "6080-$WEB_HOST:80" - -./novnc_proxy --vnc localhost:5901 +if [ ! -z $RUN_IN_BACKGROUND ]; then + info "running novnc proxy in background" + mkdir -p ~/logs + ./novnc_proxy --vnc localhost:$displayPort &> ~/logs/novnc.log & + printf "\nNavigate to this URL:\n\n$NOVNC_PORT-$WEB_HOST/vnc.html\n" +else + ./novnc_proxy --vnc localhost:$displayPort +fi