{"record":{"id":"ada52f08a3b7d656","repo":"kubernetes/kops","slug":"error-writing-systemd-service-file-v","errorCode":null,"errorMessage":"error writing systemd service file: %v","messagePattern":"error writing systemd service file: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upup/pkg/fi/nodeup/nodetasks/service.go","lineNumber":328,"sourceCode":"\t}\n\n\tserviceName := e.Name\n\n\taction := \"\"\n\n\tif changes.Running != nil && fi.ValueOf(e.ManageState) {\n\t\tif fi.ValueOf(e.Running) {\n\t\t\taction = \"restart\"\n\t\t} else {\n\t\t\taction = \"stop\"\n\t\t}\n\t}\n\n\tif changes.Definition != nil {\n\t\tservicePath := path.Join(systemdSystemPath, serviceName)\n\t\terr := fi.WriteFile(servicePath, fi.NewStringResource(*e.Definition), 0o644, 0o755, \"\", \"\")\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"error writing systemd service file: %v\", err)\n\t\t}\n\n\t\tklog.Infof(\"Reloading systemd configuration\")\n\t\tcmd := exec.Command(\"systemctl\", \"daemon-reload\")\n\t\toutput, err := cmd.CombinedOutput()\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"error doing systemd daemon-reload: %v\\nOutput: %s\", err, output)\n\t\t}\n\t}\n\n\t// \"SmartRestart\" - look at the obvious dependencies in the systemd service, restart if start time older\n\tif fi.ValueOf(e.ManageState) && fi.ValueOf(e.SmartRestart) {\n\t\tdefinition := fi.ValueOf(e.Definition)\n\t\tif definition == \"\" && a != nil {\n\t\t\tdefinition = fi.ValueOf(a.Definition)\n\t\t}\n\n\t\tif action == \"\" && fi.ValueOf(e.Running) && definition != \"\" {","sourceCodeStart":310,"sourceCodeEnd":346,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/upup/pkg/fi/nodeup/nodetasks/service.go#L310-L346","documentation":"When a service definition changes, RenderLocal writes the new unit file with fi.WriteFile and then reloads systemd. If writing the unit file fails, the change cannot be applied and this error is returned, aborting the task so systemd never sees a half-applied definition.","triggerScenarios":"fi.WriteFile(servicePath, ...) fails: /etc/systemd/system (or distro-specific dir) is read-only or full, the unit path is a directory, or the parent dir has wrong permissions for the nodeup user.","commonSituations":"Node disk full (no space left on device), immutable unit file (chattr +i left from hardening), read-only /usr on some images, or COS/Flatcar layouts where the target dir differs from expectations.","solutions":["Check disk space (df -h) and free space on the node","Check for immutable flags: lsattr <unit-file>; chattr -i if set","Verify the systemd unit directory is writable by the nodeup user (usually root)","If the path is a directory, remove it and re-run nodeup","Reboot or remount the node's filesystem if it is read-only due to disk errors"],"exampleFix":"# before\n$ df -h /etc\n/dev/root  100%  ...  # disk full\n# after: free space (e.g. clean logs), then re-run nodeup\n$ journalctl --vacuum-size=50M","handlingStrategy":"validation","validationCode":"// Before nodeup, on the node:\ndf -h /etc && sudo test -w /etc/systemd/system && echo writable || echo 'not writable'\nlsattr /etc/systemd/system/<unit> 2>/dev/null | grep -q i && echo 'immutable!' || true","typeGuard":null,"tryCatchPattern":"if err := task.RenderLocal(target, a, e, changes); err != nil {\n\tif strings.Contains(err.Error(), \"error writing systemd service file\") {\n\t\treturn fmt.Errorf(\"check disk space, immutable flags, and /etc/systemd/system perms: %w\", err)\n\t}\n\treturn err\n}","preventionTips":["Keep free disk space headroom on nodes","Never chattr +i files nodeup manages","Ensure /etc/systemd/system is writable by the nodeup user","Use supported base images with standard layouts"],"tags":["nodeup","systemd","filesystem","disk-full"],"backgroundTag":"unit-file-write-failed","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T07:17:12.445Z"}