cloudflare/cloudflared · error

cloudflared service is already installed at %s; if you are r

Error message

cloudflared service is already installed at %s; if you are running a cloudflared tunnel, you can point it to multiple origins, avoiding the need to run more than one cloudflared service in the same machine; otherwise if you are really sure, you can do `cloudflared service uninstall` to clean up the existing service and then try again this command

What it means

service_template.Generate renders the platform service definition (launchd plist, systemd unit, etc.) for `cloudflared service install`. Before writing, it stats the resolved destination path; if a file already exists there it refuses to overwrite and returns this descriptive error, protecting an existing cloudflared service from being clobbered.

Source

Thrown at cmd/cloudflared/service_template.go:45

func (st *ServiceTemplate) ResolvePath() (string, error) {
	resolvedPath, err := homedir.Expand(st.Path)
	if err != nil {
		return "", fmt.Errorf("error resolving path %s: %v", st.Path, err)
	}
	return resolvedPath, nil
}

func (st *ServiceTemplate) Generate(args *ServiceTemplateArgs) error {
	tmpl, err := template.New(st.Path).Parse(st.Content)
	if err != nil {
		return fmt.Errorf("error generating %s template: %v", st.Path, err)
	}
	resolvedPath, err := st.ResolvePath()
	if err != nil {
		return err
	}
	if _, err = os.Stat(resolvedPath); err == nil {
		return errors.New(serviceAlreadyExistsWarn(resolvedPath))
	}

	var buffer bytes.Buffer
	err = tmpl.Execute(&buffer, args)
	if err != nil {
		return fmt.Errorf("error generating %s: %v", st.Path, err)
	}
	fileMode := os.FileMode(0o644)
	if st.FileMode != 0 {
		fileMode = st.FileMode
	}

	plistFolder := filepath.Dir(resolvedPath)
	err = os.MkdirAll(plistFolder, 0o755)
	if err != nil {
		return fmt.Errorf("error creating %s: %v", plistFolder, err)
	}

View on GitHub (pinned to 2253eeeb25)

Solutions

  1. Run `sudo cloudflared service uninstall` first, then `cloudflared service install` again.
  2. If the file is stale and no service exists, remove it manually (e.g. `sudo rm /Library/LaunchDaemons/com.cloudflare.cloudflared.plist`).
  3. Serve multiple origins with one cloudflared service (multiple ingress rules) instead of installing multiple services on the same machine.

Example fix

# before
sudo cloudflared service install <token>   # fails: already installed
# after
sudo cloudflared service uninstall
sudo cloudflared service install <token>
Defensive patterns

Strategy: fallback

Validate before calling

const svcPath = "/Library/LaunchDaemons/com.cloudflare.cloudflared.plist"
if _, err := os.Stat(svcPath); err == nil {
    fmt.Println("service file exists; run `sudo cloudflared service uninstall` first")
    os.Exit(1)
}

Try / catch

if err := service.Generate(...); err != nil {
    if strings.Contains(err.Error(), "already installed") {
        // run uninstall then retry once
        if uerr := uninstallService(); uerr == nil {
            return service.Generate(...)
        }
    }
    return err
}

Prevention

When it happens

Trigger: Running `cloudflared service install` (via installLaunchd on macOS or equivalent) when a service file already exists at /Library/LaunchD/com.cloudflare.cloudflared.plist (or the platform equivalent), typically from a previously installed cloudflared service.

Common situations: Reinstalling after upgrading without uninstalling; multiple tunnel configs on one machine each attempting service install; stale service file left behind by an incomplete uninstall.

Understand the failure class

Background: "already exists" / EEXIST / FileAlreadyExistsException: what the 'file already exists' error means and how to fix it — this error's family across 37 libraries.

Related errors


AI-assisted analysis of cloudflare/cloudflared@2253eeeb25 (2026-09-06). Data as JSON: /api/errors/ef7c54a833109dcf. Report an issue: GitHub.