diff --git a/registry/coder/modules/filebrowser/run.sh b/registry/coder/modules/filebrowser/run.sh index 183c64a77..ae1e121d1 100644 --- a/registry/coder/modules/filebrowser/run.sh +++ b/registry/coder/modules/filebrowser/run.sh @@ -22,13 +22,44 @@ echo "DB_PATH: ${DB_PATH}" export FB_DATABASE="${DB_PATH}" -# Check if filebrowser db exists +if PID="$(pgrep -x filebrowser)"; then + echo "File Browser is already running (PID: $${PID})" + + # Show which database the running process is using. + RUNNING_DB="$(tr '\0' '\n' < /proc/$${PID}/environ | grep '^FB_DATABASE=' | cut -d= -f2- || true)" + + echo "Running database: $${RUNNING_DB}" + + if [[ "$${RUNNING_DB}" == "${DB_PATH}" ]]; then + echo "Existing File Browser already uses ${DB_PATH}." + echo "Skipping configuration and startup." + + exit 0 + fi + + echo "A File Browser process is already running but is using another database." + echo "Continuing..." +fi + if [[ ! -f "${DB_PATH}" ]]; then - filebrowser config init 2>&1 | tee -a ${LOG_PATH} - filebrowser users add admin "coderPASSWORD" --perm.admin=true --viewMode=mosaic 2>&1 | tee -a ${LOG_PATH} + echo "Initializing File Browser database..." + + filebrowser config init 2>&1 | tee -a "${LOG_PATH}" + + filebrowser users add \ + admin \ + "coderPASSWORD" \ + --perm.admin=true \ + --viewMode=mosaic \ + 2>&1 | tee -a "${LOG_PATH}" fi -filebrowser config set --baseURL=${SERVER_BASE_PATH} --port=${PORT} --auth.method=noauth --root=$ROOT_DIR 2>&1 | tee -a ${LOG_PATH} +filebrowser config set \ + --baseURL="${SERVER_BASE_PATH}" \ + --port="${PORT}" \ + --auth.method=noauth \ + --root="$${ROOT_DIR}" \ + 2>&1 | tee -a "${LOG_PATH}" printf "👷 Starting filebrowser in background... \n\n"