use bash to monitor files

This commit is contained in:
Sofyan Sugianto 2020-06-18 04:41:59 +07:00
parent 60c5b1890b
commit 9ce65a23f0
2 changed files with 58 additions and 21 deletions

View File

@ -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

View File

@ -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)