librelad 988297e8de compose: fall back to docker-compose.yml when the app's config is out of scope
dockerComposeUp and dockerComposeDown derive compose_file from $compose_setup,
which setupBasicScanVariables reads from CFG_<APP>_COMPOSE_FILE — a variable
that is only set once the app's config has been sourced, and is not always. A
restore wipes and re-creates the app folder around those calls.

setupBasicScanVariables already handles that, falling back to the standard file.
Neither compose function did: with compose_setup empty, neither branch ran,
compose_file stayed UNSET, and the guard

    [ ! -f "$(appDir "$app")/$compose_file" ]

then tested the app DIRECTORY, which is never a regular file. So the app was
reported as having no compose file and quietly not started.

Found restoring an app on a clean install: the restore ran to completion and
reported success, having neither stopped nor started the app —

    ---- 3. Shutting down container(s) for restoration
    ! Notice Unable to find the compose file to docker compose down this application.
    ---- 10. Starting up the linkding docker service(s)
    ! Notice Unable to find the compose file to docker compose up this application.

— while docker-compose.yml sat in the app directory the whole time. Verified:
with CFG_LINKDING_COMPOSE_FILE unset, dockerComposeUp now starts the app.

scripts/dev/lp-compose-file-test covers the empty case, the normal one, and a
genuinely missing file so the guard still fires when it should.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-28 08:21:11 +01:00

64 lines
2.6 KiB
Bash
Executable File

#!/bin/bash
dockerComposeDown()
{
local app_name="$1"
local custom_compose="$2"
local type="$3"
if [[ "$app_name" == "" ]]; then
isError "Something went wrong...No app name provided..."
fi
isHeader "Docker Compose down $app_name"
# Make sure we are able to get the compose file
if [[ $compose_setup == "" ]]; then
setupBasicScanVariables "$app_name"
fi
# Compose file public variable for restarting etc
if [[ $compose_setup == "default" ]]; then
local setup_compose="-f docker-compose.yml"
local compose_file="docker-compose.yml"
elif [[ $compose_setup == "app" ]]; then
local setup_compose="-f docker-compose.yml -f docker-compose.$app_name.yml"
local compose_file="docker-compose.$app_name.yml"
else
# setupBasicScanVariables falls back to the standard file when
# CFG_<APP>_COMPOSE_FILE is not in scope; without the same fallback here
# compose_file stays UNSET, and the existence check below then tests the
# app DIRECTORY — which is never a regular file. The app is reported as
# having no compose file and is quietly not brought down.
local setup_compose="-f docker-compose.yml"
local compose_file="docker-compose.yml"
fi
if [[ $custom_compose != "" ]]; then
local setup_compose="-f docker-compose.yml -f $custom_compose"
local compose_file="$custom_compose"
fi
if [[ "$OS_TYPE" == "Ubuntu" || "$OS_TYPE" == "Debian" ]]; then
if [ ! -f "$(appDir "$app_name")/$compose_file" ]; then
isNotice "Unable to find the compose file to docker compose down this application."
return 1
fi
# Explicit type arg (CLI dockertype switcher) wins, otherwise the
# configured install type. Every branch ends in a status line so the
# header is never left without output.
local mode="${type:-$CFG_DOCKER_INSTALL_TYPE}"
if [[ $mode == "rootless" ]]; then
local result; result=$(dockerCommandRunInstallUser "cd $(appDir "$app_name") && docker compose $setup_compose down" >/dev/null 2>&1)
checkSuccess "Shutting down container for $app_name"
elif [[ $mode == "rooted" ]]; then
local result; result=$(cd "$(appDir "$app_name")" && docker compose $setup_compose down >/dev/null 2>&1)
checkSuccess "Shutting down container for $app_name"
else
isNotice "Unknown Docker install type '$mode' — cannot shut down $app_name."
fi
else
isNotice "Unsupported OS '$OS_TYPE' — cannot shut down $app_name."
fi
}