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:
+10
-6
@@ -6,7 +6,7 @@ import (
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/warkanum/unitdore/config"
|
||||
"github.com/warkanum/unitdore/systemd"
|
||||
"github.com/warkanum/unitdore/initsys"
|
||||
)
|
||||
|
||||
var uninstallallCmd = &cobra.Command{
|
||||
@@ -27,6 +27,10 @@ func runUninstallall(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
prefix, suffix := cfg.Prefix, cfg.Suffix
|
||||
ini, err := initsys.New(cfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
units := make([]config.Unit, len(cfg.Units))
|
||||
copy(units, cfg.Units)
|
||||
@@ -41,19 +45,19 @@ func runUninstallall(cmd *cobra.Command, args []string) error {
|
||||
failed := 0
|
||||
|
||||
for _, u := range units {
|
||||
if !systemd.IsInstalled(u, prefix, suffix) {
|
||||
if !ini.IsInstalled(u, prefix, suffix) {
|
||||
continue
|
||||
}
|
||||
svcName := systemd.ServiceName(u, prefix, suffix)
|
||||
svcName := ini.ServiceName(u, prefix, suffix)
|
||||
fmt.Printf(" ■ disabling %s...\n", svcName)
|
||||
if err := systemd.Disable(u, prefix, suffix); err != nil {
|
||||
if err := ini.Disable(u, prefix, suffix); err != nil {
|
||||
fmt.Printf(" ✗ failed to disable %s: %v\n", u.Name, err)
|
||||
failed++
|
||||
continue
|
||||
}
|
||||
path, _ := systemd.UnitPath(u, prefix, suffix)
|
||||
path, _ := ini.UnitPath(u, prefix, suffix)
|
||||
fmt.Printf(" ✗ removing %s...\n", path)
|
||||
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)
|
||||
failed++
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user