diff --git a/docker-compose.yml b/docker-compose.yml index 278947b..95c9b0a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -135,6 +135,17 @@ services: networks: - bbb-net + periodic: + build: mod/periodic + restart: unless-stopped + depends_on: + - mongodb + volumes: + - /var/run/docker.sock:/var/run/docker.sock + - bigbluebutton:/var/bigbluebutton + networks: + - bbb-net + volumes: bigbluebutton: diff --git a/mod/periodic/Dockerfile b/mod/periodic/Dockerfile new file mode 100644 index 0000000..89f6e4e --- /dev/null +++ b/mod/periodic/Dockerfile @@ -0,0 +1,15 @@ +FROM debian:buster-slim + +# -- install mongo cli +RUN apt-get update \ + && apt-get install -y wget libcurl4 \ + && wget https://repo.mongodb.org/apt/debian/dists/buster/mongodb-org/4.2/main/binary-amd64/mongodb-org-shell_4.2.6_amd64.deb \ + && dpkg -i mongodb*.deb \ + && rm mongodb*.deb + +# -- install docker cli +COPY --from=library/docker:latest /usr/local/bin/docker /usr/bin/docker + +COPY bbb-restart-kms entrypoint.sh / + +ENTRYPOINT ["/entrypoint.sh"] \ No newline at end of file diff --git a/mod/periodic/bbb-restart-kms b/mod/periodic/bbb-restart-kms new file mode 100755 index 0000000..6b30b9f --- /dev/null +++ b/mod/periodic/bbb-restart-kms @@ -0,0 +1,40 @@ +#!/bin/bash + +# Source: +# https://github.com/alangecker/bbb-packages/blob/f83431c227be2c95025ea81083baeaa87667b170/bbb-webrtc-sfu/data/etc/cron.hourly/bbb-restart-kms + +# +# Restart Kurento every 24+ hours +# + +if [ ! -f /tmp/bbb-kms-last-restart.txt ]; then + date +%Y-%m-%d\ %H:%M:%S > /tmp/bbb-kms-last-restart.txt + exit +fi + +users=$(mongo --quiet mongodb://10.7.7.6:27017/meteor --eval "db.users.count({connectionStatus: 'online'})") +echo "currently active users: $users" + +if [ "$users" -eq 0 ]; then + + # Make sure 24 hours have passed since last restart + + # Seconds since epoch for last restart + dt1=$(cat /tmp/bbb-kms-last-restart.txt) + t1=`date --date="$dt1" +%s` + + # Current seconds since epoch + dt2=`date +%Y-%m-%d\ %H:%M:%S` + t2=`date --date="$dt2" +%s` + + # Hours since last restart + let "tDiff=$t2-$t1" + let "hDiff=$tDiff/3600" + + if [ "$hDiff" -ge 24 ]; then + echo "scheduled restart of kurento after 24h" + CONTAINER_ID=$(docker ps | grep kurento | awk '{print $1}') + docker restart $CONTAINER_ID + date +%Y-%m-%d\ %H:%M:%S > /tmp/bbb-kms-last-restart.txt + fi +fi diff --git a/mod/periodic/entrypoint.sh b/mod/periodic/entrypoint.sh new file mode 100755 index 0000000..820368e --- /dev/null +++ b/mod/periodic/entrypoint.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +# +# How N days back to keep files +# +history=5 + +while : +do + # restart kurento after 24h + /bbb-restart-kms + + # delete presentations older than N days + find /var/bigbluebutton/ -maxdepth 1 -type d -name "*-*" -mtime +$history -exec rm -rf '{}' + + + sleep 10s +done \ No newline at end of file