Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Propagate Medusa process exit code in k8s docker-entrypoint #806

Merged
merged 1 commit into from
Sep 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions k8s/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ set -e
echo "MEDUSA_MODE = $MEDUSA_MODE"

restore() {
# The BACKUP_NAME and RESTORE_KEY env vars have to be set in order for a
# The BACKUP_NAME and RESTORE_KEY env vars have to be set in order for a
# restore to be performed. BACKUP_NAME specifies the backup to restore.
# RESTORE_KEY is written out to a file after the restore completes. We
# compare the value in the file to RESTORE_KEY. We perform a restore if the
# the file does not exist or if the values differ.

echo "Running Medusa in restore mode"
last_restore_file=/var/lib/cassandra/.last-restore

Expand All @@ -38,7 +38,7 @@ restore() {
fi

if [ "$restore_key" == "$RESTORE_KEY" ]; then
echo "Skipping restore operation"
echo "Skipping restore operation"
else
echo "Restoring backup $BACKUP_NAME"
poetry run python -m medusa.service.grpc.restore -- "/etc/medusa/medusa.ini" $RESTORE_KEY
Expand All @@ -53,20 +53,25 @@ grpc() {
exec poetry run python -m medusa.service.grpc.server server.py &
MEDUSA_PID=$!

while true; do
# Loop while Medusa process is running
while kill -0 "$MEDUSA_PID" 2>/dev/null; do
CURRENT_DIGEST=$(md5sum /etc/medusa/medusa.ini | awk '{print $1}')
if [ "$ORIGINAL_MEDUSA_INI_DIGEST" != "$CURRENT_DIGEST" ]; then
echo "Detected change in medusa.ini, checking for running backups"
if ! [ -f /tmp/medusa_backup_in_progress ]; then
echo "No backups in progress, stopping Medusa"
kill $MEDUSA_PID
break
# Always exit with 0 on config change.
exit 0
else
echo "Backup in progress, postponing restart restart"
echo "Backup in progress, postponing restart"
fi
fi
sleep 5
done

# Exit with the Medusa process exit code.
wait "$MEDUSA_PID"
}

echo "sleeping for $DEBUG_SLEEP sec"
Expand Down
Loading