-
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
49 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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") | ||
} |