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:
@@ -51,17 +51,17 @@ type templateData struct {
|
||||
ExecStop string
|
||||
}
|
||||
|
||||
// ServiceName returns the systemd service name for a unit.
|
||||
func ServiceName(u config.Unit) string {
|
||||
return fmt.Sprintf("unitdore-%s.service", u.Name)
|
||||
// ServiceName returns the systemd service name for a unit, with optional prefix/suffix.
|
||||
func ServiceName(u config.Unit, prefix, suffix string) string {
|
||||
return fmt.Sprintf("unitdore-%s%s%s.service", prefix, u.Name, suffix)
|
||||
}
|
||||
|
||||
// Generate produces the .service file content for a unit.
|
||||
func Generate(u config.Unit) (string, error) {
|
||||
func Generate(u config.Unit, prefix, suffix string) (string, error) {
|
||||
execStart, execStop := buildExecCommands(u)
|
||||
|
||||
data := templateData{
|
||||
ServiceName: ServiceName(u),
|
||||
ServiceName: ServiceName(u, prefix, suffix),
|
||||
Unit: u,
|
||||
ExecStart: execStart,
|
||||
ExecStop: execStop,
|
||||
|
||||
Reference in New Issue
Block a user