-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Idempotent Init: Only mount if not mounted yet #145
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With my limited UNIX knowledge, this looks good to 🚢 I understand that the existing behavior is not changed, just adding some guardrails for it.
@@ -89,8 +89,16 @@ else | |||
fi | |||
echo "[Terraform Enterprise] Creating mounted disk directory at '${disk_path}'" | tee -a $log_pathname | |||
mkdir --parents ${disk_path} | |||
echo "[Terraform Enterprise] Mounting disk '$device' to directory at '${disk_path}'" | tee -a $log_pathname | |||
mount --options discard,defaults $device ${disk_path} | |||
if findmnt -rno SOURCE,TARGET $device | grep -q $disk_path; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if findmnt -rno SOURCE,TARGET $device | grep -q $disk_path; then | |
if findmnt -rno SOURCE,TARGET $device | grep -q "$disk_path"; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be an issue otherwise, if the disk_path contained spaces.
TODO: Test again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fun.
During testing on Ubuntu 22.04.4 LTS
, I mounted /path/to/your mount point
onto /dev/vda1
.
device="/dev/vda1"
disk_path="/path/to/your mount point"
mount "$device" "$disk_path"
Which works, as we see:
findmnt -rno SOURCE,TARGET "$device"
...
/dev/vda1 /path/to/your\x20mount\x20point
In the output of findmnt, whitespaces are replaced with \x20.
In this case, we will find no match with | grep -q "$disk_path"
.
Background
While I tested the migration guide for Podman, and wanted to rollback, the startup script would not run through.
During the Rollback steps, the startup script fails with
mount: /opt/hashicorp/data: /dev/sdb already mounted on /opt/hashicorp/data.
The solution to this is to unmount first with
umount /dev/sdb
and then rerun the script.To prevent future engineers from this manual step, I suggest to adapt the initialization script to make it idempotent with respect to the mount.
To make the script fully idempotent there might be more changes needed, but lets tackle this one step at a time.
How has this been tested?
I tested this adaption when I rolled back the podman installation to replicated.
This PR makes me feel
🔁