forked from go-debos/debos
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
debug: run interactive shell on error
Launch interactive shell in context of failed action for issues investigation and debug. Add options to debos: --debug-shell -- to start a shell in case of any failure --shell <path> -- use selected shell instead of default bash Fixes go-debos#30 Signed-off-by: Denis Pynkin <[email protected]>
- Loading branch information
Showing
3 changed files
with
56 additions
and
9 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
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,31 @@ | ||
package debos | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
) | ||
|
||
/* | ||
DebugShell function launches an interactive shell for | ||
debug and problems investigation. | ||
*/ | ||
func DebugShell(context DebosContext) { | ||
|
||
if len(context.DebugShell) == 0 { | ||
return | ||
} | ||
|
||
pa := os.ProcAttr{ | ||
Files: []*os.File{os.Stdin, os.Stdout, os.Stderr}, | ||
Dir: context.Scratchdir, | ||
} | ||
|
||
// Start an interactive shell for debug. | ||
log.Printf(">>> Starting a debug shell") | ||
if proc, err := os.StartProcess(context.DebugShell, []string{}, &pa); err != nil { | ||
fmt.Printf("Failed: %s\n", err) | ||
} else { | ||
proc.Wait() | ||
} | ||
} |