diff --git a/snap/hooks/configure b/snap/hooks/configure index 0b083945..ce88cc20 100644 --- a/snap/hooks/configure +++ b/snap/hooks/configure @@ -1,12 +1,6 @@ #!/bin/sh -e -listen_port="$(snapctl get novncsvc.listen_port)" -vnc_host_port="$(snapctl get novncsvc.vnc_host_port)" +listen_port="$(snapctl get novncsvc.listen-port)" +vnc_host_port="$(snapctl get novncsvc.vnc-host-port)" - # Validate listen_port -if ! expr "$listen_port" : '^[0-9]\+$' > /dev/null; then - echo "\"$listen_port\" is not a valid port number" >&2 - return 1 -fi - -snapctl restart novncsvc +snapctl restart novnc.novncsvc diff --git a/snap/hooks/install b/snap/hooks/install new file mode 100644 index 00000000..bc71e91e --- /dev/null +++ b/snap/hooks/install @@ -0,0 +1,5 @@ +#!/bin/sh -e + +# Initialise settings to blank default values so that novncsvc won't start unless the user sets these values to something meaningful +snapctl set novncsvc.listen-port=0 +snapctl set novncsvc.vnc-host-port='' diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 7e6911cc..ff2e43ba 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -11,13 +11,14 @@ confinement: strict parts: novnc: - source: https://github.com/tkedwards/noVNC.git # https://github.com/novnc/noVNC.git #https://github.com/novnc/noVNC/archive/v$SNAPCRAFT_PROJECT_VERSION.tar.gz + source: . #https://github.com/tkedwards/noVNC.git # https://github.com/novnc/noVNC.git #https://github.com/novnc/noVNC/archive/v$SNAPCRAFT_PROJECT_VERSION.tar.gz plugin: dump - source-branch: snap_package stage-packages: - websockify hooks: + install: + plugs: [network, network-bind] configure: plugs: [network, network-bind] @@ -27,5 +28,5 @@ apps: plugs: [network, network-bind] novncsvc: command: utils/svc_wrapper.sh - daemon: simple + daemon: forking plugs: [network, network-bind] diff --git a/utils/svc_wrapper.sh b/utils/svc_wrapper.sh index 98b5861c..f87f737c 100755 --- a/utils/svc_wrapper.sh +++ b/utils/svc_wrapper.sh @@ -1,6 +1,13 @@ -#!/usr/bin/bash +#!/usr/bin/env bash -listen_port="$(snapctl get novncsvc.listen_port)" -vnc_host_port="$(snapctl get novncsvc.vnc_host_port)" +listen_port="$(snapctl get novncsvc.listen-port)" +vnc_host_port="$(snapctl get novncsvc.vnc-host-port)" -utils/launch.sh --listen $listen_port --vnc $vnc_host_port +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 + echo "novncsvc disabled" +else + ./utils/launch.sh --listen $listen_port --vnc $vnc_host_port +fi