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:
@@ -0,0 +1,52 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/warkanum/unitdore/config"
|
||||
"github.com/warkanum/unitdore/initsys"
|
||||
)
|
||||
|
||||
var enableAll bool
|
||||
|
||||
var enableCmd = &cobra.Command{
|
||||
Use: "enable <name> | --all",
|
||||
Short: "Enable at boot and start a unit (or all with --all)",
|
||||
Long: `Enable enables the named installed unit at boot and starts it.
|
||||
|
||||
With --all (same as 'enableall') it does so for every enabled, installed unit
|
||||
in startup order, like 'start --all'.`,
|
||||
Args: nameOrAll(&enableAll),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
cfg, ini, err := loadInit()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if enableAll {
|
||||
bulkStart(cfg, ini, os.Stdout, initsys.Init.Enable, "enabled")
|
||||
return nil
|
||||
}
|
||||
return enableOne(cfg, ini, args[0], os.Stdout)
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
enableCmd.Flags().BoolVar(&enableAll, "all", false, "enable all enabled, installed units")
|
||||
rootCmd.AddCommand(enableCmd)
|
||||
}
|
||||
|
||||
func enableOne(cfg *config.Config, ini initsys.Init, name string, w io.Writer) error {
|
||||
u, err := installedUnit(cfg, ini, name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Fprintf(w, " ▶ enabling %s...\n", ini.ServiceName(*u, cfg.Prefix, cfg.Suffix))
|
||||
if err := ini.Enable(*u, cfg.Prefix, cfg.Suffix); err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Fprintf(w, " ✓ enabled: %s\n", name)
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user