]> git.proxmox.com Git - mirror_novnc.git/commitdiff
Added a Snap package for noVNC (#1231)
authorTim Edwards <liststuff@fastmail.com.au>
Thu, 25 Jul 2019 20:22:48 +0000 (06:22 +1000)
committerSamuel Mannehed <samuel@cendio.se>
Thu, 25 Jul 2019 20:22:48 +0000 (22:22 +0200)
Creating an Ubuntu Snap package to make noVNC easier to deploy.

Checks for the websockify binary in both the PATH (using which) and in the location where the Snap package places the binary. This is necessary for noVNC to be usable in a Snap. It doesn't affect the original functionality of git cloning websockify if it's not found in PATH or the Snap location.

README.md
snap/hooks/configure [new file with mode: 0644]
snap/snapcraft.yaml [new file with mode: 0644]
utils/launch.sh
utils/svc_wrapper.sh [new file with mode: 0755]

index 566b8e4f5afa139e544134bcf4efcaa7f79d1d4b..bd34266cfeb2e3f9d102f285def6caa3b75344e8 100644 (file)
--- a/README.md
+++ b/README.md
@@ -24,6 +24,7 @@ for a more complete list with additional info and links.
 - [Browser Requirements](#browser-requirements)
 - [Server Requirements](#server-requirements)
 - [Quick Start](#quick-start)
+- [Installation from Snap Package](#installation-from-snap-package)
 - [Integration and Deployment](#integration-and-deployment)
 - [Authors/Contributors](#authorscontributors)
 
@@ -115,6 +116,66 @@ proxy.
   script. Hit the Connect button, enter a password if the VNC server has one
   configured, and enjoy!
 
+### Installation from Snap Package
+Running the command below will install the latest release of noVNC from Snap:
+
+`sudo snap install novnc`
+
+#### Running noVNC
+
+You can run the Snap-package installed novnc directly with, for example:
+
+`novnc --listen 6081 --vnc localhost:5901 # /snap/bin/novnc if /snap/bin is not in your PATH`
+
+#### Running as a Service (Daemon)
+The Snap package also has the capability to run a 'novnc' service which can be 
+configured to listen on multiple ports connecting to multiple VNC servers 
+(effectively a service runing multiple instances of novnc).
+Instructions (with example values):
+
+List current services (out-of-box this will be blank):
+
+```
+sudo snap get novnc services
+Key             Value
+services.n6080  {...}
+services.n6081  {...}
+```
+
+Create a new service that listens on port 6082 and connects to the VNC server 
+running on port 5902 on localhost:
+
+`sudo snap set novnc services.n6082.listen=6082 services.n6082.vnc=localhost:5902`
+
+(Any services you define with 'snap set' will be automatically started)
+Note that the name of the service, 'n6082' in this example, can be anything 
+as long as it doesn't start with a number or contain spaces/special characters.
+
+View the configuration of the service just created:
+
+```
+sudo snap get novnc services.n6082
+Key                    Value
+services.n6082.listen  6082
+services.n6082.vnc     localhost:5902
+```
+
+Disable a service (note that because of a limitation in  Snap it's currently not 
+possible to unset config variables, setting them to blank values is the way 
+to disable a service):
+
+`sudo snap set novnc services.n6082.listen='' services.n6082.vnc=''`
+
+(Any services you set to blank with 'snap set' like this will be automatically stopped)
+
+Verify that the service is disabled (blank values):
+
+```
+sudo snap get novnc services.n6082
+Key                    Value
+services.n6082.listen  
+services.n6082.vnc
+```
 
 ### Integration and Deployment
 
diff --git a/snap/hooks/configure b/snap/hooks/configure
new file mode 100644 (file)
index 0000000..ff4f804
--- /dev/null
@@ -0,0 +1,3 @@
+#!/bin/sh -e
+
+snapctl restart novnc.novncsvc
diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml
new file mode 100644 (file)
index 0000000..e21ef6e
--- /dev/null
@@ -0,0 +1,34 @@
+name: novnc
+base: core18 # the base snap is the execution environment for this snap
+version: '1.1.0'
+summary: Open Source VNC client using HTML5 (WebSockets, Canvas)
+description: |
+  Open Source VNC client using HTML5 (WebSockets, Canvas).
+  noVNC is both a VNC client JavaScript library as well as an application built on top of that library. noVNC runs well in any modern browser including mobile browsers (iOS and Android).
+
+grade: stable
+confinement: strict
+
+parts:
+    novnc:
+        source: https://github.com/novnc/noVNC.git #https://github.com/novnc/noVNC/archive/v$SNAPCRAFT_PROJECT_VERSION.tar.gz 
+        plugin: dump
+        stage-packages:
+            - websockify
+            - bash
+            - jq
+            - python-numpy
+            - python3-numpy
+
+hooks:
+    configure:
+        plugs: [network, network-bind]
+
+apps:
+    novnc:
+        command: utils/launch.sh
+        plugs: [network, network-bind]
+    novncsvc:
+        command: utils/svc_wrapper.sh
+        daemon: forking
+        plugs: [network, network-bind]
index 6138b91198508afabaddef4f382997e2942d3693..4cb6fc2b30f7c12d8ff8ff9f9a0ed5151fe82a83 100755 (executable)
@@ -139,9 +139,12 @@ if [[ -d ${HERE}/websockify ]]; then
 
     echo "Using local websockify at $WEBSOCKIFY"
 else
-    WEBSOCKIFY=$(which websockify 2>/dev/null)
+    WEBSOCKIFY_FROMSYSTEM=$(which websockify 2>/dev/null)
+    WEBSOCKIFY_FROMSNAP=${HERE}/../usr/bin/python2-websockify
+    [ -f $WEBSOCKIFY_FROMSYSTEM ] && WEBSOCKIFY=$WEBSOCKIFY_FROMSYSTEM
+    [ -f $WEBSOCKIFY_FROMSNAP ] && WEBSOCKIFY=$WEBSOCKIFY_FROMSNAP
 
-    if [[ $? -ne 0 ]]; then
+    if [ ! -f "$WEBSOCKIFY" ]; then
         echo "No installed websockify, attempting to clone websockify..."
         WEBSOCKIFY=${HERE}/websockify/run
         git clone https://github.com/novnc/websockify ${HERE}/websockify
diff --git a/utils/svc_wrapper.sh b/utils/svc_wrapper.sh
new file mode 100755 (executable)
index 0000000..51d7464
--- /dev/null
@@ -0,0 +1,29 @@
+#!/bin/bash
+
+# `snapctl get services` returns a JSON array, example:
+#{
+#"n6801": {
+#   "listen": 6801,
+#   "vnc": "localhost:5901"
+#},
+#"n6802": {
+#    "listen": 6802,
+#   "vnc": "localhost:5902"
+#}
+#}
+snapctl get services | jq -c '.[]' | while read service; do # for each service the user sepcified..
+    # get the important data for the service (listen port, VNC host:port)
+    listen_port="$(echo $service | jq --raw-output '.listen')"
+    vnc_host_port="$(echo $service | jq --raw-output '.vnc')" # --raw-output removes any quotation marks from the output
+    
+    # check whether those values are valid
+    expr "$listen_port" : '^[0-9]\+$' > /dev/null
+    listen_port_valid=$?
+    if [ ! $listen_port_valid ] || [ -z "$vnc_host_port" ]; then
+        # invalid values mean the service is disabled, do nothing except for printing a message (logged in /var/log/system or systemd journal)
+        echo "novnc: not starting service ${service} with listen_port ${listen_port} and vnc_host_port ${vnc_host_port}"
+    else
+        # start (and fork with '&') the service using the specified listen port and VNC host:port
+        $SNAP/utils/launch.sh --listen $listen_port --vnc $vnc_host_port &
+    fi
+done