Add template support for generated unit files #2

Open
opened 2026-04-03 13:57:12 +00:00 by sgcommand · 1 comment
Member

Allow users to provide their own .service file template to override the built-in one.

Use cases

  • Add custom [Unit] dependencies (Requires=, After=docker.service, etc.)
  • Set environment variables (Environment=, EnvironmentFile=)
  • Change restart policy, timeouts, resource limits
  • Add ExecStartPre / ExecStartPost hooks

Proposed config

template: /etc/unitdore/unit.service.tmpl  # optional path to custom template

Template uses Go text/template with the same templateData struct already in systemd/generator.go. Built-in template is used as fallback if no custom template is set.

Per-unit override

Also consider allowing per-unit template overrides:

units:
  - name: nginx
    template: /etc/unitdore/templates/nginx.service.tmpl
Allow users to provide their own `.service` file template to override the built-in one. ## Use cases - Add custom `[Unit]` dependencies (`Requires=`, `After=docker.service`, etc.) - Set environment variables (`Environment=`, `EnvironmentFile=`) - Change restart policy, timeouts, resource limits - Add `ExecStartPre` / `ExecStartPost` hooks ## Proposed config ```yaml template: /etc/unitdore/unit.service.tmpl # optional path to custom template ``` Template uses Go `text/template` with the same `templateData` struct already in `systemd/generator.go`. Built-in template is used as fallback if no custom template is set. ## Per-unit override Also consider allowing per-unit template overrides: ```yaml units: - name: nginx template: /etc/unitdore/templates/nginx.service.tmpl ```
Owner

With this feature we must have the ability to get all the variables we can use. maybe a list-variables command that lists the [variable name] and what it does and is for.

With this feature we must have the ability to get all the variables we can use. maybe a list-variables command that lists the [variable name] and what it does and is for.
Sign in to join this conversation.