diff --git a/src/cmd/project_runner.go b/src/cmd/project_runner.go index 8a5c41d..a178b19 100644 --- a/src/cmd/project_runner.go +++ b/src/cmd/project_runner.go @@ -1,14 +1,12 @@ package cmd import ( - "fmt" "github.com/f1bonacc1/process-compose/src/app" "github.com/f1bonacc1/process-compose/src/config" "github.com/f1bonacc1/process-compose/src/loader" "github.com/f1bonacc1/process-compose/src/tui" "github.com/rs/zerolog/log" "os" - "os/exec" "os/signal" "syscall" ) @@ -139,34 +137,3 @@ func quiet() func() { os.Stderr = serr } } - -func runInDetachedMode() { - log.Info().Msg("Running in detached mode") - fmt.Println("Starting Process Compose in detached mode. Use 'process-compose attach' to connect to it or 'process-compose down' to stop it") - //remove detached flag - for i, arg := range os.Args { - if arg == "-D" || arg == "--detached" { - os.Args = append(os.Args[:i], os.Args[i+1:]...) - break - } - } - // Prepare to launch the background process - os.Args = append(os.Args, "-t=false") - cmd := exec.Command(os.Args[0], os.Args[1:]...) - cmd.SysProcAttr = &syscall.SysProcAttr{ - Setsid: true, // Detach from terminal - } - - // Redirect standard file descriptors to /dev/null - cmd.Stdin = nil - cmd.Stdout, _ = os.OpenFile("/dev/null", os.O_RDWR, 0) - cmd.Stderr, _ = os.OpenFile("/dev/null", os.O_RDWR, 0) - - // Start the process in the background - if err := cmd.Start(); err != nil { - panic(err) - } - - // Exit the parent process - os.Exit(0) -} diff --git a/src/cmd/project_runner_unix.go b/src/cmd/project_runner_unix.go new file mode 100644 index 0000000..36e52ab --- /dev/null +++ b/src/cmd/project_runner_unix.go @@ -0,0 +1,42 @@ +//go:build !windows + +package cmd + +import ( + "fmt" + "github.com/rs/zerolog/log" + "os" + "os/exec" + "syscall" +) + +func runInDetachedMode() { + log.Info().Msg("Running in detached mode") + fmt.Println("Starting Process Compose in detached mode. Use 'process-compose attach' to connect to it or 'process-compose down' to stop it") + //remove detached flag + for i, arg := range os.Args { + if arg == "-D" || arg == "--detached" { + os.Args = append(os.Args[:i], os.Args[i+1:]...) + break + } + } + // Prepare to launch the background process + os.Args = append(os.Args, "-t=false") + cmd := exec.Command(os.Args[0], os.Args[1:]...) + cmd.SysProcAttr = &syscall.SysProcAttr{ + Setsid: true, // Detach from terminal + } + + // Redirect standard file descriptors to /dev/null + cmd.Stdin = nil + cmd.Stdout, _ = os.OpenFile("/dev/null", os.O_RDWR, 0) + cmd.Stderr, _ = os.OpenFile("/dev/null", os.O_RDWR, 0) + + // Start the process in the background + if err := cmd.Start(); err != nil { + panic(err) + } + + // Exit the parent process + os.Exit(0) +} diff --git a/src/cmd/project_runner_windows.go b/src/cmd/project_runner_windows.go new file mode 100644 index 0000000..0ecaba9 --- /dev/null +++ b/src/cmd/project_runner_windows.go @@ -0,0 +1,7 @@ +package cmd + +import "github.com/rs/zerolog/log" + +func runInDetachedMode() { + log.Fatal().Msg("Running in detached mode is not supported on Windows") +}