Browse Source

fix: dev: moved state's temporary files for database communication in ``$state_tmpdir``

They were in ``/tmp`` and this was far from ideal (conflict between
concurrent version, or other process much more likely).
test
Valentin Lab 6 years ago
parent
commit
66b9c9e57c
  1. 16
      bin/compose-core

16
bin/compose-core

@ -439,7 +439,7 @@ _clean_docker() {
docker stop "$container_id"
docker rm "$_DB_NAME"
docker network rm "${_DB_NAME}"
rm -vf "/tmp/${_DB_NAME}.state"
rm -vf "$state_tmpdir/${_DB_NAME}.state"
)
}
export -f _clean_docker
@ -507,7 +507,7 @@ ensure_db_docker_running () {
local _STATE_FILE
_DB_NAME="db_${DB_NAME}_${_PID}"
_STATE_FILE=/tmp/${_DB_NAME}.state
_STATE_FILE="$state_tmpdir/${_DB_NAME}.state"
if [ -e "$_STATE_FILE" ]; then
IFS=: read DOCKER_NETWORK DOCKER_IP <<<"$(cat "$_STATE_FILE")"
@ -517,7 +517,7 @@ ensure_db_docker_running () {
return 0
fi
if [ -e "/tmp/${_DB_NAME}.working" ]; then
if [ -e "$state_tmpdir/${_DB_NAME}.working" ]; then
## avoid recursive calls.
if [ -z "$DOCKER_IP" ]; then
err "Currently figuring up DOCKER_IP, please set it yourself before this call if needed."
@ -528,7 +528,7 @@ ensure_db_docker_running () {
return 0
fi
touch "/tmp/${_DB_NAME}.working"
touch "$state_tmpdir/${_DB_NAME}.working"
docker rm "$_DB_NAME" 2>/dev/null || true
@ -568,7 +568,7 @@ ensure_db_docker_running () {
if ! network_id=$(docker network create "$_DB_NAME"); then
err "'docker network create' failed !"
_clean_docker "$_DB_NAME" "$container_id"
rm "/tmp/${_DB_NAME}.working"
rm "$state_tmpdir/${_DB_NAME}.working"
return 1
fi
debug docker run -d \
@ -587,7 +587,7 @@ ensure_db_docker_running () {
); then
err "'docker run' failed !"
_clean_docker "$_DB_NAME" "$container_id"
rm "/tmp/${_DB_NAME}.working"
rm "$state_tmpdir/${_DB_NAME}.working"
return 1
fi
trap_add EXIT,ERR "_clean_docker \"$_DB_NAME\" \"$container_id\""
@ -597,14 +597,14 @@ ensure_db_docker_running () {
IFS=: read DOCKER_NETWORK DOCKER_IP <<<"$docker_ip"
echo "$docker_ip" > "$_STATE_FILE"
debug "written '$_STATE_FILE'"
rm "/tmp/${_DB_NAME}.working"
rm "$state_tmpdir/${_DB_NAME}.working"
_set_db_params "$DOCKER_IP" "$DOCKER_NETWORK"
return 0
else
errlvl="$?"
err "Db not found (errlvl: $errlvl). Tail of docker logs follows:"
docker logs --tail=5 "$container_id" 2>&1 | prefix " | " >&2
rm "/tmp/${_DB_NAME}.working"
rm "$state_tmpdir/${_DB_NAME}.working"
return "$errlvl"
fi
}

Loading…
Cancel
Save