Add stop command (#45)

* added stop command

* readme update
This commit is contained in:
Yaron Schneider 2019-08-20 12:27:56 -07:00 committed by GitHub
parent 4397421acf
commit ce7a31b8f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 70 additions and 0 deletions

View File

@ -118,3 +118,12 @@ To list all Actions instances running in a Kubernetes cluster:
``` ```
$ actions list --kubernetes $ actions list --kubernetes
``` ```
#### Stop
Use ```actions list``` to get a list of all running instances.
To stop an actions app on your machine:
```
$ actions stop --app-id myAppID
```

View File

@ -154,6 +154,7 @@ var RunCmd = &cobra.Command{
AppPort: appPort, AppPort: appPort,
Command: strings.Join(args, " "), Command: strings.Join(args, " "),
Created: actionsRunCreatedTime, Created: actionsRunCreatedTime,
PID: os.Getpid(),
}) })
print.SuccessStatusEvent(os.Stdout, "You're up and running! Both Actions and your app logs will appear here.\n") print.SuccessStatusEvent(os.Stdout, "You're up and running! Both Actions and your app logs will appear here.\n")

29
cmd/stop.go Normal file
View File

@ -0,0 +1,29 @@
package cmd
import (
"os"
"github.com/actionscore/cli/pkg/print"
"github.com/actionscore/cli/pkg/standalone"
"github.com/spf13/cobra"
)
var stopAppID string
var StopCmd = &cobra.Command{
Use: "stop",
Short: "Stops a running Actions instance and its associated app",
Run: func(cmd *cobra.Command, args []string) {
err := standalone.Stop(stopAppID)
if err != nil {
print.FailureStatusEvent(os.Stdout, "failed to stop app id %s: %s", stopAppID, err)
} else {
print.SuccessStatusEvent(os.Stdout, "app stopped successfully")
}
},
}
func init() {
StopCmd.Flags().StringVarP(&stopAppID, "app-id", "", "", "app id to stop (standalone mode)")
RootCmd.AddCommand(StopCmd)
}

View File

@ -30,6 +30,7 @@ type RunData struct {
AppPort int AppPort int
Command string Command string
Created time.Time Created time.Time
PID int
} }
func AppendRunData(runData *RunData) error { func AppendRunData(runData *RunData) error {

View File

@ -13,6 +13,7 @@ type ListOutput struct {
Command string `csv:"COMMAND"` Command string `csv:"COMMAND"`
Age string `csv:"AGE"` Age string `csv:"AGE"`
Created string `csv:"CREATED"` Created string `csv:"CREATED"`
PID int
} }
func List() ([]ListOutput, error) { func List() ([]ListOutput, error) {
@ -30,6 +31,7 @@ func List() ([]ListOutput, error) {
ActionsPort: runtimeLine.ActionsPort, ActionsPort: runtimeLine.ActionsPort,
Command: utils.TruncateString(runtimeLine.Command, 20), Command: utils.TruncateString(runtimeLine.Command, 20),
Created: runtimeLine.Created.Format("2006-01-02 15:04.05"), Created: runtimeLine.Created.Format("2006-01-02 15:04.05"),
PID: runtimeLine.PID,
} }
if runtimeLine.AppPort > 0 { if runtimeLine.AppPort > 0 {
listRow.AppPort = runtimeLine.AppPort listRow.AppPort = runtimeLine.AppPort

28
pkg/standalone/stop.go Normal file
View File

@ -0,0 +1,28 @@
package standalone
import (
"fmt"
"runtime"
)
func Stop(appID string) error {
apps, err := List()
if err != nil {
return err
}
for _, a := range apps {
if a.AppID == appID {
pid := fmt.Sprintf("%v", a.PID)
if runtime.GOOS == "windows" {
err := runCmd("taskkill", "/F", "/PID", pid)
return err
} else {
err := runCmd("kill", pid)
return err
}
}
}
return fmt.Errorf("couldn't find app id %s", appID)
}