Added threaded stop script

This commit is contained in:
root 2024-04-03 14:58:00 +00:00
parent 3f6a0a54b2
commit f2e621cb48

View File

@ -9,10 +9,18 @@ usage() {
exit 2 exit 2
} }
stopservice() { stopservice() {
echo "* Stopping $SERVICE.." echo -ne "* Stopping $1.."
cd /federated/apps/$SERVICE && docker-compose -f docker-compose.yml -p $SERVICE down spin &
SPINPID=$!
cd /federated/apps/$1 && docker-compose -f docker-compose.yml -p $1 down &> /dev/null
[ $? -ne 0 ] && echo -ne "\nThere was a problem stopping service /federated/apps/$1\nCheck the output of 'docker logs $1' while stopping or run\ndocker-compose -f /federated/apps/$1/docker-compose.yml -p $1 down\n\n"
disown $SPINPID &> /dev/null
kill -9 $SPINPID &> /dev/null
echo "done."
} }
stopservice_all() { stopservice_all_old() {
for i in "${SERVICES[@]}"; do for i in "${SERVICES[@]}"; do
# If app isn't installed then skip # If app isn't installed then skip
[ ! -d "/federated/apps/$i" ] && echo "* $i not installed, skipping." && continue [ ! -d "/federated/apps/$i" ] && echo "* $i not installed, skipping." && continue
@ -21,14 +29,43 @@ stopservice_all() {
cd /federated/apps/$i && docker-compose -f docker-compose.yml -p $i down cd /federated/apps/$i && docker-compose -f docker-compose.yml -p $i down
done done
} }
stopservice_all() {
echo "* Stopping $i."
cd /federated/apps/$1 && docker-compose -f docker-compose.yml -p $1 down &> /dev/null
[ $? -ne 0 ] && echo -ne "\nThere was a problem stopping service /federated/apps/$1\nCheck the output of 'docker logs $1' while stopping or run\ndocker-compose -f /federated/apps/$1/docker-compose.yml -p $1 down\n\n"
}
#get_installedapps [[ $# -ne 1 ]] && usage
[ $# != 1 ] && usage
SERVICE=$1 SERVICE=$1
[ "$SERVICE" = "all" ] && stopservice_all if [ "$SERVICE" = "all" ]; then
for i in "${SERVICES[@]}"; do
# If app isn't installed then skip
[ ! -d "/federated/apps/$i" ] && echo "* $i not installed, skipping." && continue
# If app is already stopped then skip
[ ! "$(docker ps -f "name=$i" -f "status=running" -q)" ] && echo "* $i is already stopped." && continue
# If app is jitsi then check status of jitsi_web_1 since jitsi is named different
[ "$i" = "jitsi" ] && [ ! "$(docker ps -f "name=jitsi_web_1" -f "status=running" -q)" ] && echo "* $i is already stopped." && continue
# Run thread in stopservice_all function
stopservice_all "$i" &
done
wait
exit 0
fi
if printf '%s\0' "${SERVICES[@]}" | grep -Fxqz -- "$SERVICE"; then if printf '%s\0' "${SERVICES[@]}" | grep -Fxqz -- "$SERVICE"; then
stopservice # If app is already stopped then skip
[ ! "$(docker ps -f "name=$SERVICE" -f "status=running" -q)" ] && echo "* $SERVICE is already stopped." && exit 2
# If app is jitsi then check status of jitsi_web_1 since jitsi is named different
[ "$SERVICE" = "jitsi" ] && [ ! "$(docker ps -f "name=jitsi_web_1" -f "status=running" -q)" ] && echo "* $SERVICE is already stopped." && exit 2
# Stop service
stopservice "$SERVICE"
else else
usage usage
fi fi