svc_wrapper.sh 1.2 KB

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