{"record":{"id":"7e72f11efaa95c39","repo":"cloudflare/cloudflared","slug":"error-resolving-openrc-template-path-w","errorCode":null,"errorMessage":"error resolving OpenRC template path: %w","messagePattern":"error resolving OpenRC template path: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/cloudflared/linux_service.go","lineNumber":545,"sourceCode":"\tfor _, i := range [...]string{\"0\", \"1\", \"6\"} {\n\t\tif err := os.Remove(\"/etc/rc\" + i + \".d/K02et\"); err != nil {\n\t\t\tcontinue\n\t\t}\n\t}\n\treturn nil\n}\n\nfunc uninstallOpenRC(log *zerolog.Logger) error {\n\tif err := runCommand(\"rc-service\", cloudflaredOpenRCService, \"stop\"); err != nil {\n\t\tlog.Warn().Err(err).Msg(\"could not stop cloudflared OpenRC service, continuing uninstall\")\n\t}\n\tif err := runCommand(\"rc-update\", \"del\", cloudflaredOpenRCService, \"default\"); err != nil {\n\t\tlog.Warn().Err(err).Msg(\"could not remove cloudflared from the default runlevel, continuing uninstall\")\n\t}\n\tfor _, template := range []ServiceTemplate{openrcTemplate, openrcConfTemplate} {\n\t\tpath, err := template.ResolvePath()\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"error resolving OpenRC template path: %w\", err)\n\t\t}\n\t\tif err := os.Remove(path); err != nil && !errors.Is(err, os.ErrNotExist) {\n\t\t\treturn fmt.Errorf(\"error removing %s: %w\", path, err)\n\t\t}\n\t}\n\treturn nil\n}\n\nfunc copyFile(src, dest string) error {\n\tsrcFile, err := os.Open(src) //nolint:gosec // operator-provided service config path\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer func() { _ = srcFile.Close() }()\n\n\tdestFile, err := os.Create(dest) //nolint:gosec // operator-provided service config path\n\tif err != nil {\n\t\treturn err","sourceCodeStart":527,"sourceCodeEnd":563,"githubUrl":"https://github.com/cloudflare/cloudflared/blob/2253eeeb25a44a713a4b60b8ba1e1b3f377d1a0f/cmd/cloudflared/linux_service.go#L527-L563","documentation":"uninstallOpenRC calls ServiceTemplate.ResolvePath() (homedir.Expand) on both the OpenRC init script template and its conf template before deleting them, and aborts with this error if path resolution fails. Unlike the rc-update removal above it, a resolution failure is treated as fatal because the uninstall cannot know which file to remove.","triggerScenarios":"During `cloudflared service uninstall` on an OpenRC system, when homedir.Expand fails on the openrcTemplate or openrcConfTemplate path — i.e. the path contains an unresolvable '~' because HOME is unset/invalid or the invoking user has no passwd entry.","commonSituations":"Uninstalling from an environment with no HOME variable (cron, container, CI job); running under a UID missing from /etc/passwd; restricted sandbox where user lookups fail (CGO-disabled builds with unusual NSS).","solutions":["Run with a valid HOME: `sudo HOME=/root cloudflared service uninstall`","Verify the environment: `echo $HOME` must point to an existing directory and the user must resolve in passwd","Workaround: delete the files manually — `sudo rm /etc/init.d/cloudflared /etc/conf.d/cloudflared` then `sudo rc-update del cloudflared default`","Inspect the wrapped error to see which template path failed and why"],"exampleFix":"// before\n$ cloudflared service uninstall  # HOME unset in container\n// error: error resolving OpenRC template path: error resolving path /etc/init.d/cloudflared: ...\n// after\n$ sudo HOME=/root cloudflared service uninstall","handlingStrategy":"validation","validationCode":"// guard before OpenRC uninstall\nfunc ensureOpenRCUninstallEnv() error {\n    if os.Getenv(\"HOME\") == \"\" {\n        return errors.New(\"HOME unset; run with: sudo HOME=/root cloudflared service uninstall\")\n    }\n    if _, err := exec.LookPath(\"rc-update\"); err != nil {\n        return errors.New(\"rc-update not found: not an OpenRC system\")\n    }\n    return nil\n}","typeGuard":"func openrcPathsResolvable() bool {\n    for _, p := range []string{\"/etc/init.d/cloudflared\", \"/etc/conf.d/cloudflared\"} {\n        if _, err := os.Stat(p); err != nil && !os.IsNotExist(err) {\n            return false\n        }\n    }\n    return true\n}","tryCatchPattern":null,"preventionTips":["Export a valid HOME before invoking service uninstall in non-interactive shells","Run as root via `sudo -H` so user/home lookup succeeds","When scripting uninstall, tolerate this error and fall back to manually removing /etc/init.d/cloudflared and /etc/conf.d/cloudflared","Verify the target files exist before uninstalling to keep the operation idempotent"],"tags":["linux","openrc","uninstall","path-resolution"],"backgroundTag":"file-not-found","analyzedSha":"2253eeeb25a44a713a4b60b8ba1e1b3f377d1a0f","analyzedAt":"2026-09-06T04:14:33.757Z","contentChangedAt":"2026-09-06T04:14:33.757Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}