2017-07-10 23:42:40 +08:00
|
|
|
#!/usr/bin/ruby
|
2020-01-22 06:14:39 +08:00
|
|
|
# frozen_string_literal: true
|
2017-07-10 23:42:40 +08:00
|
|
|
|
2020-01-22 06:14:39 +08:00
|
|
|
# Copyright © 2017 BigBlueButton Inc. and by respective authors.
|
2017-07-10 23:42:40 +08:00
|
|
|
#
|
|
|
|
# This file is part of BigBlueButton open source conferencing system.
|
|
|
|
#
|
|
|
|
# BigBlueButton is free software: you can redistribute it and/or modify it
|
|
|
|
# under the terms of the GNU Lesser General Public License as published by the
|
|
|
|
# Free Software Foundation, either version 3 of the License, or (at your
|
|
|
|
# option) any later version.
|
|
|
|
#
|
|
|
|
# BigBlueButton is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
|
|
|
# details.
|
2019-12-05 22:41:13 +08:00
|
|
|
#
|
2017-07-10 23:42:40 +08:00
|
|
|
# You should have received a copy of the GNU Lesser General Public License
|
|
|
|
# along with BigBlueButton. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2020-01-22 06:14:39 +08:00
|
|
|
require_relative '../lib/recordandplayback'
|
|
|
|
|
|
|
|
require 'recordandplayback/workers'
|
2017-07-10 23:42:40 +08:00
|
|
|
require 'rubygems'
|
|
|
|
require 'yaml'
|
|
|
|
require 'fileutils'
|
|
|
|
require 'resque'
|
2019-12-05 22:41:13 +08:00
|
|
|
require 'rb-inotify'
|
2017-07-10 23:42:40 +08:00
|
|
|
|
2019-12-07 04:06:32 +08:00
|
|
|
class StopSignalException < StandardError
|
|
|
|
end
|
|
|
|
|
2020-01-22 06:14:39 +08:00
|
|
|
def parse_meeting_id(done_file)
|
|
|
|
id = File.basename(done_file, '.done')
|
|
|
|
if (match = /^([0-9a-f]+-[0-9]+)$/.match(id))
|
|
|
|
{ meeting_id: match[1], break_timestamp: nil }
|
|
|
|
elsif (match = /^([0-9a-f]+-[0-9]+)-([0-9]+)$/.match(id))
|
|
|
|
{ meeting_id: match[1], break_timestamp: match[2] }
|
2019-12-05 22:41:13 +08:00
|
|
|
else
|
2020-01-22 06:14:39 +08:00
|
|
|
BigBlueButton.logger.warn("Recording done file #{done_file} has invalid format")
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def keep_meeting_events(recording_dir, ended_done_file)
|
|
|
|
id = File.basename(ended_done_file, '.done')
|
|
|
|
BigBlueButton.logger.debug("Seen new ended done file for #{id}")
|
|
|
|
attrs = parse_meeting_id(id)
|
|
|
|
return if attrs.nil?
|
|
|
|
|
|
|
|
# If a meeting was recorded, the events will be archived by the archive step, and
|
|
|
|
# the events script will be run after that (it'll grab the already archived events
|
|
|
|
# from the recording raw directory)
|
|
|
|
if File.exist?("#{recording_dir}/status/recorded/#{id}.done") || File.exist?("#{recording_dir}/raw/#{attrs[:meeting_id]}")
|
|
|
|
BigBlueButton.logger.info("Meeting #{id} had recording enabled, events will be handled after recording archive")
|
2019-12-05 22:41:13 +08:00
|
|
|
return
|
2017-07-10 23:42:40 +08:00
|
|
|
end
|
2019-12-05 22:41:13 +08:00
|
|
|
|
2020-01-22 06:14:39 +08:00
|
|
|
BigBlueButton.logger.info("Enqueueing job to keep events #{attrs.inspect}")
|
|
|
|
Resque.enqueue(BigBlueButton::Resque::EventsWorker, attrs)
|
|
|
|
FileUtils.rm_f(ended_done_file)
|
|
|
|
end
|
|
|
|
|
|
|
|
def archive_recorded_meetings(recording_dir, done_file)
|
|
|
|
id = File.basename(done_file, '.done')
|
|
|
|
BigBlueButton.logger.debug("Seen new recorded done file for #{id}")
|
|
|
|
attrs = parse_meeting_id(id)
|
|
|
|
return if attrs.nil?
|
|
|
|
|
|
|
|
# The keep events stuff uses this directory presence to check if a meeting is
|
|
|
|
# recorded when the recorded done file is gone
|
|
|
|
FileUtils.mkdir_p("#{recording_dir}/raw/#{attrs[:meeting_id]}")
|
|
|
|
|
2019-12-05 22:41:13 +08:00
|
|
|
BigBlueButton.logger.info("Enqueuing job to archive #{attrs.inspect}")
|
|
|
|
Resque.enqueue(BigBlueButton::Resque::ArchiveWorker, attrs)
|
2020-01-22 06:14:39 +08:00
|
|
|
FileUtils.rm_f(recorded_done_file)
|
2017-07-10 23:42:40 +08:00
|
|
|
end
|
|
|
|
|
2017-07-11 05:18:39 +08:00
|
|
|
begin
|
|
|
|
props = BigBlueButton.read_props
|
2017-07-10 23:42:40 +08:00
|
|
|
|
2017-07-14 04:48:02 +08:00
|
|
|
redis_host = props['redis_workers_host'] || props['redis_host']
|
|
|
|
redis_port = props['redis_workers_port'] || props['redis_port']
|
|
|
|
Resque.redis = "#{redis_host}:#{redis_port}"
|
|
|
|
|
2020-01-22 06:14:39 +08:00
|
|
|
BigBlueButton.logger.debug('Running rap-starter...')
|
2017-07-10 23:42:40 +08:00
|
|
|
|
2019-12-05 22:41:13 +08:00
|
|
|
recording_dir = props['recording_dir']
|
2020-01-22 06:14:39 +08:00
|
|
|
ended_status_dir = "#{recording_dir}/status/ended"
|
|
|
|
recorded_status_dir = "#{recording_dir}/status/recorded"
|
|
|
|
|
|
|
|
# Check for missed "ended" .done files
|
|
|
|
ended_done_files = Dir.glob("#{ended_status_dir}/*.done")
|
|
|
|
ended_done_files.each do |ended_done_file|
|
|
|
|
keep_meeting_events(recording_id, ended_done_file)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Check for missed "recorded" .done files
|
|
|
|
recorded_done_files = Dir.glob("#{recorded_status_dir}/*.done")
|
|
|
|
recorded_done_files.each do |recorded_done_file|
|
|
|
|
archive_recorded_meetings(recording_dir, recorded_done_file)
|
2019-12-06 22:50:08 +08:00
|
|
|
end
|
|
|
|
|
2020-01-22 06:14:39 +08:00
|
|
|
# Listen the directories for when new files are created
|
|
|
|
BigBlueButton.logger.info("Setting up inotify watch on #{ended_status_dir}")
|
2019-12-05 22:41:13 +08:00
|
|
|
notifier = INotify::Notifier.new
|
2020-01-22 06:14:39 +08:00
|
|
|
notifier.watch(ended_status_dir, :moved_to, :create) do |event|
|
2019-12-05 22:41:13 +08:00
|
|
|
next unless event.name.end_with?('.done')
|
2017-07-10 23:42:40 +08:00
|
|
|
|
2020-01-22 06:14:39 +08:00
|
|
|
keep_meeting_events(recording_dir, event.absolute_name)
|
|
|
|
end
|
|
|
|
BigBlueButton.logger.info("Setting up inotify watch on #{recorded_status_dir}")
|
|
|
|
notifier.watch(recorded_status_dir, :moved_to, :create) do |event|
|
|
|
|
next unless event.name.end_with?('.done')
|
|
|
|
|
|
|
|
archive_recorded_meetings(recording_dir, event.absolute_name)
|
2019-12-05 22:41:13 +08:00
|
|
|
end
|
2017-07-10 23:42:40 +08:00
|
|
|
|
2019-12-07 04:06:32 +08:00
|
|
|
BigBlueButton.logger.info('Waiting for new recordings...')
|
2020-01-22 06:14:39 +08:00
|
|
|
Signal.trap('INT') { raise StopSignalException, 'INT' }
|
|
|
|
Signal.trap('TERM') { raise StopSignalException, 'TERM' }
|
2019-12-05 22:41:13 +08:00
|
|
|
notifier.run
|
2019-12-07 04:06:32 +08:00
|
|
|
rescue StopSignalException
|
2019-12-07 03:30:28 +08:00
|
|
|
notifier.stop
|
2017-07-10 23:42:40 +08:00
|
|
|
end
|