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