From 93e5fa89563a616fb0c1b88531aa5b2f448de595 Mon Sep 17 00:00:00 2001 From: Keith Whyte Date: Wed, 24 Feb 2021 04:59:18 +0100 Subject: [PATCH] Use ncat with meas web for multiple clients --- modules/rhizo_base/files/etc/sv/meas-json/run | 8 +++++++- modules/rhizo_base/files/etc/sv/meas-json/scr | 3 +++ modules/rhizo_base/files/etc/sv/meas-web/run | 10 +--------- modules/rhizo_base/files/etc/sv/meas-web/scr | 3 --- modules/rhizo_base/manifests/packages.pp | 2 +- 5 files changed, 12 insertions(+), 14 deletions(-) create mode 100755 modules/rhizo_base/files/etc/sv/meas-json/scr delete mode 100755 modules/rhizo_base/files/etc/sv/meas-web/scr diff --git a/modules/rhizo_base/files/etc/sv/meas-json/run b/modules/rhizo_base/files/etc/sv/meas-json/run index 14b2915..bd9d9c7 100755 --- a/modules/rhizo_base/files/etc/sv/meas-json/run +++ b/modules/rhizo_base/files/etc/sv/meas-json/run @@ -1,4 +1,10 @@ #!/bin/bash exec 2>&1 -exec /usr/bin/stdbuf -oL /usr/bin/meas_json > /tmp/json_pipe +if [ -a /tmp/json_socket ]; then + killall ncat + killall meas_json + rm -f /tmp/json_socket +fi + +exec /etc/sv/meas-json/scr | ncat -l -U /tmp/json_socket -k --send-only diff --git a/modules/rhizo_base/files/etc/sv/meas-json/scr b/modules/rhizo_base/files/etc/sv/meas-json/scr new file mode 100755 index 0000000..e46c9c8 --- /dev/null +++ b/modules/rhizo_base/files/etc/sv/meas-json/scr @@ -0,0 +1,3 @@ +#!/bin/sh +exec 2>&1 +exec /usr/bin/stdbuf -oL /usr/bin/meas_json diff --git a/modules/rhizo_base/files/etc/sv/meas-web/run b/modules/rhizo_base/files/etc/sv/meas-web/run index 31f2836..eb59787 100755 --- a/modules/rhizo_base/files/etc/sv/meas-web/run +++ b/modules/rhizo_base/files/etc/sv/meas-web/run @@ -1,11 +1,3 @@ #!/bin/bash exec 2>&1 - -if [ ! -p /tmp/json_pipe ] ; then - if [ -f /tmp/json_pipe ] ; then - rm -f /tmp/json_pipe - fi - mkfifo /tmp/json_pipe -fi - -exec /usr/bin/websocketd --staticdir=/var/www/meas --port=8080 /etc/sv/meas-web/scr +exec /usr/bin/websocketd --staticdir=/var/www/meas --port=8080 ncat -U /tmp/json_socket diff --git a/modules/rhizo_base/files/etc/sv/meas-web/scr b/modules/rhizo_base/files/etc/sv/meas-web/scr deleted file mode 100755 index 65c0ed1..0000000 --- a/modules/rhizo_base/files/etc/sv/meas-web/scr +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -sv restart meas-json -exec cat /tmp/json_pipe diff --git a/modules/rhizo_base/manifests/packages.pp b/modules/rhizo_base/manifests/packages.pp index 0cea030..bc01cfc 100644 --- a/modules/rhizo_base/manifests/packages.pp +++ b/modules/rhizo_base/manifests/packages.pp @@ -30,7 +30,7 @@ class rhizo_base::packages::common { 'sngrep', 'rrdtool', 'dnsmasq', 'joe', 'curl', 'htop', 'screen', 'iperf3', 'websocketd', 'fping', 'mtr-tiny', 'openssh-server', 'telnet', 'netcat-traditional', 'python-unidecode', 'python-dateutil', 'python-yaml', 'python-formencode', - 'python-smpplib', 'python-psycopg2', 'python-pysqlite2' ]: + 'python-smpplib', 'python-psycopg2', 'python-pysqlite2', 'ncat' ]: ensure => installed, require => Class['rhizo_base::apt'], }