[yocto] [yocto-autobuilder-helper][PATCH]] checkvnc, run-config, config.json: DISPLAY=:1

Thomas Goodwin btgoodwin at geontech.com
Tue Aug 6 10:25:51 PDT 2019


The original check of /proc/net/tcp did not work on
a headless Ubuntu 18.04.02 server.  This new check-
-and-reset routine should be equivalent if the script
is executed.  The assumption of DISPLAY=:1 was also
troublesome in an environment where multiple VNC
servers are running.

Changes:

If the user sources this script, it will perform the
new check-and-reset function as well as set DISPLAY to
the instance found.  This means EXTRACMD on certain
builds can now be, e.g.:

   source ${SCRIPTSDIR}/checkvnc; oe-selftest ...

This change has been added to run-config and config.json.

Signed-off-by: Thomas Goodwin <btgoodwin at geontech.com>
---
 config.json        |  8 ++++----
 scripts/checkvnc   | 35 +++++++++++++++++++++++++++++------
 scripts/run-config |  2 +-
 3 files changed, 34 insertions(+), 11 deletions(-)

diff --git a/config.json b/config.json
index 2252b83..3d13720 100644
--- a/config.json
+++ b/config.json
@@ -67,7 +67,7 @@
             },
             "step3" : {
                 "BUILDHISTORY" : false,
-                "EXTRACMDS" : ["${SCRIPTSDIR}/checkvnc; DISPLAY=:1 oe-selftest -r runqemu meta_ide -j 15"],
+                "EXTRACMDS" : ["source ${SCRIPTSDIR}/checkvnc; oe-selftest -r runqemu meta_ide -j 15"],
                 "ADDLAYER" : ["${BUILDDIR}/../meta-selftest"]
             }
         },
@@ -149,7 +149,7 @@
                 "EXTRACMDS" : ["bitbake-selftest"]
             },
             "step2" : {
-                "EXTRACMDS" : ["${SCRIPTSDIR}/checkvnc; DISPLAY=:1 oe-selftest --skip-tests distrodata.Distrodata.test_checkpkg buildoptions.SourceMirroring.test_yocto_source_mirror -j 15"],
+                "EXTRACMDS" : ["source ${SCRIPTSDIR}/checkvnc; oe-selftest --skip-tests distrodata.Distrodata.test_checkpkg buildoptions.SourceMirroring.test_yocto_source_mirror -j 15"],
                 "ADDLAYER" : ["${BUILDDIR}/../meta-selftest"]
             },
             "step3" : {
@@ -166,7 +166,7 @@
                 ]
             },
             "step2" : {
-                "EXTRACMDS" : ["${SCRIPTSDIR}/checkvnc; DISPLAY=:1 oe-selftest -r buildoptions.SourceMirroring.test_yocto_source_mirror"],
+                "EXTRACMDS" : ["source ${SCRIPTSDIR}/checkvnc; oe-selftest -r buildoptions.SourceMirroring.test_yocto_source_mirror"],
                 "ADDLAYER" : ["${BUILDDIR}/../meta-selftest"]
             }
         }
@@ -280,7 +280,7 @@
                 "extravars" : [
                     "RPM_GPG_SIGN_CHUNK = '1'"
                 ],
-                "EXTRACMDS" : ["${SCRIPTSDIR}/checkvnc; DISPLAY=:1 oe-selftest --skip-tests distrodata.Distrodata.test_checkpkg buildoptions.SourceMirroring.test_yocto_source_mirror -j 15"],
+                "EXTRACMDS" : ["source ${SCRIPTSDIR}/checkvnc; oe-selftest --skip-tests distrodata.Distrodata.test_checkpkg buildoptions.SourceMirroring.test_yocto_source_mirror -j 15"],
                 "ADDLAYER" : ["${BUILDDIR}/../meta-selftest"]
             }
         },
diff --git a/scripts/checkvnc b/scripts/checkvnc
index 11e03bb..3935213 100755
--- a/scripts/checkvnc
+++ b/scripts/checkvnc
@@ -1,10 +1,33 @@
 #!/bin/sh
 #
-# check if vnc server is running, and if not, cleanup and restart
+# Description: checks if vnc server is running, and if not, cleanup and restart
+# 
+# Source this file if you want DISPLAY set to the result
+# Execute this file if you only want the "check and restart" behavior.
 #
-grep ':170D' /proc/net/tcp > /dev/null
-if [ $? != 0 ]; then
-    echo "Xvnc not running, attempting restart"
-    vncserver -kill :1
+unset DISPLAY
+
+checkvnc() {
+    for pid_file in ~/.vnc/*.pid; do
+        [ -f "$pid_file" ] || break
+        vnc_display=$(echo $(basename "$pid_file") | cut -f 1 -d '.')
+
+        # Test if running
+        kill -0 $(cat "$pid_file") > /dev/null
+        if [ $? == 0 ]; then
+            echo "Found running Xvnc server at $vnc_display"
+            DISPLAY=":$(echo $vnc_display | cut -d ':' -f 2)"
+            break
+        else
+            echo "Cleaning up display: $vnc_display"
+            vncserver -kill "$vnc_display"
+        fi
+    done
+}
+
+checkvnc
+if [ -z "$DISPLAY" ]; then
+    echo "Starting Xvnc"
     vncserver
-fi
+    checkvnc
+fi
\ No newline at end of file
diff --git a/scripts/run-config b/scripts/run-config
index fe89163..2b39822 100755
--- a/scripts/run-config
+++ b/scripts/run-config
@@ -168,7 +168,7 @@ for stepnum in range(1, maxsteps + 1):
     sanitytargets = utils.getconfigvar("SANITYTARGETS", ourconfig, args.target, stepnum)
     if sanitytargets:
         hp.printheader("Step %s/%s: Running bitbake %s" % (stepnum, maxsteps, sanitytargets))
-        bitbakecmd(args.builddir, "%s/checkvnc; DISPLAY=:1 bitbake %s -k" % (scriptsdir, sanitytargets), report, stepnum, 'c')
+        bitbakecmd(args.builddir, "source %s/checkvnc; bitbake %s -k" % (scriptsdir, sanitytargets), report, stepnum, 'c')
 
     # Run any extra commands specified
     cmds = utils.getconfiglist("EXTRACMDS", ourconfig, args.target, stepnum)
-- 
2.17.1



More information about the yocto mailing list