Skip to content

Commit

Permalink
profiles: Add --detach/-d flag
Browse files Browse the repository at this point in the history
This new flag makes the detached mode to become an opt-in, allowing
for better user experience.

Signed-off-by: Paulo Gomes <pjbgf@linux.com>
  • Loading branch information
pjbgf committed Feb 24, 2025
1 parent b0ae038 commit fa2f8fc
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions cmd/cli/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/urfave/cli/v3"
)

var selfcall bool
var detach bool

func startCommand() *cli.Command {
cmd := &cli.Command{
Expand Down Expand Up @@ -43,16 +43,19 @@ qubesome start -git https://github.com/qubesome/sample-dotfiles i3
&cli.StringFlag{
Name: "runner",
Destination: &runner,
Usage: "sets what runner to be used, this will override the value set at the qubesome.config. Options: docker or podman.",
},
&cli.BoolFlag{
Name: "interactive",
Aliases: []string{"i"},
Destination: &interactive,
Usage: "enables interactive mode, which runs the profile container but holds any windows manager execution. Use this for troubleshooting.",
},
&cli.BoolFlag{
Sources: cli.EnvVars("QUBESOME_SELFCALL"),
Destination: &selfcall,
Hidden: true,
Name: "detach",
Aliases: []string{"d"},
Destination: &detach,
Usage: "start the profile process in the background. This cannot be used in conjunction with --interactive nor --debug.",
},
},
Arguments: []cli.Argument{
Expand All @@ -66,11 +69,18 @@ qubesome start -git https://github.com/qubesome/sample-dotfiles i3
Action: func(ctx context.Context, cmd *cli.Command) error {
// When a profile is started, it starts an inception server
// so that the containerised Windows Manager is able to execute
// new container workloads. This self-calls qubesome and leave it
// running so that the main process exits right away.
if !debug && !interactive && !selfcall {
cmd := exec.Command(os.Args[0], os.Args[1:]...) //nolint
cmd.Env = append(cmd.Env, "QUBESOME_SELFCALL=true")
// new container workloads.
// Running on detached mode makes a background call to qubesome,
// leaving it running so that the main process can exit right away.
if !debug && !interactive && detach {
var args []string
for _, arg := range os.Args[1:] {
if arg == "-d" || arg == "-detach" {
continue
}
args = append(args, arg)
}
cmd := exec.Command(os.Args[0], args...) //nolint
cmd.Env = append(cmd.Env, os.Environ()...)
cmd.Stdout = nil
cmd.Stderr = nil
Expand All @@ -80,10 +90,10 @@ qubesome start -git https://github.com/qubesome/sample-dotfiles i3
}

if err := cmd.Start(); err != nil {
return fmt.Errorf("failed to daemonise profile start: %w", err)
return fmt.Errorf("failed to run profile start in detach mode: %w", err)
}

fmt.Printf("[%d] profile start as daemon\n", cmd.Process.Pid)
fmt.Printf("[%d] %q profile start detached\n", cmd.Process.Pid, targetProfile)
os.Exit(0)
}

Expand Down

0 comments on commit fa2f8fc

Please sign in to comment.