Further work on getting configurable service setup

This commit is contained in:
Tim Edwards 2019-05-09 05:24:15 +02:00
parent 99d4b9218e
commit 473810e676
4 changed files with 23 additions and 16 deletions

12
snap/hooks/configure vendored
View File

@ -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

5
snap/hooks/install Normal file
View File

@ -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=''

View File

@ -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]

View File

@ -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