diff --git a/README.md b/README.md index 566b8e4f..bd34266c 100644 --- 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 index 00000000..ff4f8047 --- /dev/null +++ b/snap/hooks/configure @@ -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 index 00000000..e21ef6e5 --- /dev/null +++ b/snap/snapcraft.yaml @@ -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] diff --git a/utils/launch.sh b/utils/launch.sh index 6138b911..4cb6fc2b 100755 --- a/utils/launch.sh +++ b/utils/launch.sh @@ -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 index 00000000..51d74645 --- /dev/null +++ b/utils/svc_wrapper.sh @@ -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