-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Send the running app and dapr an interrupt signal instead of killing …
…them immediately. This allows the processes to clean up appropriately.
- Loading branch information
Showing
8 changed files
with
143 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,4 +25,4 @@ cli | |
# CLI's auto-generated components directory | ||
**/components | ||
|
||
test_output.json | ||
test_output.json |
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,28 @@ | ||
// +build !windows | ||
|
||
package cmd | ||
|
||
import ( | ||
"os" | ||
"os/exec" | ||
"syscall" | ||
) | ||
|
||
// interruptProcess sends an Interrupt signal to the process. | ||
func interruptProcess(proc *os.Process) error { | ||
return proc.Signal(os.Interrupt) | ||
} | ||
|
||
func suppressCtrlC(err error) error { | ||
if exitErr, ok := err.(*exec.ExitError); ok { | ||
// The SIGINT signal is sent when the user at the | ||
// controlling terminal presses the interrupt character, | ||
// which by default is ^C (Control-C) | ||
// https://golang.org/pkg/os/signal/#hdr-Types_of_signals | ||
if exitErr.ExitCode() == int(syscall.SIGINT) { | ||
return nil | ||
} | ||
} | ||
|
||
return err | ||
} |
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,26 @@ | ||
package cmd | ||
|
||
import ( | ||
"os" | ||
"os/exec" | ||
|
||
"golang.org/x/sys/windows" | ||
) | ||
|
||
// interruptProcess sends a CTRL-BREAK to the process. | ||
func interruptProcess(proc *os.Process) error { | ||
return windows.GenerateConsoleCtrlEvent(windows.CTRL_BREAK_EVENT, uint32(proc.Pid)) | ||
} | ||
|
||
func suppressCtrlC(err error) error { | ||
if exitErr, ok := err.(*exec.ExitError); ok { | ||
// windows.STATUS_CONTROL_C_EXIT means | ||
// The application terminated as a result of a CTRL+C. | ||
// http://errorco.de/win32/ntstatus-h/status_control_c_exit/0xc000013a/ | ||
if exitErr.ExitCode() == int(windows.STATUS_CONTROL_C_EXIT) { | ||
return nil | ||
} | ||
} | ||
|
||
return err | ||
} |
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,17 @@ | ||
//go:build !windows | ||
// +build !windows | ||
|
||
// ------------------------------------------------------------ | ||
// Copyright (c) Microsoft Corporation and Dapr Contributors. | ||
// Licensed under the MIT License. | ||
// ------------------------------------------------------------ | ||
|
||
package standalone | ||
|
||
import ( | ||
"os/exec" | ||
) | ||
|
||
func setCmdSysProcAttr(cmd *exec.Cmd) { | ||
// Do nothing | ||
} |
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,19 @@ | ||
// ------------------------------------------------------------ | ||
// Copyright (c) Microsoft Corporation and Dapr Contributors. | ||
// Licensed under the MIT License. | ||
// ------------------------------------------------------------ | ||
|
||
package standalone | ||
|
||
import ( | ||
"os/exec" | ||
"syscall" | ||
) | ||
|
||
func setCmdSysProcAttr(cmd *exec.Cmd) { | ||
if cmd.SysProcAttr == nil { | ||
cmd.SysProcAttr = &syscall.SysProcAttr{} | ||
} | ||
|
||
cmd.SysProcAttr.CreationFlags = syscall.CREATE_NEW_PROCESS_GROUP | ||
} |
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