fix:权限调整
This commit is contained in:
@@ -40,25 +40,44 @@ json_text() {
|
||||
sed -nE 's/.*"'"${key}"'"[[:space:]]*:[[:space:]]*"([^"]*)".*/\1/p' "${CONTEXT_FILE}" | head -n 1
|
||||
}
|
||||
|
||||
split_command() {
|
||||
local value="$1"
|
||||
# shellcheck disable=SC2206
|
||||
CTL_COMMAND=(${value})
|
||||
}
|
||||
|
||||
find_ctl() {
|
||||
local configured="${RABBITMQ_CTL_COMMAND:-}"
|
||||
if [[ -n "${configured}" ]]; then
|
||||
printf '%s' "${configured}"
|
||||
split_command "${configured}"
|
||||
return 0
|
||||
fi
|
||||
if [[ -x "/usr/local/sbin/tms-rabbitmqctl" ]] && command -v sudo >/dev/null 2>&1; then
|
||||
CTL_COMMAND=(sudo -n /usr/local/sbin/tms-rabbitmqctl)
|
||||
return 0
|
||||
fi
|
||||
for candidate in rabbitmqctl /usr/local/rabbitmq/sbin/rabbitmqctl /usr/local/rabbitmq-server/sbin/rabbitmqctl /usr/sbin/rabbitmqctl /usr/lib/rabbitmq/bin/rabbitmqctl; do
|
||||
if command -v "${candidate}" >/dev/null 2>&1; then
|
||||
command -v "${candidate}"
|
||||
CTL_COMMAND=("$(command -v "${candidate}")")
|
||||
return 0
|
||||
fi
|
||||
if [[ -x "${candidate}" ]]; then
|
||||
printf '%s' "${candidate}"
|
||||
CTL_COMMAND=("${candidate}")
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
run_ctl() {
|
||||
local timeout_seconds="${RABBITMQ_CTL_TIMEOUT_SECONDS:-30}"
|
||||
if command -v timeout >/dev/null 2>&1; then
|
||||
timeout "${timeout_seconds}" "${CTL_COMMAND[@]}" "$@"
|
||||
else
|
||||
"${CTL_COMMAND[@]}" "$@"
|
||||
fi
|
||||
}
|
||||
|
||||
if [[ -n "${MQ_REPLAY_COMMAND:-}" ]]; then
|
||||
log "delegating mq replay to configured command"
|
||||
"${MQ_REPLAY_COMMAND}" --context-file "${CONTEXT_FILE}" --work-dir "${WORK_DIR}" >> "${LOG_FILE}" 2>&1
|
||||
@@ -85,15 +104,16 @@ if [[ -z "${USER_NAME}" || -z "${USER_PASS}" ]]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
CTL="$(find_ctl)" || {
|
||||
CTL_COMMAND=()
|
||||
find_ctl || {
|
||||
echo "[ERROR] rabbitmqctl not found" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
"${CTL}" status >> "${LOG_FILE}" 2>&1 || log "rabbitmqctl status failed, continue replay"
|
||||
"${CTL}" add_vhost "${VHOST}" >> "${LOG_FILE}" 2>&1 || true
|
||||
"${CTL}" add_user "${USER_NAME}" "${USER_PASS}" >> "${LOG_FILE}" 2>&1 || "${CTL}" change_password "${USER_NAME}" "${USER_PASS}" >> "${LOG_FILE}" 2>&1
|
||||
"${CTL}" set_permissions -p "${VHOST}" "${USER_NAME}" ".*" ".*" ".*" >> "${LOG_FILE}" 2>&1
|
||||
run_ctl status >> "${LOG_FILE}" 2>&1 || log "rabbitmqctl status failed, continue replay"
|
||||
run_ctl add_vhost "${VHOST}" >> "${LOG_FILE}" 2>&1 || true
|
||||
run_ctl add_user "${USER_NAME}" "${USER_PASS}" >> "${LOG_FILE}" 2>&1 || run_ctl change_password "${USER_NAME}" "${USER_PASS}" >> "${LOG_FILE}" 2>&1
|
||||
run_ctl set_permissions -p "${VHOST}" "${USER_NAME}" ".*" ".*" ".*" >> "${LOG_FILE}" 2>&1
|
||||
log "rabbitmq user and permissions replayed"
|
||||
|
||||
if [[ -n "${RABBIT_QUEUE_REPLAY_SCRIPT_PATH:-}" && -x "${RABBIT_QUEUE_REPLAY_SCRIPT_PATH}" ]]; then
|
||||
|
||||
@@ -60,5 +60,4 @@ fi
|
||||
--host="${HOST}" \
|
||||
--port="${PORT}" \
|
||||
--user="${USERNAME}" \
|
||||
--password="${PASSWORD}" \
|
||||
"${DB_NAME}" < "${SQL_FILE}"
|
||||
--password="${PASSWORD}" < "${SQL_FILE}"
|
||||
|
||||
Reference in New Issue
Block a user