From 7d291abcfd0733c12c46b66d3a82e91bc85e69f6 Mon Sep 17 00:00:00 2001
From: Gustavo Salazar <guga.salazar.loor@gmail.com>
Date: Mon, 14 Apr 2014 15:14:14 -0700
Subject: [PATCH] delete old raw dir from published recordings

---
 bigbluebutton-config/bin/bbb-record           |  9 +++++
 bigbluebutton-config/cron.daily/bigbluebutton | 33 +++++++++++++++++++
 .../scripts/publish/presentation.rb           | 17 ++++++++++
 3 files changed, 59 insertions(+)

diff --git a/bigbluebutton-config/bin/bbb-record b/bigbluebutton-config/bin/bbb-record
index e19815887b..4cc453e825 100755
--- a/bigbluebutton-config/bin/bbb-record
+++ b/bigbluebutton-config/bin/bbb-record
@@ -66,6 +66,15 @@ mark_for_rebuild() {
 
                 if [ -f $STATUS/processed/$MEETING_ID-$type.done ]; then
                         rm $STATUS/processed/$MEETING_ID-$type.done
+
+                if [ -f $STATUS/published/$MEETING_ID-$type.done ]; then
+                        rm $STATUS/published/$MEETING_ID-$type.done
+                fi
+
+                if [ -f $STATUS/published/$MEETING_ID-$type.fail ]; then
+                        rm $STATUS/published/$MEETING_ID-$type.fail
+                fi
+
 #                else
 #                        echo "Warn: Didn't find $STATUS/processed/$MEETING_ID-$type.done"
 #                        exit 1
diff --git a/bigbluebutton-config/cron.daily/bigbluebutton b/bigbluebutton-config/cron.daily/bigbluebutton
index 4015f39d54..7675833829 100755
--- a/bigbluebutton-config/cron.daily/bigbluebutton
+++ b/bigbluebutton-config/cron.daily/bigbluebutton
@@ -45,3 +45,36 @@ find /var/bigbluebutton/deskshare/ -name "*.flv" -mtime +$history -exec rm '{}'
 #
 find /var/freeswitch/meetings/ -name "*.wav" -mtime +$history -exec rm '{}' \;
 
+#
+# Delete old raw dirs from recordings properly published using 'presentation' scripts.
+#
+
+remove_raw_of_published_recordings(){
+    #TYPES=$(cd /usr/local/bigbluebutton/core/scripts/process; ls *.rb | sed s/.rb//g)
+    logger "Removing raw directory of old recordings:"
+    TYPES="presentation"
+    MIN_DAYS=10
+    old_meetings=$(find /var/bigbluebutton/recording/raw/*/events.xml  -mtime +$MIN_DAYS | cut -d"/" -f6 )
+    for meeting in $old_meetings
+    do
+        PROPERLY_PUBLISHED="true"
+        FAILED_TYPES=""
+        for type in $TYPES
+        do
+            file="/var/bigbluebutton/recording/status/published/$meeting-$type.done"
+            if ! [ -f "$file" ]; then
+                PROPERLY_PUBLISHED="false"
+                FAILED_TYPES="$FAILED_TYPES $type"
+            fi
+        done
+        if [ "$PROPERLY_PUBLISHED" == "true" ]; then
+            logger "$meeting properly published, removing raw dir."
+            rm -r /var/bigbluebutton/recording/raw/$meeting/
+        else
+            logger "$meeting was not properly published in [ $FAILED_TYPES ]"
+        fi
+    done 
+}
+
+#remove_raw_of_published_recordings
+
diff --git a/record-and-playback/presentation/scripts/publish/presentation.rb b/record-and-playback/presentation/scripts/publish/presentation.rb
index bcd2b3ad11..3076cee330 100755
--- a/record-and-playback/presentation/scripts/publish/presentation.rb
+++ b/record-and-playback/presentation/scripts/publish/presentation.rb
@@ -825,6 +825,9 @@ $playback = match[2]
 
 puts $meeting_id
 puts $playback
+
+begin
+
 if ($playback == "presentation")
 
 	# This script lives in scripts/archive/steps while properties.yaml lives in scripts/
@@ -978,11 +981,25 @@ if ($playback == "presentation")
 			end
 			exit 1
 		end
+        publish_done = File.new("#{recording_dir}/status/published/#{$meeting_id}-presentation.done", "w")
+        publish_done.write("Published #{$meeting_id}")
+        publish_done.close
+
 	else
 		BigBlueButton.logger.info("#{target_dir} is already there")
 	end
 end
 
 
+rescue Exception => e
+        BigBlueButton.logger.error(e.message)
+        e.backtrace.each do |traceline|
+            BigBlueButton.logger.error(traceline)
+        end
+        publish_done = File.new("#{recording_dir}/status/published/#{$meeting_id}-presentation.fail", "w")
+        publish_done.write("Failed Publishing #{$meeting_id}")
+        publish_done.close
 
+        exit 1
+end
 
-- 
GitLab