Add prefix/suffix support, short ID fallback, unit docs

- config: add Prefix/Suffix fields to Config struct
- systemd: ServiceName/Generate/UnitPath/Install/Uninstall/Enable/Disable/Status all accept prefix+suffix
- runtime: fall back to short container ID (12 chars) when container has no name
- cmd: active, status, install all thread prefix/suffix from config
- systemd/generator_test.go: updated all calls + added TestGenerate_WithPrefixSuffix
- docs/generated-units.md: full examples of every unit type + ordering + naming
- README: updated config docs, prefix/suffix section, link to docs/
This commit is contained in:
2026-04-03 15:47:56 +02:00
parent 5078558d01
commit a8c12c8c21
11 changed files with 419 additions and 51 deletions

View File

@@ -76,6 +76,9 @@ oldthing podman hein no no — container
**Location:** `/etc/unitdore/units.yaml`
```yaml
prefix: "" # optional: prepended to all service names, e.g. "prod-"
suffix: "" # optional: appended to all service names, e.g. "-svc"
units:
- name: nginx
runtime: podman # podman | docker
@@ -94,7 +97,35 @@ units:
enabled: true
```
## Generated unit file (example)
### Prefix and suffix
Set `prefix` and/or `suffix` to namespace your service files:
```yaml
prefix: prod-
suffix: ""
```
Generates: `unitdore-prod-nginx.service`, `unitdore-prod-myapp.service`, etc.
Prefix/suffix apply to the **service file name only** — container names are unchanged.
### Unnamed containers
If a container has no name, `syncup` uses its short container ID (first 12 chars) as the unit name.
You can rename it later with `unitdore edit`.
## Generated unit files
See **[docs/generated-units.md](docs/generated-units.md)** for full examples covering:
- System units (root)
- User units (rootless)
- Docker vs Podman
- Custom commands
- Prefix/suffix naming
- Startup ordering
- Unnamed containers (short ID fallback)
Quick example:
```ini
# /etc/systemd/system/unitdore-nginx.service
@@ -115,8 +146,6 @@ RestartSec=5
WantedBy=multi-user.target
```
For user units (rootless containers), files go to `~/.config/systemd/user/` and target `default.target`.
## Flags
```