talos/cmd/osctl/cmd/dmesg.go
Andrey Smirnov ca95469247
feat(osctl): handle ^C by aborting context (#693)
This provides a bit better handling for the handing grpc
requests (or just slow requests):

```
$ osctl-linux-amd64 --talosconfig talosconfig version
Client:
	Tag:         ad410fb-dirty
	SHA:         ad410fb-dirty
	Built:
	Go version:  go1.12.5
	OS/Arch:     linux/amd64

^CSignal received, aborting, press Ctrl+C once again to abort immediately...
error getting version: rpc error: code = Canceled desc = context canceled
```

For now we catch `SIGINT` & `SIGTERM`. Second signal kills process
immediately as signal handler is removed.

Signed-off-by: Andrey Smirnov <smirnov.andrey@gmail.com>
2019-05-30 00:11:58 +03:00

42 lines
978 B
Go

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package cmd
import (
"os"
"github.com/spf13/cobra"
"github.com/talos-systems/talos/cmd/osctl/pkg/client"
"github.com/talos-systems/talos/cmd/osctl/pkg/helpers"
)
// dmesgCmd represents the dmesg command
var dmesgCmd = &cobra.Command{
Use: "dmesg",
Short: "Retrieve kernel logs",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 0 {
helpers.Should(cmd.Usage())
os.Exit(1)
}
setupClient(func(c *client.Client) {
msg, err := c.Dmesg(globalCtx)
if err != nil {
helpers.Fatalf("error getting dmesg: %s", err)
}
_, err = os.Stdout.Write(msg)
helpers.Should(err)
})
},
}
func init() {
dmesgCmd.Flags().StringVarP(&target, "target", "t", "", "target the specificed node")
rootCmd.AddCommand(dmesgCmd)
}