Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

nikolasrieble
Copy link
Contributor

@nikolasrieble nikolasrieble commented Apr 3, 2024

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

🔁

@nikolasrieble nikolasrieble requested a review from a team as a code owner April 3, 2024 12:35
@hashicorp-cla
Copy link

hashicorp-cla commented Apr 3, 2024

CLA assistant check
All committers have signed the CLA.

Copy link

@miguelhrocha miguelhrocha left a 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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if findmnt -rno SOURCE,TARGET $device | grep -q $disk_path; then
if findmnt -rno SOURCE,TARGET $device | grep -q "$disk_path"; then

Copy link
Contributor Author

@nikolasrieble nikolasrieble Apr 4, 2024

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.

Copy link
Contributor Author

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".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants