Skip to content

Commit

Permalink
To avoid sync issue on MAC OS - delete mutagen sessions with obsolete…
Browse files Browse the repository at this point in the history
… docker id (#254)

* To avoid sync issue - delete mutagen sessions with obsolete docker id

* Rename method to be more clear.

Co-authored-by: Aleksandr Myrnyi <oleksandr.myrnyi@spryker.com>

* More clear messages for a user.

Co-authored-by: Aleksandr Myrnyi <oleksandr.myrnyi@spryker.com>

* That was a bug, thanks to alexanderM91

Co-authored-by: Aleksandr Myrnyi <oleksandr.myrnyi@spryker.com>

Co-authored-by: Andrey Bobkov <andrey.bobkov@mediawave.de>
Co-authored-by: Aleksandr Myrnyi <oleksandr.myrnyi@spryker.com>
  • Loading branch information
3 people committed Nov 17, 2021
1 parent a27de0f commit d72ae2f
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions bin/sdk/mount/mutagen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ function Mount::Mutagen::beforeUp() {
# The volume will not be deleted if any app container is running.
docker volume rm "${SPRYKER_SYNC_VOLUME}" >/dev/null 2>&1 || true

terminateMutagenSessionsWithObsoleteDockerId

# Clean content of the sync volume if the sync session is terminated or halted.
sessionStatus=$(mutagen sync list "${SPRYKER_SYNC_SESSION_NAME}" 2>/dev/null | grep 'Status:' | awk '{print $2}' || echo '')
if [ -z "${sessionStatus}" ] || [ "${sessionStatus}" == 'Halted' ]; then
Expand All @@ -35,6 +37,38 @@ function Mount::Mutagen::beforeUp() {
fi
}

function terminateMutagenSessionsWithObsoleteDockerId() {
dockerId=$(docker info --format '{{.ID}}' 2>/dev/null | awk '{ gsub(":","_",$1); print $1 }' || echo '')

if [ -z "$dockerId" ]; then
Console::error "${WARN}Docker ID is empty, please check the script and try again."
return
fi

Console::log "Checking mutagen sessions for docker ID: ${dockerId}"

sessionIds=$(mutagen sync list "${SPRYKER_SYNC_SESSION_NAME}" 2>/dev/null | grep 'Identifier:' | awk '{print $2}' || echo '')

for sessionId in ${sessionIds}; do
if [ -z "$sessionId" ]; then
Console::warn "Session ID is empty, please check the script and try again."
continue
fi

sessionDockerId=$(mutagen sync list "${sessionId}" 2>/dev/null | grep 'io.mutagen.compose.daemon.identifier:' | awk '{print $2}' || echo '')

if [ -z "$sessionDockerId" ]; then
Console::warn "Docker ID for session ${sessionId} is empty, please check the script and try again."
continue
fi

if [ "$sessionDockerId" != "$dockerId" ]; then
mutagen sync terminate "${sessionId}"
Console::log "Mutagen session ${sessionId} has been terminated."
fi
done
}

# This is necessary due to https://github.com/mutagen-io/mutagen/issues/224
function Mount::Mutagen::beforeRun() {
Console::verbose::start "${INFO}Creating file syncronization volume${NC}"
Expand Down

0 comments on commit d72ae2f

Please sign in to comment.