Skip to content

Instantly share code, notes, and snippets.

@frispete
Last active December 16, 2023 20:51
Show Gist options
  • Save frispete/c99c5bd46aede1505b004494d2e4fe65 to your computer and use it in GitHub Desktop.
Save frispete/c99c5bd46aede1505b004494d2e4fe65 to your computer and use it in GitHub Desktop.
docker-jitsi-meet control script
#!/bin/bash
meetsh=$(basename "$0")
meetctl=$(basename "${0%%.sh}")
# jitsi components
jitsi=(-f docker-compose.yml)
jitsilst=$meetctl.lst
test -f $jitsilst && {
# read list of additional jitsi components
while read line; do
[[ "$line" =~ \#* ]] && jitsi+=(-f ${line%%.yml}.yml)
done < "$jitsilst"
}
test -f ./$meetctl.unstable && export JITSI_RELEASE=unstable
services=(web prosody jicofo jvb jigasi jibri etherpad)
logservice=
logfile=
usage() {
cat >&2 << EOM
docker-jetsi-meet controls
usage: $0 [-hv] start
$0 [-hv] stop
$0 [-hv] restart
$0 [-hv] up
$0 [-hv] ps
$0 [-hvl][-s service] log
$0 [-hv] clean
$0 [-hv][-f][-u] build
-h this message
-v verbose mode
-l write log to file
-f force rebuild
-u perform builds from unstable jitsi release
(also, if a file ./$meetctl.unstable exists)
build implicitly cleans, stops, builds and starts these dockers:
docker-compose ${jitsi[@]}
services are: ${services[@]}
list any *additional* docker-compose yaml file in $jitsilst (one file per line)
EOM
exit 1
}
function info {
echo "[INFO] $@" 1>&2
}
function error {
echo "[ERROR] $@" 1>&2
}
function timestamp {
date +'%Y%m%d-%H%M%S'
}
function fix_pubip {
test -f .env && {
# grab public URL, remove proto, fails with following comments
local pubname=$(sed -n 's,^PUBLIC_URL=.*://\(.*\)\s*$,\1,p' .env)
local pubip=$(dig +short "$pubname")
test -n "$pubip" && {
local curip=$(sed -n 's,^DOCKER_HOST_ADDRESS=\(.*\)\s*$,\1,p' .env)
test "$pubip" != "$curip" && {
info "update public IP address from $curip to $pubip in .env"
sed -i~ -e "s,^DOCKER_HOST_ADDRESS=.*$,DOCKER_HOST_ADDRESS=$pubip," .env
} || info "public IP address $curip is up-to-date in .env"
}
} || error '.env missing'
}
function start {
docker-compose "${jitsi[@]}" start
}
function stop {
docker-compose "${jitsi[@]}" stop
}
function up {
fix_pubip
docker-compose "${jitsi[@]}" up -d
}
function ps {
docker-compose "${jitsi[@]}" ps
}
function log {
args=(--no-color)
test -n "$logservice" && args+=($logservice)
test -n "$logfile" && {
test -n "$logservice" && logfile="$logservice" || logfile="$meetctl"
logfile=$logfile-$(timestamp).log
docker-compose "${jitsi[@]}" logs "${args[@]}" > $logfile
info "$logfile written"
} || {
docker-compose "${jitsi[@]}" logs "${args[@]}"
}
}
function clean {
# equivalent of make clean, but for all jitsi elements without further inquiry
# stop dockers
docker-compose "${jitsi[@]}" stop
# remove stopped containers and any anonymous volumes attached to containers
docker-compose "${jitsi[@]}" rm -vf
# remove unused networks
docker network prune -f
# remove any vim backups, because docker-compose doen't ignore them
find "${services[@]}" -name \*~ -exec rm -v {} \;
# recreate config
rm -r ~/.jitsi-meet-cfg
mkdir -p ~/.jitsi-meet-cfg/{letsencrypt,log,transcripts,prosody,jicofo,jvb,avatarcache}
}
function build {
time ( clean && make && up ) 2>&1 | tee build-$(timestamp).log
rcnginx restart
}
# main
OPTIND=1
while getopts "hvlfus:" opt; do
case "$opt" in
h) usage;;
v) set -o xtrace;;
l) logfile=1;;
s) logservice=$OPTARG;;
f) export FORCE_REBUILD=1;;
u) export JITSI_RELEASE=unstable;;
esac
done
shift $((OPTIND-1))
test "$1" = "--" && shift
test -z "$1" && usage
while test -n "$1"; do
case "$1" in
start) start;;
stop) stop;;
restart) stop && start;;
up) up;;
ps) ps;;
log) log;;
build) build;;
clean) clean;;
reconfig) clean && up;;
fix-pubip) fix_pubip;;
*) error "unknown command: $1"; exit 2;;
esac
shift
done
exit $?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment