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.
- [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)
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
--- /dev/null
+#!/bin/sh -e
+
+snapctl restart novnc.novncsvc
--- /dev/null
+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]
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
--- /dev/null
+#!/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