From c2930509fc8a4ad0402050a9540e957484c405a6 Mon Sep 17 00:00:00 2001 From: pitchum Date: Sat, 16 May 2020 15:12:45 +0200 Subject: [PATCH] Add an admin script to check if mumble's WebUI is currently in use. --- active_web_users | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100755 active_web_users diff --git a/active_web_users b/active_web_users new file mode 100755 index 0000000..2da9567 --- /dev/null +++ b/active_web_users @@ -0,0 +1,31 @@ +#! /bin/bash + +# Parse mumble logs in order to determine if someone is currently accessing +# mumble through the WebUI. If not it means we can safely restart nginx +# on the reverse-proxy side without bothering anyone :) + +MUMBLE_LOG=/var/log/mumble-server/mumble-server.log + + +main() { + candidates=$(last_connections) + for candidate in ${candidates}; do + grep "<${candidate}:" "${MUMBLE_LOG}" | tail -n 1 | grep -q 'Connection closed' + if [ $? -ne 0 ]; then + echo "At least one person is currently using mumble's Web interface." + grep "<${candidate}:" "${MUMBLE_LOG}" | tail -n 5 + exit 1 + fi + done + echo "It looks like nobody is currently using mumble's Web interface. You may restart nginx if you want ;)" + exit 0 +} + +last_connections() { + grep 'Client.*Node.js' "${MUMBLE_LOG}" \ + | tail -n 10 \ + | sed -r 's/^.*=> <([0-9]+):\(-1\)>.*$/\1/' \ + | tac +} + +main