From d15727fa45c8982fa994501c3876743307e74382 Mon Sep 17 00:00:00 2001 From: peng9808 Date: Fri, 26 Apr 2024 10:14:48 +0800 Subject: [PATCH] fix drbd.conf's empty content problem --- docker-drbd9/config-drbd.sh | 20 +++++++++++++++----- docker-drbd9/entry.sh | 6 ++++++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/docker-drbd9/config-drbd.sh b/docker-drbd9/config-drbd.sh index 64139fb..3e812cc 100755 --- a/docker-drbd9/config-drbd.sh +++ b/docker-drbd9/config-drbd.sh @@ -3,11 +3,21 @@ conf_file="/etc/drbd.conf" example_file="/usr/share/doc/drbd.../drbd.conf.example" content_to_append="include \"/etc/drbd.d/global_common.conf\";\ninclude \"/etc/drbd.d/*.res\";" -echo -e "# You can find an example in $example_file\n$content_to_append" > "$conf_file" -echo "Content successfully written to $conf_file." +if [ ! -s "$conf_file" ]; then + echo -e "# You can find an example in $example_file\n$content_to_append" > "$conf_file" + echo "Content successfully written to $conf_file." +else + echo "$conf_file exists and is not empty." +fi + conf_file2="/etc/drbd.d/global_common.conf" content_to_write2="global { usage-count no; }" -mkdir -p "$(dirname "$conf_file2")" -echo "$content_to_write2" > "$conf_file2" -echo "Content successfully written to $conf_file2." + +if [ ! -s "$conf_file2" ]; then + mkdir -p "$(dirname "$conf_file2")" + echo "$content_to_write2" > "$conf_file2" + echo "Content successfully written to $conf_file2." +else + echo "$conf_file2 exists and is not empty." +fi diff --git a/docker-drbd9/entry.sh b/docker-drbd9/entry.sh index 5355fa1..6489d6c 100644 --- a/docker-drbd9/entry.sh +++ b/docker-drbd9/entry.sh @@ -267,6 +267,9 @@ if [ -n "$drbd_rpm" ]; then if [ $exit_code -eq 0 ]; then #Notify shipper that installation is complete export DRBD_RMP_INSTALL='yes' + cp /config-drbd.sh /pkgs_root/config-drbd.sh + nsenter --target 1 --mount --uts --ipc --net --pid chmod +x /root/config-drbd.sh + nsenter --target 1 --mount --uts --ipc --net --pid /root/config-drbd.sh exit 0 else debug "modprobe err_code: $exit_code" @@ -296,6 +299,9 @@ else exit_code=$? if [ $exit_code -eq 0 ]; then export DRBD_RMP_INSTALL='yes' + cp /config-drbd.sh /pkgs_root/config-drbd.sh + nsenter --target 1 --mount --uts --ipc --net --pid chmod +x /root/config-drbd.sh + nsenter --target 1 --mount --uts --ipc --net --pid /root/config-drbd.sh exit 0 else debug "modprobe err_code: $exit_code"