test/bin/start

180 lines
6.1 KiB
Bash
Executable File

#!/bin/bash
#
# Federated Start Script
. /federated/lib/functions.sh
. /etc/federated
usage() {
printf -v SERVICES_JOINED '%s|' "${SERVICES[@]}"
echo "$0: ${SERVICES_JOINED%|}"
exit 2
}
startservice_jitsi() {
if [ "$JITSI_SCALE" = "server" ]; then
JITSI_IP="192.168.0.28 8080"
else
JITSI_IP="192.168.0.25 443"
fi
if [ -z "$ALERTS_EMAIL" ]; then
AE=no
S=jitsi
else
AE=yes
S="$SERVICE"
fi
spin &
SPINPID=$!
NC_COMMAND=`grep "$JITSI_IP" /federated/lib/$SERVICE.sh | awk -F\" '{ print $4 }'`
RETRY=`grep "$JITSI_IP" /federated/lib/jitsi.sh | awk -F\" '{ print $6 }'`
start_service_withalert "$S" "$NC_COMMAND" "$RETRY" "$AE"
disown $SPINPID &> /dev/null
kill -9 $SPINPID &> /dev/null
# Allow multiple JVBs to connect
if [ "$JITSI_SCALE" = "client" -o "$JITSI_SCALE" = "both" ]; then
for i in $(seq 1 10); do
docker exec -ti jitsi-prosody-1 prosodyctl --config /config/prosody.cfg.lua register jvb$i auth.jitsiscale.federated.computer J17515cAl3-jvb
done
fi
echo -ne "done."
}
startservice() {
echo -ne "* Starting $SERVICE.."
local ALERT
if [ -z "$ALERTS_EMAIL" ]; then
ALERT="yes"
else
ALERT="no"
fi
spin &
SPINPID=$!
if [ "$SERVICE" = "traefik" ] && [ "$PLUS" ]; then
docker compose -f /federated/apps/traefik/docker-compose.yml -p traefik up -d &> /dev/null
else
NC_COMMAND=`grep start_service /federated/lib/$SERVICE.sh | awk -F\" '{ print $4 }'`
RETRY=`grep start_service /federated/lib/$SERVICE.sh | awk -F\" '{ print $6 }'`
eval start_service_withalert "$SERVICE" "$NC_COMMAND" "$RETRY" "$ALERT"
fi
disown $SPINPID &> /dev/null
kill -9 $SPINPID &> /dev/null
echo "done."
}
startservice_all() {
for SERVICE in "${SERVICES[@]}"; do
# If app isn't installed then skip
[ ! -d "/federated/apps/$SERVICE" ] && continue
FAILED="no"
if [ "$SERVICE" = "jitsi" ]; then
if [ "$(docker container inspect -f '{{.State.Status}}' jitsi-web-1 2>/dev/null)" = "running" ]; then
echo -ne "* $SERVICE is already running.\n"
else
startservice_jitsi
fi
else
if [ "$(docker container inspect -f '{{.State.Status}}' $SERVICE 2>/dev/null)" = "running" ]; then
echo -ne "* $SERVICE is already running.\n"
else
if [ -z "$ALERTS_EMAIL" ]; then
spin &
SPINPID=$!
NC_COMMAND=`grep start_service /federated/lib/$SERVICE.sh | awk -F\" '{ print $4 }'`
RETRY=`grep start_service /federated/lib/$SERVICE.sh | awk -F\" '{ print $6 }'`
start_service_withalert "$SERVICE" "$NC_COMMAND" "$RETRY" "no"
disown $SPINPID &> /dev/null
kill -9 $SPINPID &> /dev/null
echo -ne "done.\n"
else
spin &
SPINPID=$!
NC_COMMAND=`grep start_service /federated/lib/$SERVICE.sh | awk -F\" '{ print $4 }'`
RETRY=`grep start_service /federated/lib/$SERVICE.sh | awk -F\" '{ print $6 }'`
start_service_withalert "$SERVICE" "$NC_COMMAND" "$RETRY" "yes"
disown $SPINPID &> /dev/null
kill -9 $SPINPID &> /dev/null
echo -ne "done.\n"
fi
fi
fi
done
}
startservice_coreapp() {
echo "* Starting $1."
if [ "$1" = "traefik" ] && [ "$PLUS" ]; then
docker compose -f /federated/apps/traefik/docker-compose.yml -p traefik up -d &> /dev/null
else
NC_COMMAND=`grep start_service /federated/lib/$1.sh | awk -F\" '{ print $4 }'`
RETRY=`grep start_service /federated/lib/$1.sh | awk -F\" '{ print $6 }'`
eval start_service_withalert2 "$1" "$NC_COMMAND" "$RETRY" "no"
fi
}
startservice_all_new() {
echo "* Starting $1."
if [ "$i" = "jitsi" ]; then
if [ "$JITSI_SCALE" = "server" ]; then
JITSI_IP="192.168.0.28 8080"
NC_COMMAND=`grep "$JITSI_IP" /federated/lib/$1.sh | awk -F\" '{ print $4 }'`
RETRY=`grep "$JITSI_IP" /federated/lib/$1.sh | awk -F\" '{ print $6 }'`
eval start_service_withalert2 "$1" "$NC_COMMAND" "$RETRY" "no"
else
JITSI_IP="192.168.0.25 443"
NC_COMMAND=`grep "$JITSI_IP" /federated/lib/$1.sh | awk -F\" '{ print $4 }'`
RETRY=`grep "$JITSI_IP" /federated/lib/$1.sh | awk -F\" '{ print $6 }'`
eval start_service_withalert2 "$1" "$NC_COMMAND" "$RETRY" "no"
fi
else
NC_COMMAND=`grep start_service /federated/lib/$1.sh | awk -F\" '{ print $4 }'`
RETRY=`grep start_service /federated/lib/$1.sh | awk -F\" '{ print $6 }'`
eval start_service_withalert2 "$1" "$NC_COMMAND" "$RETRY" "no"
fi
}
[ $# != 1 ] && usage
SERVICE=$1
if [ "$SERVICE" = "jitsi" ]; then
[ ! -d "/federated/apps/jitsi" ] && failts "* jitsi is not installed."
# If jitsi is already running then skip
[ "$(docker container inspect -f '{{.State.Status}}' jitsi-web-1 2>/dev/null)" = "running" ] && echo "* $SERVICE is already running." && exit 2
startservice_jitsi
elif [ "$SERVICE" = "all" ]; then
# Starting all apps
# First start the CORE_APPS one by one
for i in "${CORE_APPS[@]}"; do
[ ! -d "/federated/apps/$i" ] && continue
[ "$(docker container inspect -f '{{.State.Status}}' $i 2>/dev/null)" = "running" ] && echo "* $i is already started." && continue
startservice_coreapp "$i"
done
# Next start EXTRA_APPS in parallel
for i in "${EXTRA_APPS[@]}"; do
[ ! -d "/federated/apps/$i" ] && continue
[ "$(docker container inspect -f '{{.State.Status}}' $i 2>/dev/null)" = "running" ] && echo "* $i is already started." && continue
[ "$i" = "jitsi" ] && [ "$(docker container inspect -f '{{.State.Status}}' jitsi-web-1 2>/dev/null)" = "running" ] && echo "* $i is already started." && continue
startservice_all_new "$i" &
done
wait
exit 0
elif printf '%s\0' "${SERVICES[@]}" | grep -Fxqz -- "$SERVICE"; then
[ ! -d "/federated/apps/$SERVICE" ] && echo "* $SERVICE is not installed." && exit 2
# If app is already running then skip
[ "$(docker container inspect -f '{{.State.Status}}' $SERVICE 2>/dev/null)" = "running" ] && echo "* $SERVICE is already running." && exit 2
startservice
else
usage
fi