feat: order/delay in service files, enable cmd, --all on unit commands

- install/uninstall/start/stop/enable take <name> or --all; *all kept as shortcuts
- add enable (enable at boot + start); startall no longer enables
- order/delay resolved by config.ResolveOrder and written into systemd,
  OpenRC and runit service files (After=/sleep), so they apply at boot
- install --all stops and disables units before removing their files
- update regenerates all installed, enabled units and removes disabled ones
- edit creates the config dir; docs and man page updated
- tests: fake Init for cmd, ResolveOrder, backend ordering output
This commit is contained in:
2026-10-12 21:31:41 +02:00
parent d1d0889eb3
commit 91811b4fa1
28 changed files with 1394 additions and 503 deletions
+29 -26
View File
@@ -2,49 +2,52 @@ package cmd
import (
"fmt"
"io"
"os"
"github.com/spf13/cobra"
"github.com/warkanum/unitdore/config"
"github.com/warkanum/unitdore/initsys"
)
var startAll bool
var startCmd = &cobra.Command{
Use: "start <name>",
Short: "Start a unit by name",
Args: cobra.ExactArgs(1),
RunE: runStart,
Use: "start <name> | --all",
Short: "Start a unit by name (or all with --all)",
Long: `Start starts the named installed unit without enabling it at boot.
With --all (same as 'startall') it starts every enabled, installed unit in
startup order: equal 'order' values in parallel, groups one after another.
'delay' is waited inside the generated service.`,
Args: nameOrAll(&startAll),
RunE: func(cmd *cobra.Command, args []string) error {
cfg, ini, err := loadInit()
if err != nil {
return err
}
if startAll {
bulkStart(cfg, ini, os.Stdout, initsys.Init.Start, "started")
return nil
}
return startOne(cfg, ini, args[0], os.Stdout)
},
}
func init() {
startCmd.Flags().BoolVar(&startAll, "all", false, "start all enabled, installed units")
rootCmd.AddCommand(startCmd)
}
func runStart(cmd *cobra.Command, args []string) error {
cfg, err := config.Load(configPath)
func startOne(cfg *config.Config, ini initsys.Init, name string, w io.Writer) error {
u, err := installedUnit(cfg, ini, name)
if err != nil {
return err
}
name := args[0]
u := cfg.FindUnit(name)
if u == nil {
return fmt.Errorf("unit %q not found", name)
}
prefix, suffix := cfg.Prefix, cfg.Suffix
ini, err := initsys.New(cfg)
if err != nil {
fmt.Fprintf(w, " ▶ starting %s...\n", ini.ServiceName(*u, cfg.Prefix, cfg.Suffix))
if err := ini.Start(*u, cfg.Prefix, cfg.Suffix); err != nil {
return err
}
if !ini.IsInstalled(*u, prefix, suffix) {
return fmt.Errorf("%s is not installed — run 'unitdore install' first", name)
}
fmt.Printf(" ▶ starting %s...\n", ini.ServiceName(*u, prefix, suffix))
if err := ini.Start(*u, prefix, suffix); err != nil {
return err
}
fmt.Printf(" ✓ started: %s\n", name)
fmt.Fprintf(w, " ✓ started: %s\n", name)
return nil
}