feat: OpenRC and runit init backends behind an Init interface
Extract init-neutral unit resolution into service/, add initsys.Init with systemd, openrc and runit backends, selected by 'init:' config or autodetect. OpenRC and runit are root only; rootless units run as system services as that user. Add docs and generated examples for all three.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
## Project Overview
|
||||
|
||||
**Unitdore** is a Go CLI tool that bridges container runtimes (Podman, Docker) and systemd. It discovers running containers, stores them in a YAML config, and generates + manages systemd `.service` unit files for each one.
|
||||
**Unitdore** is a Go CLI tool that bridges container runtimes (Podman, Docker) and the init system (systemd, OpenRC, runit). It discovers running containers, stores them in a YAML config, and generates + manages service files for each one.
|
||||
|
||||
# Agent Rules
|
||||
|
||||
@@ -33,7 +33,11 @@ config/ # Config struct + YAML load/save (units.yaml)
|
||||
runtime/ # Docker and Podman runtime abstraction, compose labels
|
||||
sysuser/ # run commands as root/user (runuser), home/linger lookup
|
||||
testdata/stack # podman-compose test stack + captured `podman ps` fixture
|
||||
systemd/ # .service file generator and systemd manager
|
||||
service/ # init-neutral unit resolution: commands, quoting, user env
|
||||
initsys/ # Init interface, backend selection (config init: / autodetect)
|
||||
systemd/ # .service generator + systemctl manager (Backend)
|
||||
openrc/ # /etc/init.d script generator + rc-service manager (Backend)
|
||||
runit/ # /etc/sv run/finish generator + sv manager (Backend)
|
||||
docs/ # generated-units.md (unit file examples), unitdore.1 (man page)
|
||||
```
|
||||
|
||||
@@ -41,13 +45,18 @@ docs/ # generated-units.md (unit file examples), unitdore.1 (man page)
|
||||
|
||||
- **`config`** — `Unit` and `Config` structs; `Load`, `Save`, `FindUnit`, `AddUnit`
|
||||
- **`runtime`** — `ContainerRuntime` interface; `docker.go`, `podman.go` implementations
|
||||
- **`service`** — `Resolve(unit)` → start/stop commands, type, workdir; shared by all backends
|
||||
- **`initsys`** — `Init` interface; `New(cfg)` picks backend; cmd/ only talks to `Init`
|
||||
- **`systemd`** — `generator.go` builds `.service` file content; `manager.go` calls `systemctl`
|
||||
- **`openrc`**, **`runit`** — same role; root only; tests stub command execution via package vars
|
||||
|
||||
### Config file
|
||||
|
||||
**Location:** `/etc/unitdore/units.yaml`
|
||||
|
||||
```yaml
|
||||
init: "" # systemd | openrc | runit (empty = autodetect)
|
||||
service_dir: "" # runit: supervised dir (empty = autodetect)
|
||||
prefix: "" # prepended to service file name (e.g. "prod-")
|
||||
suffix: "" # appended to service file name (e.g. "-svc")
|
||||
users: [] # root only: rootless users scanned by syncup
|
||||
@@ -101,6 +110,10 @@ Tests exist in:
|
||||
- `runtime/runtime_test.go`
|
||||
- `cmd/syncup_test.go`
|
||||
- `sysuser/sysuser_test.go`
|
||||
- `service/spec_test.go`
|
||||
- `initsys/initsys_test.go`
|
||||
- `openrc/openrc_test.go`
|
||||
- `runit/runit_test.go`
|
||||
- `systemd/generator_test.go`
|
||||
|
||||
Always run `make test` before marking a task complete. Add tests for new behaviour in the same package as the code under test.
|
||||
|
||||
Reference in New Issue
Block a user