Added start script with alerts
This commit is contained in:
parent
49a08fa097
commit
4c106eb011
2
bin/.env
2
bin/.env
@ -23,4 +23,4 @@ B2_APPLICATION_KEY_ID="3239c6765fdc"
|
|||||||
B2_APPLICATION_KEY="0050ac8837466cbca0e0aa574b5f8332f706a5e26c"
|
B2_APPLICATION_KEY="0050ac8837466cbca0e0aa574b5f8332f706a5e26c"
|
||||||
|
|
||||||
# Email address for alerts on services that fail to start
|
# Email address for alerts on services that fail to start
|
||||||
ALERTS_EMAIL="derek@federated.computer"
|
ALERTS_EMAIL="alerts@federated.computer"
|
||||||
|
94
bin/start
94
bin/start
@ -1,66 +1,124 @@
|
|||||||
#!/bin/bash -x
|
#!/bin/bash
|
||||||
#
|
#
|
||||||
# Federated Start Script
|
# Federated Start Script
|
||||||
. /federated/lib/functions.sh
|
. /federated/lib/functions.sh
|
||||||
|
. /federated/bin/.env
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
printf -v SERVICES_JOINED '%s|' "${SERVICES[@]}"
|
printf -v SERVICES_JOINED '%s|' "${SERVICES[@]}"
|
||||||
echo "$0: ${SERVICES_JOINED%|}"
|
echo "$0: ${SERVICES_JOINED%|}"
|
||||||
exit 2
|
exit 2
|
||||||
}
|
}
|
||||||
startservice() {
|
startservice_jitsi() {
|
||||||
. /federated/bin/.env
|
if [ "$(docker container inspect -f '{{.State.Status}}' jitsi_web_1 2>/dev/null)" = "running" ]; then
|
||||||
echo -ne "* Starting $SERVICE.."
|
echo -ne "* $SERVICE is already running.\n"
|
||||||
|
|
||||||
if [ "$(docker container inspect -f '{{.State.Status}}' $SERVICE 2>/dev/null)" = "running" ]; then
|
|
||||||
echo -ne "is already running.\n"
|
|
||||||
else
|
else
|
||||||
if [ -z "$ALERTS_EMAIL" ]; then
|
if [ -z "$ALERTS_EMAIL" ]; then
|
||||||
cd /federated/apps/$SERVICE && docker-compose -f docker-compose.yml -p $SERVICE up -d &> /dev/null
|
spin &
|
||||||
|
SPINPID=$!
|
||||||
|
|
||||||
|
NC_COMMAND=`grep start_service /federated/lib/$SERVICE.sh | awk -F\" '{ print $4 }'`
|
||||||
|
RETRY=`grep start_service /federated/lib/jitsi.sh | awk -F\" '{ print $6 }'`
|
||||||
|
start_service_withalert "jitsi" "$NC_COMMAND" "$RETRY" "no"
|
||||||
|
|
||||||
|
if [ "$FAILED" = "no" ]; then
|
||||||
|
disown $SPINPID &> /dev/null
|
||||||
|
kill -9 $SPINPID &> /dev/null
|
||||||
echo -ne "done.\n"
|
echo -ne "done.\n"
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
spin &
|
spin &
|
||||||
SPINPID=$!
|
SPINPID=$!
|
||||||
|
|
||||||
NC_COMMAND=`grep start_service /federated/lib/$SERVICE.sh | awk -F\" '{ print $4 }'`
|
NC_COMMAND=`grep start_service /federated/lib/$SERVICE.sh | awk -F\" '{ print $4 }'`
|
||||||
RETRY=`grep start_service /federated/lib/caddy.sh | awk -F\" '{ print $6 }'`
|
RETRY=`grep start_service /federated/lib/jitsi.sh | awk -F\" '{ print $6 }'`
|
||||||
start_service_withalert "$SERVICE" "$NC_COMMAND" "$RETRY"
|
start_service_withalert "$SERVICE" "$NC_COMMAND" "$RETRY" "yes"
|
||||||
|
|
||||||
|
if [ "$FAILED" = "no" ]; then
|
||||||
|
disown $SPINPID &> /dev/null
|
||||||
|
kill -9 $SPINPID &> /dev/null
|
||||||
|
echo -ne "done.\n"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
startservice() {
|
||||||
|
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
|
||||||
|
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."
|
||||||
|
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
|
kill -9 $SPINPID &> /dev/null
|
||||||
echo -ne "done.\n"
|
echo -ne "done.\n"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
startservice_all() {
|
startservice_all() {
|
||||||
. /federated/bin/.env
|
|
||||||
for SERVICE in "${SERVICES[@]}"; do
|
for SERVICE in "${SERVICES[@]}"; do
|
||||||
echo -ne "* Starting $SERVICE.."
|
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
|
if [ "$(docker container inspect -f '{{.State.Status}}' $SERVICE 2>/dev/null)" = "running" ]; then
|
||||||
echo -ne "is already running.\n"
|
echo -ne "* $SERVICE is already running.\n"
|
||||||
else
|
else
|
||||||
if [ -z "$ALERTS_EMAIL" ]; then
|
if [ -z "$ALERTS_EMAIL" ]; then
|
||||||
cd /federated/apps/$SERVICE && docker-compose -f docker-compose.yml -p $SERVICE up -d &> /dev/null
|
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"
|
echo -ne "done.\n"
|
||||||
else
|
else
|
||||||
spin &
|
spin &
|
||||||
SPINPID=$!
|
SPINPID=$!
|
||||||
|
|
||||||
NC_COMMAND=`grep start_service /federated/lib/$SERVICE.sh | awk -F\" '{ print $4 }'`
|
NC_COMMAND=`grep start_service /federated/lib/$SERVICE.sh | awk -F\" '{ print $4 }'`
|
||||||
RETRY=`grep start_service /federated/lib/caddy.sh | awk -F\" '{ print $6 }'`
|
RETRY=`grep start_service /federated/lib/$SERVICE.sh | awk -F\" '{ print $6 }'`
|
||||||
start_service_withalert "$SERVICE" "$NC_COMMAND" "$RETRY"
|
start_service_withalert "$SERVICE" "$NC_COMMAND" "$RETRY" "yes"
|
||||||
|
|
||||||
|
if [ "$FAILED" = "no" ]; then
|
||||||
|
disown $SPINPID &> /dev/null
|
||||||
kill -9 $SPINPID &> /dev/null
|
kill -9 $SPINPID &> /dev/null
|
||||||
echo -ne "done.\n"
|
echo -ne "done.\n"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
[ $# != 1 ] && usage
|
[ $# != 1 ] && usage
|
||||||
SERVICE=$1
|
SERVICE=$1
|
||||||
|
|
||||||
[ "$SERVICE" = "all" ] && startservice_all
|
if [ "$SERVICE" = "jitsi" ]; then
|
||||||
if printf '%s\0' "${SERVICES[@]}" | grep -Fxqz -- "$SERVICE"; then
|
startservice_jitsi
|
||||||
|
elif [ "$SERVICE" = "all" ]; then
|
||||||
|
startservice_all
|
||||||
|
elif printf '%s\0' "${SERVICES[@]}" | grep -Fxqz -- "$SERVICE"; then
|
||||||
startservice
|
startservice
|
||||||
else
|
else
|
||||||
usage
|
usage
|
||||||
|
@ -161,6 +161,9 @@ start_service_withalert() {
|
|||||||
SERVICE="$1"
|
SERVICE="$1"
|
||||||
COMMAND="$2"
|
COMMAND="$2"
|
||||||
RETRY="$3"
|
RETRY="$3"
|
||||||
|
ALERT="$4"
|
||||||
|
|
||||||
|
echo -ne "* Starting $SERVICE.."
|
||||||
|
|
||||||
docker-compose -f /federated/apps/$SERVICE/docker-compose.yml -p $SERVICE up -d &> /dev/null
|
docker-compose -f /federated/apps/$SERVICE/docker-compose.yml -p $SERVICE up -d &> /dev/null
|
||||||
|
|
||||||
@ -172,11 +175,20 @@ start_service_withalert() {
|
|||||||
break
|
break
|
||||||
else
|
else
|
||||||
if [ "$RETRY" == 1 ]; then
|
if [ "$RETRY" == 1 ]; then
|
||||||
|
disown $SPINPID &> /dev/null
|
||||||
|
kill -9 $SPINPID &> /dev/null
|
||||||
|
FAILED="yes"
|
||||||
|
|
||||||
|
if [ "$ALERT" = "yes" ]; then
|
||||||
EXTERNALIP=`dig @resolver4.opendns.com myip.opendns.com +short 2> /dev/null`
|
EXTERNALIP=`dig @resolver4.opendns.com myip.opendns.com +short 2> /dev/null`
|
||||||
docker-compose -f /federated/apps/$SERVICE/docker-compose.yml -p $SERVICE down &> /dev/null
|
docker-compose -f /federated/apps/$SERVICE/docker-compose.yml -p $SERVICE down &> /dev/null
|
||||||
echo "Generated by /federated/bin/start" > /federated/apps/mail/data/root/certs/mailfile
|
echo "Generated by /federated/bin/start" > /federated/apps/mail/data/root/certs/mailfile
|
||||||
docker exec mail bash -c "mail -r admin@$DOMAIN -a \"Content-type: text/html\" -s \"$SERVICE failed to start on $EXTERNALIP\" $ALERTS_EMAIL < /root/certs/mailfile"
|
docker exec mail bash -c "mail -r admin@$DOMAIN -a \"Content-type: text/html\" -s \"$SERVICE failed to start on $EXTERNALIP\" $ALERTS_EMAIL < /root/certs/mailfile"
|
||||||
fail "There was a problem starting service /federated/apps/$SERVICE\nCheck the output of 'docker logs $SERVICE' or turn on\ndebug with -d"
|
echo -ne "\n\nThere was a problem starting service /federated/apps/$SERVICE\nCheck the output of 'docker logs $SERVICE' or turn on\ndebug with set -x\n\n"
|
||||||
|
else
|
||||||
|
docker-compose -f /federated/apps/$SERVICE/docker-compose.yml -p $SERVICE down &> /dev/null
|
||||||
|
echo -ne "\n\nThere was a problem starting service /federated/apps/$SERVICE\nCheck the output of 'docker logs $SERVICE' or turn on\ndebug with set -x\n\n"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
((RETRY--))
|
((RETRY--))
|
||||||
sleep 7
|
sleep 7
|
||||||
@ -210,7 +222,7 @@ start_service() {
|
|||||||
RETRY="$3"
|
RETRY="$3"
|
||||||
|
|
||||||
# Start /federated/apps/SERVICE with output to /dev/null
|
# Start /federated/apps/SERVICE with output to /dev/null
|
||||||
echo -ne "\n* Starting /federated/apps/$SERVICE service.."
|
echo -ne "* Starting $SERVICE.."
|
||||||
spin &
|
spin &
|
||||||
SPINPID=$!
|
SPINPID=$!
|
||||||
|
|
||||||
@ -231,7 +243,7 @@ start_service() {
|
|||||||
if [ "$RETRY" == 1 ]; then
|
if [ "$RETRY" == 1 ]; then
|
||||||
docker-compose -f /federated/apps/$SERVICE/docker-compose.yml -p $SERVICE down &> /dev/null
|
docker-compose -f /federated/apps/$SERVICE/docker-compose.yml -p $SERVICE down &> /dev/null
|
||||||
kill -9 $SPINPID &> /dev/null
|
kill -9 $SPINPID &> /dev/null
|
||||||
fail "There was a problem starting service /federated/apps/$SERVICE\nCheck the output of 'docker logs $SERVICE' or turn on\ndebug with -d"
|
fail "There was a problem starting service /federated/apps/$SERVICE\nCheck the output of 'docker logs $SERVICE' or turn on\ndebug with set -x"
|
||||||
fi
|
fi
|
||||||
((RETRY--))
|
((RETRY--))
|
||||||
sleep 7
|
sleep 7
|
||||||
|
@ -5,7 +5,7 @@ traefik=v2.10.1
|
|||||||
caddy=latest
|
caddy=latest
|
||||||
baserow=1.18.0
|
baserow=1.18.0
|
||||||
collabora=22.05.13.1.1
|
collabora=22.05.13.1.1
|
||||||
element=v1.11.33
|
element=v1.11.34
|
||||||
postgresql=14
|
postgresql=14
|
||||||
jitsi=stable-8615
|
jitsi=stable-8615
|
||||||
nextcloud=27.0
|
nextcloud=27.0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user