{"record":{"id":"0864394a0144ca05","repo":"cloudflare/cloudflared","slug":"error-generating-openrc-service-template-w","errorCode":null,"errorMessage":"error generating OpenRC service template: %w","messagePattern":"error generating OpenRC service template: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/cloudflared/linux_service.go","lineNumber":430,"sourceCode":"\t\tif err := os.Symlink(confPath, \"/etc/rc\"+i+\".d/K02et\"); err != nil {\n\t\t\tcontinue\n\t\t}\n\t}\n\treturn runCommand(\"service\", \"cloudflared\", \"start\")\n}\n\nfunc installOpenRC(templateArgs *ServiceTemplateArgs, autoUpdate bool) error {\n\tif autoUpdate {\n\t\ttemplateArgs.ExtraArgs = append([]string{\"--autoupdate-freq\", \"24h0m0s\"}, templateArgs.ExtraArgs...)\n\t} else {\n\t\ttemplateArgs.ExtraArgs = append([]string{\"--no-autoupdate\"}, templateArgs.ExtraArgs...)\n\t}\n\n\tif err := openrcConfTemplate.Generate(templateArgs); err != nil {\n\t\treturn fmt.Errorf(\"error generating OpenRC conf.d template: %w\", err)\n\t}\n\tif err := openrcTemplate.Generate(templateArgs); err != nil {\n\t\treturn fmt.Errorf(\"error generating OpenRC service template: %w\", err)\n\t}\n\n\tif err := runCommand(\"rc-update\", \"add\", cloudflaredOpenRCService, \"default\"); err != nil {\n\t\treturn fmt.Errorf(\"rc-update add %s default: %w\", cloudflaredOpenRCService, err)\n\t}\n\tif err := runCommand(\"rc-service\", cloudflaredOpenRCService, \"start\"); err != nil {\n\t\treturn fmt.Errorf(\"rc-service %s start: %w\", cloudflaredOpenRCService, err)\n\t}\n\treturn nil\n}\n\nfunc uninstallLinuxService(c *cli.Context) error {\n\tlog := logger.CreateLoggerFromContext(c, logger.EnableTerminalLog)\n\n\tvar err error\n\tswitch {\n\tcase inits.IsSystemd():\n\t\tlog.Info().Msg(\"Using Systemd\")","sourceCodeStart":412,"sourceCodeEnd":448,"githubUrl":"https://github.com/cloudflare/cloudflared/blob/2253eeeb25a44a713a4b60b8ba1e1b3f377d1a0f/cmd/cloudflared/linux_service.go#L412-L448","documentation":"Returned by installOpenRC when rendering the OpenRC service (init.d) template fails after the conf.d template succeeded. cloudflared generates /etc/init.d/cloudflared from a Go template; failure here leaves the service unregistered and installation aborts before rc-update add runs.","triggerScenarios":"`cloudflared service install` on an OpenRC-based system where openrcTemplate.Generate(templateArgs) fails — unwritable /etc/init.d, existing non-regular file at the target path, filesystem error, or invalid template arguments (cloudflaredBinaryPath/ExtraArgs).","commonSituations":"Installing without root on Gentoo/Alpine; /etc/init.d/cloudflared exists as a directory or is immutable; read-only root filesystem (containers, live systems); disk full while writing the init script.","solutions":["Run the install as root: `sudo cloudflared service install`.","Ensure /etc/init.d exists and is writable; remove or fix any non-file at /etc/init.d/cloudflared.","Confirm the root filesystem is writable (mount checks in containers/chroots).","Inspect the wrapped cause (%w) for the exact underlying error and address it.","After a successful install, register manually if needed: rc-update add cloudflared default && rc-service cloudflared start."],"exampleFix":"# before\n$ cloudflared service install\n# ERROR: error generating OpenRC service template: mkdir /etc/init.d: read-only file system\n\n# after\n$ sudo mount -o remount,rw /\n$ sudo cloudflared service install","handlingStrategy":"try-catch","validationCode":"// Shell preflight before OpenRC install\n[ \"$(id -u)\" -eq 0 ] || { echo \"need root\"; exit 1; }\n[ ! -d /etc/init.d/cloudflared ] || { echo \"/etc/init.d/cloudflared is a directory\"; exit 1; }\ntouch /etc/init.d/.wtest 2>/dev/null && rm /etc/init.d/.wtest || { echo \"/etc/init.d not writable\"; exit 1; }","typeGuard":null,"tryCatchPattern":"// Go\nout, err := exec.Command(\"cloudflared\", \"service\", \"install\").CombinedOutput()\nif err != nil && strings.Contains(string(out), \"error generating OpenRC service template\") {\n    return fmt.Errorf(\"OpenRC init.d template generation failed; check /etc/init.d permissions: %s\", out)\n}","preventionTips":["Run service installs on Gentoo/Alpine as root","Ensure /etc/init.d exists, is writable, and /etc/init.d/cloudflared is not a directory or immutable file","Confirm the root filesystem is mounted rw (common pitfall in containers/chroots)","Monitor disk space on minimal systems before installing services"],"tags":["cli","openrc","service-install","template","linux"],"backgroundTag":"file-write-failed","analyzedSha":"2253eeeb25a44a713a4b60b8ba1e1b3f377d1a0f","analyzedAt":"2026-09-06T04:14:33.757Z","contentChangedAt":"2026-09-06T04:14:33.757Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}