fix: back up existing systemd unit before overwriting on update (#24350) (#24937)

When `openclaw update` regenerates the systemd service file, any user
customizations to ExecStart (e.g. proxychains4 wrapper) are silently
lost. Now the existing unit file is copied to `.bak` before writing
the new one, so users can restore their customizations.

The backup path is printed in the install output so users are aware.

Co-authored-by: echoVic <AkiraVic@outlook.com>
This commit is contained in:
青雲
2026-02-24 11:22:55 +08:00
committed by GitHub
parent 70cfb69a5f
commit dc8423f2c0

View File

@@ -193,6 +193,18 @@ export async function installSystemdService({
const unitPath = resolveSystemdUnitPath(env);
await fs.mkdir(path.dirname(unitPath), { recursive: true });
// Preserve user customizations: back up existing unit file before overwriting.
let backedUp = false;
try {
await fs.access(unitPath);
const backupPath = `${unitPath}.bak`;
await fs.copyFile(unitPath, backupPath);
backedUp = true;
} catch {
// File does not exist yet — nothing to back up.
}
const serviceDescription = resolveGatewayServiceDescription({ env, environment, description });
const unit = buildSystemdUnit({
description: serviceDescription,
@@ -227,6 +239,14 @@ export async function installSystemdService({
label: "Installed systemd service",
value: unitPath,
},
...(backedUp
? [
{
label: "Previous unit backed up to",
value: `${unitPath}.bak`,
},
]
: []),
],
{ leadingBlankLine: true },
);