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:
+14
-10
@@ -5,7 +5,7 @@ import (
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/warkanum/unitdore/config"
|
||||
"github.com/warkanum/unitdore/systemd"
|
||||
"github.com/warkanum/unitdore/initsys"
|
||||
)
|
||||
|
||||
var dryRun bool
|
||||
@@ -32,6 +32,10 @@ func runInstall(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
prefix, suffix := cfg.Prefix, cfg.Suffix
|
||||
ini, err := initsys.New(cfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
installed := 0
|
||||
skipped := 0
|
||||
removed := 0
|
||||
@@ -40,14 +44,14 @@ func runInstall(cmd *cobra.Command, args []string) error {
|
||||
for _, u := range cfg.Units {
|
||||
if !u.Enabled {
|
||||
// Remove unit file if it exists for disabled units
|
||||
if systemd.IsInstalled(u, prefix, suffix) {
|
||||
if ini.IsInstalled(u, prefix, suffix) {
|
||||
if dryRun {
|
||||
fmt.Printf(" ~ would remove: %s\n", systemd.ServiceName(u, prefix, suffix))
|
||||
fmt.Printf(" ~ would remove: %s\n", ini.ServiceName(u, prefix, suffix))
|
||||
} else {
|
||||
if err := systemd.Uninstall(u, prefix, suffix); err != nil {
|
||||
if err := ini.Uninstall(u, prefix, suffix); err != nil {
|
||||
fmt.Printf(" ✗ failed to remove %s: %v\n", u.Name, err)
|
||||
} else {
|
||||
fmt.Printf(" - removed: %s (disabled)\n", systemd.ServiceName(u, prefix, suffix))
|
||||
fmt.Printf(" - removed: %s (disabled)\n", ini.ServiceName(u, prefix, suffix))
|
||||
removed++
|
||||
}
|
||||
}
|
||||
@@ -58,23 +62,23 @@ func runInstall(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
if dryRun {
|
||||
content, err := systemd.Generate(u, prefix, suffix)
|
||||
content, err := ini.Generate(u, prefix, suffix)
|
||||
if err != nil {
|
||||
fmt.Printf(" ✗ %s: %v\n", u.Name, err)
|
||||
continue
|
||||
}
|
||||
path, _ := systemd.UnitPath(u, prefix, suffix)
|
||||
path, _ := ini.UnitPath(u, prefix, suffix)
|
||||
fmt.Printf("\n--- %s ---\n%s\n", path, content)
|
||||
installed++
|
||||
continue
|
||||
}
|
||||
|
||||
if err := systemd.Install(u, prefix, suffix); err != nil {
|
||||
if err := ini.Install(u, prefix, suffix); err != nil {
|
||||
fmt.Printf(" ✗ failed: %s: %v\n", u.Name, err)
|
||||
} else {
|
||||
path, _ := systemd.UnitPath(u, prefix, suffix)
|
||||
path, _ := ini.UnitPath(u, prefix, suffix)
|
||||
fmt.Printf(" ✓ installed: %s\n", path)
|
||||
lingerHint(lingerSeen, u)
|
||||
lingerHint(ini, lingerSeen, u)
|
||||
installed++
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user