hashicorp/nomad · error

service name too long

Error message

service name too long

What it means

ScanServiceName in command/agent/monitor/export_monitor.go validates a systemd service name for log export. systemd limits unit names to 255 characters; if the combined input length exceeds 255, the check fails with this error before any further prefix/suffix validation. It enforces systemd's naming convention so the generated unit name will be usable by journald.

Source

Thrown at command/agent/monitor/export_monitor.go:128

	sw := ExportMonitor{
		logger:       hclog.Default().Named("export"),
		doneCh:       make(chan struct{}, 1),
		logCh:        make(chan []byte, bufSize),
		bufSize:      bufSize,
		ExportReader: exportReader,
	}

	return &sw, nil
}

// ScanServiceName checks that the length, prefix and suffix conform to
// systemd conventions and ensures the service name includes the word 'nomad'
func ScanServiceName(input string) error {
	prefix := ""
	// invalid if prefix and suffix together are > 255 char
	if len(input) > 255 {
		return errors.New("service name too long")
	}

	if isNomad := strings.Contains(input, "nomad"); !isNomad {
		return errors.New(`service name must include 'nomad`)
	}

	// if there is a suffix, check against list of valid suffixes
	// and set prefix to exclude suffix index, else set prefix
	splitInput := strings.Split(input, ".")
	if len(splitInput) < 2 {
		prefix = input
	} else {
		suffix := splitInput[len(splitInput)-1]
		validSuffix := []string{
			"service",
			"socket",
			"device",
			"mount",

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. Shorten the service name to <= 255 characters, truncating the middle segment (job/task portion) while keeping the 'nomad' token and suffix.
  2. Check where the name is generated (nomad logmon/export template) and add length limiting there.
  3. Strip redundant prefixes/namespace decorations from the configured service name.
  4. Log/print the computed name length in config validation to catch this before issuing the monitor request.

Example fix

// before
name := "nomad-" + jobID + "-" + taskGroup + "-" + allocID + ".service" // 300 chars
// after
if len(name) > 255 {
    name = name[:252] + ".service"
}
Defensive patterns

Strategy: validation

Validate before calling

if len(serviceName) > 255 {
    serviceName = serviceName[:252] + ".service" // truncate before calling
}

Try / catch

if err := monitor.ScanServiceName(name); err != nil {
    if strings.Contains(err.Error(), "too long") {
        return fmt.Errorf("truncate unit name (len=%d > 255): %s", len(name), name)
    }
    return err
}

Prevention

When it happens

Trigger: Calling ScanServiceName (via AgentMonitorExport or cliReader) with a service/unit name string longer than 255 bytes — e.g. a generated name composed of a long job/task/allocation id chain.

Common situations: Deeply nested or templated job names producing very long systemd unit names; concatenating namespace/job/task IDs without truncation; users pasting fully-qualified names with long prefixes into monitoring config.

Related errors


AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04). Data as JSON: /api/errors/3230e79979a7d337. Report an issue: GitHub.