- syncup: podman first, docker only as fallback (podman wins on name clash;
existing docker units found in podman switch to podman)
- syncup: group podman-compose containers into one `kind: stack` unit per
project (project, working_dir, compose_files, compose_bin from labels);
disable existing member units ("part of stack <project>")
- generator: compose mode (podman-compose up/stop, WorkingDirectory) with
pod start/stop fallback when compose binary/dir/files are missing
- reconcile: stacks disabled with "stack not found" when neither compose
files nor pod exist
- root: scan root + rootless users listed in `users:` (podman only)
- non-root: config ~/.config/unitdore/units.yaml, own user units only
- sysuser package: runuser with XDG_RUNTIME_DIR/DBUS env, home/linger lookup
- install: warn when linger is not enabled for user units
- testdata/stack: podman-compose test stack and captured podman ps fixture
- docs: README, generated-units, man page, AGENTS, PLAN
87 lines
2.1 KiB
Go
87 lines
2.1 KiB
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/spf13/cobra"
|
|
"github.com/warkanum/unitdore/config"
|
|
"github.com/warkanum/unitdore/systemd"
|
|
)
|
|
|
|
var dryRun bool
|
|
|
|
var installCmd = &cobra.Command{
|
|
Use: "install",
|
|
Short: "Generate and install systemd unit files for all enabled units",
|
|
Long: `Install generates .service files for all enabled units and writes them
|
|
to the appropriate systemd directory. It does not enable or start them.
|
|
|
|
Use --dry-run to preview the generated unit files without writing anything.`,
|
|
RunE: runInstall,
|
|
}
|
|
|
|
func init() {
|
|
installCmd.Flags().BoolVar(&dryRun, "dry-run", false, "preview unit files without writing")
|
|
rootCmd.AddCommand(installCmd)
|
|
}
|
|
|
|
func runInstall(cmd *cobra.Command, args []string) error {
|
|
cfg, err := config.Load(configPath)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
prefix, suffix := cfg.Prefix, cfg.Suffix
|
|
installed := 0
|
|
skipped := 0
|
|
removed := 0
|
|
lingerSeen := map[string]bool{}
|
|
|
|
for _, u := range cfg.Units {
|
|
if !u.Enabled {
|
|
// Remove unit file if it exists for disabled units
|
|
if systemd.IsInstalled(u, prefix, suffix) {
|
|
if dryRun {
|
|
fmt.Printf(" ~ would remove: %s\n", systemd.ServiceName(u, prefix, suffix))
|
|
} else {
|
|
if err := systemd.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))
|
|
removed++
|
|
}
|
|
}
|
|
} else {
|
|
skipped++
|
|
}
|
|
continue
|
|
}
|
|
|
|
if dryRun {
|
|
content, err := systemd.Generate(u, prefix, suffix)
|
|
if err != nil {
|
|
fmt.Printf(" ✗ %s: %v\n", u.Name, err)
|
|
continue
|
|
}
|
|
path, _ := systemd.UnitPath(u, prefix, suffix)
|
|
fmt.Printf("\n--- %s ---\n%s\n", path, content)
|
|
installed++
|
|
continue
|
|
}
|
|
|
|
if err := systemd.Install(u, prefix, suffix); err != nil {
|
|
fmt.Printf(" ✗ failed: %s: %v\n", u.Name, err)
|
|
} else {
|
|
path, _ := systemd.UnitPath(u, prefix, suffix)
|
|
fmt.Printf(" ✓ installed: %s\n", path)
|
|
lingerHint(lingerSeen, u)
|
|
installed++
|
|
}
|
|
}
|
|
|
|
if !dryRun {
|
|
fmt.Printf("\nDone. Installed: %d Removed: %d Skipped: %d\n", installed, removed, skipped)
|
|
}
|
|
return nil
|
|
}
|