mkunit validate

Validate unit files for common issues and mistakes.

mkunit validate <name|path> [flags]

Description

The validate command checks unit files for common issues including syntax errors, missing executables, relative paths, and configuration problems. It uses systemd-analyze verify under the hood plus additional checks.

Arguments

Argument Description
<name|path> Unit name or path to unit file

Flags

Flag Description Default
--system Validate as a system unit false
--strict Treat warnings as errors false
--json Output results as JSON false

Validation Checks

mkunit validate checks for the following issues:

Errors (will fail validation)

Warnings

Examples

Validate an installed unit

mkunit validate myapp

Example output:

Validating myapp.service...
✓ Syntax OK
✓ ExecStart path exists
⚠ Warning: No security hardening options enabled
⚠ Warning: Consider adding ProtectSystem=strict

1 error, 2 warnings

Validate a unit file before installing

mkunit validate ./myapp.service

Strict mode (fail on warnings)

mkunit validate myapp --strict

JSON output for CI/CD

mkunit validate myapp --json

Example JSON output:

{
  "unit": "myapp.service",
  "valid": true,
  "errors": [],
  "warnings": [
    {
      "code": "W001",
      "message": "No security hardening options enabled",
      "line": null,
      "suggestion": "Add --hardening flag or manually add security directives"
    }
  ]
}

Validate in CI pipeline

# In your CI script
mkunit service myapp --exec "./server" --dry-run > myapp.service
mkunit validate ./myapp.service --strict
if [ $? -ne 0 ]; then
  echo "Unit validation failed"
  exit 1
fi
Exit Codes

0 = Valid (may have warnings)
1 = Errors found
2 = Warnings found (with --strict)

See Also