From 9ce65a23f05a97cd4a00341f1d4e1820a77c08d5 Mon Sep 17 00:00:00 2001 From: Sofyan Sugianto Date: Thu, 18 Jun 2020 04:41:59 +0700 Subject: [PATCH] use bash to monitor files --- .../record-monitor.sh | 58 +++++++++++++++++++ .../recorder-monitor.py | 21 ------- 2 files changed, 58 insertions(+), 21 deletions(-) create mode 100755 mod/core/bbb-playback-presentation/record-monitor.sh delete mode 100644 mod/core/bbb-playback-presentation/recorder-monitor.py diff --git a/mod/core/bbb-playback-presentation/record-monitor.sh b/mod/core/bbb-playback-presentation/record-monitor.sh new file mode 100755 index 0000000..df7459a --- /dev/null +++ b/mod/core/bbb-playback-presentation/record-monitor.sh @@ -0,0 +1,58 @@ +#!/bin/bash + +# /var/bigbluebutton/recording/status/processed/*.done -> publish-worker.rb +# /var/bigbluebutton/recording/status/sanity/*.done -> process-worker +# /var/bigbluebutton/recording/status/ended/*.done -> events-worker +# /var/bigbluebutton/recording/status/recorded/*.done -> archive-worker +# /var/bigbluebutton/recording/status/archived/*.done -> sanity-worker + +FILES_TO_CHECK=$1 + +PATH_TO_CHECK="/var/bigbluebutton/recording/status" +CMD_DIR_PATH="/usr/local/bigbluebutton/core/scripts" + +function do_monitoring() { + check_done_files + while ! compgen -G "$PATH_TO_CHECK" > /dev/null; do + echo "$PATH_TO_CHECK returning 0 files, sleeping for 30s..." + sleep 30 + done + if [[ -d "$CMD_DIR_PATH" ]]; then + pushd $CMD_DIR_PATH > /dev/null + ruby $CMD_PATH + popd > /dev/null + fi + sleep 5 + echo "Re-monitoring files.." + do_monitoring +} + +function check_done_files() { + echo "$FILES_TO_CHECK" + if [[ ! -z $FILES_TO_CHECK ]]; then + if [[ $FILES_TO_CHECK == "processed" ]]; then + PATH_TO_CHECK="$PATH_TO_CHECK/processed/*.done" + CMD_PATH="/usr/local/bigbluebutton/core/scripts/rap-publish-worker.rb" + elif [[ $FILES_TO_CHECK == "sanity" ]]; then + PATH_TO_CHECK="$PATH_TO_CHECK/sanity/*.done" + CMD_PATH="/usr/local/bigbluebutton/core/scripts/rap-process-worker.rb" + elif [[ $FILES_TO_CHECK == "ended" ]]; then + PATH_TO_CHECK="$PATH_TO_CHECK/ended/*.done" + CMD_PATH="/usr/local/bigbluebutton/core/scripts/rap-events-worker.rb" + elif [[ $FILES_TO_CHECK == "recorded" ]]; then + PATH_TO_CHECK="$PATH_TO_CHECK/recorded/*.done" + CMD_PATH="/usr/local/bigbluebutton/core/scripts/rap-archive-worker.rb" + elif [[ $FILES_TO_CHECK == "archived" ]]; then + PATH_TO_CHECK="$PATH_TO_CHECK/archived/*.done" + CMD_PATH="/usr/local/bigbluebutton/core/scripts/rap-sanity-worker.rb" + else + echo "invalid argument, exiting..." + exit + fi + else + echo "invalid argument, exiting..." + exit + fi +} + +do_monitoring diff --git a/mod/core/bbb-playback-presentation/recorder-monitor.py b/mod/core/bbb-playback-presentation/recorder-monitor.py deleted file mode 100644 index 1403b61..0000000 --- a/mod/core/bbb-playback-presentation/recorder-monitor.py +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env python3 - -import time -import argparse -import subprocess -import glob - -PATH_MONITOR = "/var/bigbluebutton/recording/status/" - -def file_monitor(event_to_check): - done_files = glob.glob(PATH_MONITOR + event_to_check + "/*.done") # List - while len(done_files) == 0: - time.sleep(5) - done_files = glob.glob(PATH_MONITOR + event_to_check + "/*.done") # List - subprocess.Popen("/usr/local/bigbluebutton/scripts/rap-"+event_to_check+"-worker.rb", cwd="/usr/local/bigbluebutton/core/scripts") - -if __name__ == "__main__": - parser = argparse.ArgumentParser() - parser.add_argument("--event", type=str, dest="event_to_check", help="Event to check (archive, events, process, publish, sanity)") - args = parser.parse_args() - file_monitor(args.event_to_check)