- 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
50 lines
1.3 KiB
Go
50 lines
1.3 KiB
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/spf13/cobra"
|
|
"github.com/warkanum/unitdore/config"
|
|
"github.com/warkanum/unitdore/sysuser"
|
|
)
|
|
|
|
var version = "0.0.10"
|
|
|
|
var configPath string
|
|
|
|
var rootCmd = &cobra.Command{
|
|
Use: "unitdore",
|
|
Short: "A door you open and close for container units",
|
|
Long: `Unitdore manages container units via systemd.
|
|
|
|
It discovers running containers and podman-compose stacks, stores them in a
|
|
config file, and generates + manages systemd .service units for each one.
|
|
|
|
As root: system units, plus user units for users listed in 'users:'.
|
|
As a normal user: own config and user units only.`,
|
|
Version: version,
|
|
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
|
|
// Normal users get their own config and manage only their user units
|
|
if !cmd.Flags().Changed("config") && !sysuser.IsRoot() {
|
|
home, err := sysuser.HomeDir(sysuser.Current())
|
|
if err != nil {
|
|
return err
|
|
}
|
|
configPath = config.UserConfigPath(home)
|
|
}
|
|
return nil
|
|
},
|
|
}
|
|
|
|
func Execute() {
|
|
if err := rootCmd.Execute(); err != nil {
|
|
fmt.Fprintln(os.Stderr, err)
|
|
os.Exit(1)
|
|
}
|
|
}
|
|
|
|
func init() {
|
|
rootCmd.PersistentFlags().StringVar(&configPath, "config", config.DefaultConfigPath, "path to units config file (default for non-root: ~/.config/unitdore/units.yaml)")
|
|
}
|