mirror of https://github.com/dapr/cli.git
parent
8e183b25db
commit
4ad42fffbc
|
@ -9,10 +9,8 @@ import (
|
|||
"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/signal"
|
||||
"strconv"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/dapr/cli/pkg/metadata"
|
||||
|
@ -90,7 +88,7 @@ var RunCmd = &cobra.Command{
|
|||
}
|
||||
|
||||
sigCh := make(chan os.Signal, 1)
|
||||
signal.Notify(sigCh, syscall.SIGTERM, syscall.SIGINT)
|
||||
setupShutdownNotify(sigCh)
|
||||
|
||||
daprRunning := make(chan bool, 1)
|
||||
appRunning := make(chan bool, 1)
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
// +build !windows
|
||||
|
||||
// ------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation and Dapr Contributors.
|
||||
// Licensed under the MIT License.
|
||||
// ------------------------------------------------------------
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func setupShutdownNotify(sigCh chan os.Signal) {
|
||||
signal.Notify(sigCh, syscall.SIGTERM, syscall.SIGINT)
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
// ------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation and Dapr Contributors.
|
||||
// Licensed under the MIT License.
|
||||
// ------------------------------------------------------------
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
"github.com/dapr/cli/pkg/print"
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
func setupShutdownNotify(sigCh chan os.Signal){
|
||||
//This will catch Ctrl-C
|
||||
signal.Notify(sigCh, syscall.SIGTERM, syscall.SIGINT)
|
||||
|
||||
// Unlike Linux/Mac, you can't just send a SIGTERM from another process
|
||||
// In order for 'dapr stop' to be able to signal gracefully we must use a named event in Windows
|
||||
go func() {
|
||||
eventName, _ := syscall.UTF16FromString(fmt.Sprintf("dapr_cli_%v", os.Getpid()))
|
||||
eventHandle, _ := windows.CreateEvent(nil, 0, 0, &eventName[0])
|
||||
_, err := windows.WaitForSingleObject(eventHandle, windows.INFINITE)
|
||||
if err != nil {
|
||||
print.WarningStatusEvent(os.Stdout, "Unable to wait for shutdown event. 'dapr stop' will not work. Error: %s", err.Error())
|
||||
return
|
||||
}
|
||||
sigCh <- os.Interrupt
|
||||
}()
|
||||
}
|
1
go.mod
1
go.mod
|
@ -23,6 +23,7 @@ require (
|
|||
github.com/spf13/cobra v1.1.1
|
||||
github.com/spf13/viper v1.7.0
|
||||
github.com/stretchr/testify v1.6.1
|
||||
golang.org/x/sys v0.0.0-20210319071255-635bc2c9138d // indirect
|
||||
gopkg.in/yaml.v2 v2.3.0
|
||||
helm.sh/helm/v3 v3.4.0
|
||||
k8s.io/api v0.20.0
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// +build !windows
|
||||
|
||||
// ------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation and Dapr Contributors.
|
||||
// Licensed under the MIT License.
|
||||
|
@ -7,7 +9,6 @@ package standalone
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
|
||||
"github.com/dapr/cli/utils"
|
||||
)
|
||||
|
@ -23,12 +24,7 @@ func Stop(appID string) error {
|
|||
if a.AppID == appID {
|
||||
pid := fmt.Sprintf("%v", a.PID)
|
||||
|
||||
var err error
|
||||
if runtime.GOOS == "windows" {
|
||||
_, err = utils.RunCmdAndWait("taskkill", "/F", "/T", "/PID", pid)
|
||||
} else {
|
||||
_, err = utils.RunCmdAndWait("kill", pid)
|
||||
}
|
||||
_, err := utils.RunCmdAndWait("kill", pid)
|
||||
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
// ------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation and Dapr Contributors.
|
||||
// Licensed under the MIT License.
|
||||
// ------------------------------------------------------------
|
||||
|
||||
package standalone
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"syscall"
|
||||
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
// Stop terminates the application process.
|
||||
func Stop(appID string) error {
|
||||
apps, err := List()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, a := range apps {
|
||||
if a.AppID == appID {
|
||||
eventName, _ := syscall.UTF16FromString(fmt.Sprintf("dapr_cli_%v", a.PID))
|
||||
eventHandle, err := windows.OpenEvent(windows.EVENT_MODIFY_STATE, false, &eventName[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = windows.SetEvent(eventHandle)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return fmt.Errorf("couldn't find app id %s", appID)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue