mirror of
https://github.com/bitnami/containers.git
synced 2026-04-04 16:27:46 +08:00
Use sync instead of stdbuf (#43)
Signed-off-by: shaoyue.chen <shaoyue.chen@zilliz.com>
This commit is contained in:
committed by
Bitnami Containers
parent
4ec8e196a1
commit
18c0a0eb9d
@@ -19,7 +19,8 @@ if is_empty_value "${endpoints}"; then
|
||||
fi
|
||||
read -r -a extra_flags <<< "$(etcdctl_auth_flags)"
|
||||
extra_flags+=("--endpoints=${endpoints}" "--debug=true")
|
||||
# We use 'stdbuf' to ensure memory buffers are flushed to disk
|
||||
# We use 'sync' to ensure memory buffers are flushed to disk
|
||||
# so we reduce the chances that the "member_removal.log" file is empty.
|
||||
# ref: https://www.gnu.org/software/coreutils/manual/html_node/stdbuf-invocation.html#stdbuf-invocation
|
||||
stdbuf -oL etcdctl member remove "$(cat "${ETCD_DATA_DIR}/member_id")" "${extra_flags[@]}" > "$(dirname "$ETCD_DATA_DIR")/member_removal.log"
|
||||
# ref: https://man7.org/linux/man-pages/man1/sync.1.html
|
||||
etcdctl member remove "$(cat "${ETCD_DATA_DIR}/member_id")" "${extra_flags[@]}" > "$(dirname "$ETCD_DATA_DIR")/member_removal.log"
|
||||
sync -d "$(dirname "$ETCD_DATA_DIR")/member_removal.log"
|
||||
|
||||
@@ -306,19 +306,21 @@ etcdctl_auth_flags() {
|
||||
########################
|
||||
etcd_store_member_id() {
|
||||
local -a extra_flags
|
||||
|
||||
local member_id=""
|
||||
info "Obtaining cluster member ID"
|
||||
etcd_start_bg
|
||||
read -r -a extra_flags <<<"$(etcdctl_auth_flags)"
|
||||
is_boolean_yes "$ETCD_ON_K8S" && extra_flags+=("--endpoints=$(etcdctl_get_endpoints)")
|
||||
if retry_while "etcdctl ${extra_flags[*]} member list" >/dev/null 2>&1; then
|
||||
while [[ ! -s "${ETCD_DATA_DIR}/member_id" ]]; do
|
||||
# We use 'stdbuf' to ensure memory buffers are flushed to disk
|
||||
# so we reduce the chances that the "member_id" file is empty.
|
||||
# ref: https://www.gnu.org/software/coreutils/manual/html_node/stdbuf-invocation.html#stdbuf-invocation
|
||||
while is_empty_value "$member_id"; do
|
||||
read -r -a advertised_array <<<"$(tr ',;' ' ' <<<"$ETCD_ADVERTISE_CLIENT_URLS")"
|
||||
stdbuf -oL etcdctl "${extra_flags[@]}" member list | grep -w "${advertised_array[0]}" | awk -F "," '{ print $1}' >"${ETCD_DATA_DIR}/member_id" || true
|
||||
member_id="$(etcdctl "${extra_flags[@]}" member list | grep -w "${advertised_array[0]}" | awk -F "," '{ print $1}' || true)"
|
||||
done
|
||||
# We use 'sync' to ensure memory buffers are flushed to disk
|
||||
# so we reduce the chances that the "member_id" file is empty.
|
||||
# ref: https://man7.org/linux/man-pages/man1/sync.1.html
|
||||
echo "$member_id" > "${ETCD_DATA_DIR}/member_id"
|
||||
sync -d "${ETCD_DATA_DIR}/member_id"
|
||||
info "Stored member ID: $(cat "${ETCD_DATA_DIR}/member_id")"
|
||||
fi
|
||||
etcd_stop
|
||||
|
||||
@@ -19,7 +19,8 @@ if is_empty_value "${endpoints}"; then
|
||||
fi
|
||||
read -r -a extra_flags <<< "$(etcdctl_auth_flags)"
|
||||
extra_flags+=("--endpoints=${endpoints}" "--debug=true")
|
||||
# We use 'stdbuf' to ensure memory buffers are flushed to disk
|
||||
# We use 'sync' to ensure memory buffers are flushed to disk
|
||||
# so we reduce the chances that the "member_removal.log" file is empty.
|
||||
# ref: https://www.gnu.org/software/coreutils/manual/html_node/stdbuf-invocation.html#stdbuf-invocation
|
||||
stdbuf -oL etcdctl member remove "$(cat "${ETCD_DATA_DIR}/member_id")" "${extra_flags[@]}" > "$(dirname "$ETCD_DATA_DIR")/member_removal.log"
|
||||
# ref: https://man7.org/linux/man-pages/man1/sync.1.html
|
||||
etcdctl member remove "$(cat "${ETCD_DATA_DIR}/member_id")" "${extra_flags[@]}" > "$(dirname "$ETCD_DATA_DIR")/member_removal.log"
|
||||
sync -d "$(dirname "$ETCD_DATA_DIR")/member_removal.log"
|
||||
|
||||
@@ -306,19 +306,21 @@ etcdctl_auth_flags() {
|
||||
########################
|
||||
etcd_store_member_id() {
|
||||
local -a extra_flags
|
||||
|
||||
local member_id=""
|
||||
info "Obtaining cluster member ID"
|
||||
etcd_start_bg
|
||||
read -r -a extra_flags <<<"$(etcdctl_auth_flags)"
|
||||
is_boolean_yes "$ETCD_ON_K8S" && extra_flags+=("--endpoints=$(etcdctl_get_endpoints)")
|
||||
if retry_while "etcdctl ${extra_flags[*]} member list" >/dev/null 2>&1; then
|
||||
while [[ ! -s "${ETCD_DATA_DIR}/member_id" ]]; do
|
||||
# We use 'stdbuf' to ensure memory buffers are flushed to disk
|
||||
# so we reduce the chances that the "member_id" file is empty.
|
||||
# ref: https://www.gnu.org/software/coreutils/manual/html_node/stdbuf-invocation.html#stdbuf-invocation
|
||||
while is_empty_value "$member_id"; do
|
||||
read -r -a advertised_array <<<"$(tr ',;' ' ' <<<"$ETCD_ADVERTISE_CLIENT_URLS")"
|
||||
stdbuf -oL etcdctl "${extra_flags[@]}" member list | grep -w "${advertised_array[0]}" | awk -F "," '{ print $1}' >"${ETCD_DATA_DIR}/member_id" || true
|
||||
member_id="$(etcdctl "${extra_flags[@]}" member list | grep -w "${advertised_array[0]}" | awk -F "," '{ print $1}' || true)"
|
||||
done
|
||||
# We use 'sync' to ensure memory buffers are flushed to disk
|
||||
# so we reduce the chances that the "member_id" file is empty.
|
||||
# ref: https://man7.org/linux/man-pages/man1/sync.1.html
|
||||
echo "$member_id" > "${ETCD_DATA_DIR}/member_id"
|
||||
sync -d "${ETCD_DATA_DIR}/member_id"
|
||||
info "Stored member ID: $(cat "${ETCD_DATA_DIR}/member_id")"
|
||||
fi
|
||||
etcd_stop
|
||||
|
||||
@@ -19,7 +19,8 @@ if is_empty_value "${endpoints}"; then
|
||||
fi
|
||||
read -r -a extra_flags <<< "$(etcdctl_auth_flags)"
|
||||
extra_flags+=("--endpoints=${endpoints}" "--debug=true")
|
||||
# We use 'stdbuf' to ensure memory buffers are flushed to disk
|
||||
# We use 'sync' to ensure memory buffers are flushed to disk
|
||||
# so we reduce the chances that the "member_removal.log" file is empty.
|
||||
# ref: https://www.gnu.org/software/coreutils/manual/html_node/stdbuf-invocation.html#stdbuf-invocation
|
||||
stdbuf -oL etcdctl member remove "$(cat "${ETCD_DATA_DIR}/member_id")" "${extra_flags[@]}" > "$(dirname "$ETCD_DATA_DIR")/member_removal.log"
|
||||
# ref: https://man7.org/linux/man-pages/man1/sync.1.html
|
||||
etcdctl member remove "$(cat "${ETCD_DATA_DIR}/member_id")" "${extra_flags[@]}" > "$(dirname "$ETCD_DATA_DIR")/member_removal.log"
|
||||
sync -d "$(dirname "$ETCD_DATA_DIR")/member_removal.log"
|
||||
@@ -306,19 +306,21 @@ etcdctl_auth_flags() {
|
||||
########################
|
||||
etcd_store_member_id() {
|
||||
local -a extra_flags
|
||||
|
||||
local member_id=""
|
||||
info "Obtaining cluster member ID"
|
||||
etcd_start_bg
|
||||
read -r -a extra_flags <<<"$(etcdctl_auth_flags)"
|
||||
is_boolean_yes "$ETCD_ON_K8S" && extra_flags+=("--endpoints=$(etcdctl_get_endpoints)")
|
||||
if retry_while "etcdctl ${extra_flags[*]} member list" >/dev/null 2>&1; then
|
||||
while [[ ! -s "${ETCD_DATA_DIR}/member_id" ]]; do
|
||||
# We use 'stdbuf' to ensure memory buffers are flushed to disk
|
||||
# so we reduce the chances that the "member_id" file is empty.
|
||||
# ref: https://www.gnu.org/software/coreutils/manual/html_node/stdbuf-invocation.html#stdbuf-invocation
|
||||
while is_empty_value "$member_id"; do
|
||||
read -r -a advertised_array <<<"$(tr ',;' ' ' <<<"$ETCD_ADVERTISE_CLIENT_URLS")"
|
||||
stdbuf -oL etcdctl "${extra_flags[@]}" member list | grep -w "${advertised_array[0]}" | awk -F "," '{ print $1}' >"${ETCD_DATA_DIR}/member_id" || true
|
||||
member_id="$(etcdctl "${extra_flags[@]}" member list | grep -w "${advertised_array[0]}" | awk -F "," '{ print $1}' || true)"
|
||||
done
|
||||
# We use 'sync' to ensure memory buffers are flushed to disk
|
||||
# so we reduce the chances that the "member_id" file is empty.
|
||||
# ref: https://man7.org/linux/man-pages/man1/sync.1.html
|
||||
echo "$member_id" > "${ETCD_DATA_DIR}/member_id"
|
||||
sync -d "${ETCD_DATA_DIR}/member_id"
|
||||
info "Stored member ID: $(cat "${ETCD_DATA_DIR}/member_id")"
|
||||
fi
|
||||
etcd_stop
|
||||
|
||||
Reference in New Issue
Block a user