ReviewOS

also looking at this

stacks/ts-cloud

test(fleet): prove the database and hostname halves of a transfer on real machines

#184
Merged glennmichael123 wants to merge test/move-database-and-rename-e2e into main
4 files +363 -3
packages/ts-cloud/src/operations/server-rename.tsmodified+9-2
Changes to packages/ts-cloud/src/operations/server-rename.ts
@@ -177,8 +177,15 @@ export function buildSetHostnameScript(next: string): string {
177177 `hostnamectl set-hostname ${quoted} 2>/dev/null || { echo ${quoted} > /etc/hostname && hostname ${quoted}; }`,
178178 // Replace the old name where it stands rather than appending: a second
179179 // 127.0.1.1 line would leave the box resolving its own name two ways.
180 `if grep -q "127.0.1.1" /etc/hosts; then`,
181 ` sed -i "s/^127\\.0\\.1\\.1.*/127.0.1.1\\t${next}/" /etc/hosts`,
180 //
181 // Rewritten through a variable and truncating redirect rather than `sed -i`,
182 // which renames a temp file over the target and so fails outright when
183 // /etc/hosts is a bind mount (every container), is hard-linked, or lives on
184 // a filesystem the rename cannot cross. Writing in place keeps the inode and
185 // works in all of those.
186 `if grep -q "^127.0.1.1" /etc/hosts; then`,
187 ` TS_CLOUD_HOSTS="$(sed -E "s/^127\\.0\\.1\\.1.*/127.0.1.1\\t${next}/" /etc/hosts)"`,
188 ` printf '%s\\n' "$TS_CLOUD_HOSTS" > /etc/hosts`,
182189 'else',
183190 ` printf '127.0.1.1\\t%s\\n' ${quoted} >> /etc/hosts`,
184191 'fi',