3 # `snapctl get services` returns a JSON array, example:
7 # "vnc": "localhost:5901"
11 # "vnc": "localhost:5902"
14 snapctl get services | jq
-c '.[]' |
while read service
; do # for each service the user sepcified..
15 # get the important data for the service (listen port, VNC host:port)
16 listen_port
="$(echo $service | jq --raw-output '.listen')"
17 vnc_host_port
="$(echo $service | jq --raw-output '.vnc')" # --raw-output removes any quotation marks from the output
19 # check whether those values are valid
20 expr "$listen_port" : '^[0-9]\+$' > /dev
/null
22 if [ ! $listen_port_valid ] ||
[ -z "$vnc_host_port" ]; then
23 # invalid values mean the service is disabled, do nothing except for printing a message (logged in /var/log/system or systemd journal)
24 echo "novnc: not starting service ${service} with listen_port ${listen_port} and vnc_host_port ${vnc_host_port}"
26 # start (and fork with '&') the service using the specified listen port and VNC host:port
27 $SNAP/utils
/launch.sh
--listen $listen_port --vnc $vnc_host_port &