Add the system command with reboot subcommand
This commit is contained in:
@@ -36,7 +36,7 @@ func Execute() {
|
|||||||
|
|
||||||
cobra.OnInitialize(initConfig)
|
cobra.OnInitialize(initConfig)
|
||||||
rootCmd.SetUsageTemplate(rootUsage)
|
rootCmd.SetUsageTemplate(rootUsage)
|
||||||
rootCmd.AddCommand(runCmd, serviceCmd, fileCmd)
|
rootCmd.AddCommand(runCmd, serviceCmd, fileCmd, systemCmd)
|
||||||
|
|
||||||
home, err := homedir.Dir()
|
home, err := homedir.Dir()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
90
cmd/speedrun/cli/system.go
Normal file
90
cmd/speedrun/cli/system.go
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
package cli
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"crypto/tls"
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/alitto/pond"
|
||||||
|
"github.com/apex/log"
|
||||||
|
"github.com/dpogorzelski/speedrun/pkg/speedrun/cloud"
|
||||||
|
portalpb "github.com/dpogorzelski/speedrun/proto/portal"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/spf13/viper"
|
||||||
|
"storj.io/drpc/drpcconn"
|
||||||
|
)
|
||||||
|
|
||||||
|
var systemCmd = &cobra.Command{
|
||||||
|
Use: "system",
|
||||||
|
Short: "Manage the system",
|
||||||
|
TraverseChildren: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
var rebootCmd = &cobra.Command{
|
||||||
|
Use: "reboot",
|
||||||
|
Short: "Reboot the system",
|
||||||
|
Example: " speedrun system reboot",
|
||||||
|
Args: cobra.NoArgs,
|
||||||
|
RunE: reboot,
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
systemCmd.SetUsageTemplate(usage)
|
||||||
|
systemCmd.AddCommand(rebootCmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
func reboot(cmd *cobra.Command, _ []string) error {
|
||||||
|
usePrivateIP := viper.GetBool("portal.use-private-ip")
|
||||||
|
|
||||||
|
tlsConfig, err := cloud.SetupTLS()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
target, err := cmd.Flags().GetString("target")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
portals, err := cloud.GetInstances(target)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
pool := pond.New(1000, 10000)
|
||||||
|
for _, p := range portals {
|
||||||
|
portal := p
|
||||||
|
pool.Submit(func() {
|
||||||
|
fields := log.Fields{
|
||||||
|
"host": portal.Name,
|
||||||
|
"address": portal.GetAddress(usePrivateIP),
|
||||||
|
}
|
||||||
|
log := log.WithFields(fields)
|
||||||
|
|
||||||
|
addr := fmt.Sprintf("%s:%d", portal.GetAddress(usePrivateIP), 1337)
|
||||||
|
rawconn, err := tls.Dial("tcp", addr, tlsConfig)
|
||||||
|
if err != nil {
|
||||||
|
log.Error(err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
conn := drpcconn.New(rawconn)
|
||||||
|
defer conn.Close()
|
||||||
|
|
||||||
|
c := portalpb.NewDRPCPortalClient(conn)
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
r, err := c.SystemReboot(ctx, &portalpb.SystemRebootRequest{})
|
||||||
|
if err != nil {
|
||||||
|
log.Error(err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log.WithField("state", r.GetState()).Infof(r.GetMessage())
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
||||||
|
pool.StopAndWait()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -5,7 +5,7 @@ Usage:{{if .Runnable}}
|
|||||||
Core Commands:{{range .Commands}}{{if (or (eq .Name "help") (eq .Name "completion"))}}
|
Core Commands:{{range .Commands}}{{if (or (eq .Name "help") (eq .Name "completion"))}}
|
||||||
{{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}}
|
{{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}}
|
||||||
|
|
||||||
Action Commands:{{range .Commands}}{{if (or (eq .Name "run") (eq .Name "exec") (eq .Name "service") (eq .Name "file"))}}
|
Action Commands:{{range .Commands}}{{if (or (eq .Name "run") (eq .Name "exec") (eq .Name "service") (eq .Name "file") (eq .Name "system") )}}
|
||||||
{{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}}
|
{{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}}
|
||||||
{{if .HasAvailableLocalFlags}}
|
{{if .HasAvailableLocalFlags}}
|
||||||
Flags:
|
Flags:
|
||||||
|
|||||||
25
pkg/portal/system.go
Normal file
25
pkg/portal/system.go
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
//go:build linux && amd64
|
||||||
|
|
||||||
|
package portal
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"syscall"
|
||||||
|
|
||||||
|
"github.com/apex/log"
|
||||||
|
"github.com/dpogorzelski/speedrun/proto/portal"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (s *Server) SystemReboot(ctx context.Context, file *portal.SystemRebootRequest) (*portal.SystemRebootResponse, error) {
|
||||||
|
fields := log.Fields{
|
||||||
|
"context": "system",
|
||||||
|
"command": "reboot",
|
||||||
|
}
|
||||||
|
log := log.WithFields(fields)
|
||||||
|
log.Debug("Received system reboot request")
|
||||||
|
|
||||||
|
syscall.Sync()
|
||||||
|
go syscall.Reboot(syscall.LINUX_REBOOT_CMD_RESTART)
|
||||||
|
|
||||||
|
return &portal.SystemRebootResponse{State: portal.State_CHANGED, Message: "Rebooting"}, nil
|
||||||
|
}
|
||||||
@@ -555,6 +555,99 @@ func (x *FileReadResponse) GetContent() string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type SystemRebootRequest struct {
|
||||||
|
state protoimpl.MessageState
|
||||||
|
sizeCache protoimpl.SizeCache
|
||||||
|
unknownFields protoimpl.UnknownFields
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *SystemRebootRequest) Reset() {
|
||||||
|
*x = SystemRebootRequest{}
|
||||||
|
if protoimpl.UnsafeEnabled {
|
||||||
|
mi := &file_portal_portal_proto_msgTypes[9]
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *SystemRebootRequest) String() string {
|
||||||
|
return protoimpl.X.MessageStringOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*SystemRebootRequest) ProtoMessage() {}
|
||||||
|
|
||||||
|
func (x *SystemRebootRequest) ProtoReflect() protoreflect.Message {
|
||||||
|
mi := &file_portal_portal_proto_msgTypes[9]
|
||||||
|
if protoimpl.UnsafeEnabled && x != nil {
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
if ms.LoadMessageInfo() == nil {
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
return ms
|
||||||
|
}
|
||||||
|
return mi.MessageOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deprecated: Use SystemRebootRequest.ProtoReflect.Descriptor instead.
|
||||||
|
func (*SystemRebootRequest) Descriptor() ([]byte, []int) {
|
||||||
|
return file_portal_portal_proto_rawDescGZIP(), []int{9}
|
||||||
|
}
|
||||||
|
|
||||||
|
type SystemRebootResponse struct {
|
||||||
|
state protoimpl.MessageState
|
||||||
|
sizeCache protoimpl.SizeCache
|
||||||
|
unknownFields protoimpl.UnknownFields
|
||||||
|
|
||||||
|
State State `protobuf:"varint,1,opt,name=state,proto3,enum=portal.State" json:"state,omitempty"`
|
||||||
|
Message string `protobuf:"bytes,2,opt,name=message,proto3" json:"message,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *SystemRebootResponse) Reset() {
|
||||||
|
*x = SystemRebootResponse{}
|
||||||
|
if protoimpl.UnsafeEnabled {
|
||||||
|
mi := &file_portal_portal_proto_msgTypes[10]
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *SystemRebootResponse) String() string {
|
||||||
|
return protoimpl.X.MessageStringOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*SystemRebootResponse) ProtoMessage() {}
|
||||||
|
|
||||||
|
func (x *SystemRebootResponse) ProtoReflect() protoreflect.Message {
|
||||||
|
mi := &file_portal_portal_proto_msgTypes[10]
|
||||||
|
if protoimpl.UnsafeEnabled && x != nil {
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
if ms.LoadMessageInfo() == nil {
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
return ms
|
||||||
|
}
|
||||||
|
return mi.MessageOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deprecated: Use SystemRebootResponse.ProtoReflect.Descriptor instead.
|
||||||
|
func (*SystemRebootResponse) Descriptor() ([]byte, []int) {
|
||||||
|
return file_portal_portal_proto_rawDescGZIP(), []int{10}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *SystemRebootResponse) GetState() State {
|
||||||
|
if x != nil {
|
||||||
|
return x.State
|
||||||
|
}
|
||||||
|
return State_UNKNOWN
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *SystemRebootResponse) GetMessage() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Message
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
var File_portal_portal_proto protoreflect.FileDescriptor
|
var File_portal_portal_proto protoreflect.FileDescriptor
|
||||||
|
|
||||||
var file_portal_portal_proto_rawDesc = []byte{
|
var file_portal_portal_proto_rawDesc = []byte{
|
||||||
@@ -601,43 +694,55 @@ var file_portal_portal_proto_rawDesc = []byte{
|
|||||||
0x01, 0x28, 0x0e, 0x32, 0x0d, 0x2e, 0x70, 0x6f, 0x72, 0x74, 0x61, 0x6c, 0x2e, 0x53, 0x74, 0x61,
|
0x01, 0x28, 0x0e, 0x32, 0x0d, 0x2e, 0x70, 0x6f, 0x72, 0x74, 0x61, 0x6c, 0x2e, 0x53, 0x74, 0x61,
|
||||||
0x74, 0x65, 0x52, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x6e,
|
0x74, 0x65, 0x52, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x6e,
|
||||||
0x74, 0x65, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x63, 0x6f, 0x6e, 0x74,
|
0x74, 0x65, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x63, 0x6f, 0x6e, 0x74,
|
||||||
0x65, 0x6e, 0x74, 0x2a, 0x30, 0x0a, 0x05, 0x53, 0x74, 0x61, 0x74, 0x65, 0x12, 0x0b, 0x0a, 0x07,
|
0x65, 0x6e, 0x74, 0x22, 0x15, 0x0a, 0x13, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x52, 0x65, 0x62,
|
||||||
0x55, 0x4e, 0x4b, 0x4e, 0x4f, 0x57, 0x4e, 0x10, 0x00, 0x12, 0x0b, 0x0a, 0x07, 0x43, 0x48, 0x41,
|
0x6f, 0x6f, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x55, 0x0a, 0x14, 0x53, 0x79,
|
||||||
0x4e, 0x47, 0x45, 0x44, 0x10, 0x01, 0x12, 0x0d, 0x0a, 0x09, 0x55, 0x4e, 0x43, 0x48, 0x41, 0x4e,
|
0x73, 0x74, 0x65, 0x6d, 0x52, 0x65, 0x62, 0x6f, 0x6f, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e,
|
||||||
0x47, 0x45, 0x44, 0x10, 0x02, 0x32, 0xdf, 0x03, 0x0a, 0x06, 0x50, 0x6f, 0x72, 0x74, 0x61, 0x6c,
|
0x73, 0x65, 0x12, 0x23, 0x0a, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28,
|
||||||
0x12, 0x43, 0x0a, 0x0e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x52, 0x65, 0x73, 0x74, 0x61,
|
0x0e, 0x32, 0x0d, 0x2e, 0x70, 0x6f, 0x72, 0x74, 0x61, 0x6c, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x65,
|
||||||
0x72, 0x74, 0x12, 0x16, 0x2e, 0x70, 0x6f, 0x72, 0x74, 0x61, 0x6c, 0x2e, 0x53, 0x65, 0x72, 0x76,
|
0x52, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61,
|
||||||
0x69, 0x63, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x17, 0x2e, 0x70, 0x6f, 0x72,
|
0x67, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67,
|
||||||
0x74, 0x61, 0x6c, 0x2e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f,
|
0x65, 0x2a, 0x30, 0x0a, 0x05, 0x53, 0x74, 0x61, 0x74, 0x65, 0x12, 0x0b, 0x0a, 0x07, 0x55, 0x4e,
|
||||||
0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x41, 0x0a, 0x0c, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65,
|
0x4b, 0x4e, 0x4f, 0x57, 0x4e, 0x10, 0x00, 0x12, 0x0b, 0x0a, 0x07, 0x43, 0x48, 0x41, 0x4e, 0x47,
|
||||||
0x53, 0x74, 0x61, 0x72, 0x74, 0x12, 0x16, 0x2e, 0x70, 0x6f, 0x72, 0x74, 0x61, 0x6c, 0x2e, 0x53,
|
0x45, 0x44, 0x10, 0x01, 0x12, 0x0d, 0x0a, 0x09, 0x55, 0x4e, 0x43, 0x48, 0x41, 0x4e, 0x47, 0x45,
|
||||||
|
0x44, 0x10, 0x02, 0x32, 0xac, 0x04, 0x0a, 0x06, 0x50, 0x6f, 0x72, 0x74, 0x61, 0x6c, 0x12, 0x43,
|
||||||
|
0x0a, 0x0e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x52, 0x65, 0x73, 0x74, 0x61, 0x72, 0x74,
|
||||||
|
0x12, 0x16, 0x2e, 0x70, 0x6f, 0x72, 0x74, 0x61, 0x6c, 0x2e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63,
|
||||||
|
0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x17, 0x2e, 0x70, 0x6f, 0x72, 0x74, 0x61,
|
||||||
|
0x6c, 0x2e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73,
|
||||||
|
0x65, 0x22, 0x00, 0x12, 0x41, 0x0a, 0x0c, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x53, 0x74,
|
||||||
|
0x61, 0x72, 0x74, 0x12, 0x16, 0x2e, 0x70, 0x6f, 0x72, 0x74, 0x61, 0x6c, 0x2e, 0x53, 0x65, 0x72,
|
||||||
|
0x76, 0x69, 0x63, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x17, 0x2e, 0x70, 0x6f,
|
||||||
|
0x72, 0x74, 0x61, 0x6c, 0x2e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x52, 0x65, 0x73, 0x70,
|
||||||
|
0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x40, 0x0a, 0x0b, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63,
|
||||||
|
0x65, 0x53, 0x74, 0x6f, 0x70, 0x12, 0x16, 0x2e, 0x70, 0x6f, 0x72, 0x74, 0x61, 0x6c, 0x2e, 0x53,
|
||||||
0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x17, 0x2e,
|
0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x17, 0x2e,
|
||||||
0x70, 0x6f, 0x72, 0x74, 0x61, 0x6c, 0x2e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x52, 0x65,
|
0x70, 0x6f, 0x72, 0x74, 0x61, 0x6c, 0x2e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x52, 0x65,
|
||||||
0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x40, 0x0a, 0x0b, 0x53, 0x65, 0x72, 0x76,
|
0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x48, 0x0a, 0x0d, 0x53, 0x65, 0x72, 0x76,
|
||||||
0x69, 0x63, 0x65, 0x53, 0x74, 0x6f, 0x70, 0x12, 0x16, 0x2e, 0x70, 0x6f, 0x72, 0x74, 0x61, 0x6c,
|
0x69, 0x63, 0x65, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x16, 0x2e, 0x70, 0x6f, 0x72, 0x74,
|
||||||
0x2e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a,
|
0x61, 0x6c, 0x2e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73,
|
||||||
0x17, 0x2e, 0x70, 0x6f, 0x72, 0x74, 0x61, 0x6c, 0x2e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65,
|
0x74, 0x1a, 0x1d, 0x2e, 0x70, 0x6f, 0x72, 0x74, 0x61, 0x6c, 0x2e, 0x53, 0x65, 0x72, 0x76, 0x69,
|
||||||
0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x48, 0x0a, 0x0d, 0x53, 0x65,
|
0x63, 0x65, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65,
|
||||||
0x72, 0x76, 0x69, 0x63, 0x65, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x16, 0x2e, 0x70, 0x6f,
|
0x22, 0x00, 0x12, 0x3f, 0x0a, 0x0a, 0x52, 0x75, 0x6e, 0x43, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64,
|
||||||
0x72, 0x74, 0x61, 0x6c, 0x2e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x52, 0x65, 0x71, 0x75,
|
0x12, 0x16, 0x2e, 0x70, 0x6f, 0x72, 0x74, 0x61, 0x6c, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x61, 0x6e,
|
||||||
0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x70, 0x6f, 0x72, 0x74, 0x61, 0x6c, 0x2e, 0x53, 0x65, 0x72,
|
0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x17, 0x2e, 0x70, 0x6f, 0x72, 0x74, 0x61,
|
||||||
0x76, 0x69, 0x63, 0x65, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e,
|
0x6c, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73,
|
||||||
0x73, 0x65, 0x22, 0x00, 0x12, 0x3f, 0x0a, 0x0a, 0x52, 0x75, 0x6e, 0x43, 0x6f, 0x6d, 0x6d, 0x61,
|
0x65, 0x22, 0x00, 0x12, 0x3f, 0x0a, 0x08, 0x43, 0x50, 0x55, 0x75, 0x73, 0x61, 0x67, 0x65, 0x12,
|
||||||
0x6e, 0x64, 0x12, 0x16, 0x2e, 0x70, 0x6f, 0x72, 0x74, 0x61, 0x6c, 0x2e, 0x43, 0x6f, 0x6d, 0x6d,
|
0x17, 0x2e, 0x70, 0x6f, 0x72, 0x74, 0x61, 0x6c, 0x2e, 0x43, 0x50, 0x55, 0x75, 0x73, 0x61, 0x67,
|
||||||
0x61, 0x6e, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x17, 0x2e, 0x70, 0x6f, 0x72,
|
0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x18, 0x2e, 0x70, 0x6f, 0x72, 0x74, 0x61,
|
||||||
0x74, 0x61, 0x6c, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f,
|
0x6c, 0x2e, 0x43, 0x50, 0x55, 0x75, 0x73, 0x61, 0x67, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e,
|
||||||
0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x3f, 0x0a, 0x08, 0x43, 0x50, 0x55, 0x75, 0x73, 0x61, 0x67,
|
0x73, 0x65, 0x22, 0x00, 0x12, 0x3f, 0x0a, 0x08, 0x46, 0x69, 0x6c, 0x65, 0x52, 0x65, 0x61, 0x64,
|
||||||
0x65, 0x12, 0x17, 0x2e, 0x70, 0x6f, 0x72, 0x74, 0x61, 0x6c, 0x2e, 0x43, 0x50, 0x55, 0x75, 0x73,
|
0x12, 0x17, 0x2e, 0x70, 0x6f, 0x72, 0x74, 0x61, 0x6c, 0x2e, 0x46, 0x69, 0x6c, 0x65, 0x52, 0x65,
|
||||||
0x61, 0x67, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x18, 0x2e, 0x70, 0x6f, 0x72,
|
0x61, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x18, 0x2e, 0x70, 0x6f, 0x72, 0x74,
|
||||||
0x74, 0x61, 0x6c, 0x2e, 0x43, 0x50, 0x55, 0x75, 0x73, 0x61, 0x67, 0x65, 0x52, 0x65, 0x73, 0x70,
|
0x61, 0x6c, 0x2e, 0x46, 0x69, 0x6c, 0x65, 0x52, 0x65, 0x61, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f,
|
||||||
0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x3f, 0x0a, 0x08, 0x46, 0x69, 0x6c, 0x65, 0x52, 0x65,
|
0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x4b, 0x0a, 0x0c, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x52,
|
||||||
0x61, 0x64, 0x12, 0x17, 0x2e, 0x70, 0x6f, 0x72, 0x74, 0x61, 0x6c, 0x2e, 0x46, 0x69, 0x6c, 0x65,
|
0x65, 0x62, 0x6f, 0x6f, 0x74, 0x12, 0x1b, 0x2e, 0x70, 0x6f, 0x72, 0x74, 0x61, 0x6c, 0x2e, 0x53,
|
||||||
0x52, 0x65, 0x61, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x18, 0x2e, 0x70, 0x6f,
|
0x79, 0x73, 0x74, 0x65, 0x6d, 0x52, 0x65, 0x62, 0x6f, 0x6f, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65,
|
||||||
0x72, 0x74, 0x61, 0x6c, 0x2e, 0x46, 0x69, 0x6c, 0x65, 0x52, 0x65, 0x61, 0x64, 0x52, 0x65, 0x73,
|
0x73, 0x74, 0x1a, 0x1c, 0x2e, 0x70, 0x6f, 0x72, 0x74, 0x61, 0x6c, 0x2e, 0x53, 0x79, 0x73, 0x74,
|
||||||
0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x2f, 0x5a, 0x2d, 0x67, 0x69, 0x74, 0x68, 0x75,
|
0x65, 0x6d, 0x52, 0x65, 0x62, 0x6f, 0x6f, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65,
|
||||||
0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x64, 0x70, 0x6f, 0x67, 0x6f, 0x72, 0x7a, 0x65, 0x6c, 0x73,
|
0x22, 0x00, 0x42, 0x2f, 0x5a, 0x2d, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d,
|
||||||
0x6b, 0x69, 0x2f, 0x73, 0x70, 0x65, 0x65, 0x64, 0x72, 0x75, 0x6e, 0x2f, 0x70, 0x72, 0x6f, 0x74,
|
0x2f, 0x64, 0x70, 0x6f, 0x67, 0x6f, 0x72, 0x7a, 0x65, 0x6c, 0x73, 0x6b, 0x69, 0x2f, 0x73, 0x70,
|
||||||
0x6f, 0x2f, 0x70, 0x6f, 0x72, 0x74, 0x61, 0x6c, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
0x65, 0x65, 0x64, 0x72, 0x75, 0x6e, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x70, 0x6f, 0x72,
|
||||||
|
0x74, 0x61, 0x6c, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -653,7 +758,7 @@ func file_portal_portal_proto_rawDescGZIP() []byte {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var file_portal_portal_proto_enumTypes = make([]protoimpl.EnumInfo, 1)
|
var file_portal_portal_proto_enumTypes = make([]protoimpl.EnumInfo, 1)
|
||||||
var file_portal_portal_proto_msgTypes = make([]protoimpl.MessageInfo, 9)
|
var file_portal_portal_proto_msgTypes = make([]protoimpl.MessageInfo, 11)
|
||||||
var file_portal_portal_proto_goTypes = []interface{}{
|
var file_portal_portal_proto_goTypes = []interface{}{
|
||||||
(State)(0), // 0: portal.State
|
(State)(0), // 0: portal.State
|
||||||
(*CommandRequest)(nil), // 1: portal.CommandRequest
|
(*CommandRequest)(nil), // 1: portal.CommandRequest
|
||||||
@@ -665,31 +770,36 @@ var file_portal_portal_proto_goTypes = []interface{}{
|
|||||||
(*CPUusageResponse)(nil), // 7: portal.CPUusageResponse
|
(*CPUusageResponse)(nil), // 7: portal.CPUusageResponse
|
||||||
(*FileReadRequest)(nil), // 8: portal.FileReadRequest
|
(*FileReadRequest)(nil), // 8: portal.FileReadRequest
|
||||||
(*FileReadResponse)(nil), // 9: portal.FileReadResponse
|
(*FileReadResponse)(nil), // 9: portal.FileReadResponse
|
||||||
|
(*SystemRebootRequest)(nil), // 10: portal.SystemRebootRequest
|
||||||
|
(*SystemRebootResponse)(nil), // 11: portal.SystemRebootResponse
|
||||||
}
|
}
|
||||||
var file_portal_portal_proto_depIdxs = []int32{
|
var file_portal_portal_proto_depIdxs = []int32{
|
||||||
0, // 0: portal.CommandResponse.state:type_name -> portal.State
|
0, // 0: portal.CommandResponse.state:type_name -> portal.State
|
||||||
0, // 1: portal.ServiceResponse.state:type_name -> portal.State
|
0, // 1: portal.ServiceResponse.state:type_name -> portal.State
|
||||||
0, // 2: portal.ServiceStatusResponse.state:type_name -> portal.State
|
0, // 2: portal.ServiceStatusResponse.state:type_name -> portal.State
|
||||||
0, // 3: portal.FileReadResponse.state:type_name -> portal.State
|
0, // 3: portal.FileReadResponse.state:type_name -> portal.State
|
||||||
3, // 4: portal.Portal.ServiceRestart:input_type -> portal.ServiceRequest
|
0, // 4: portal.SystemRebootResponse.state:type_name -> portal.State
|
||||||
3, // 5: portal.Portal.ServiceStart:input_type -> portal.ServiceRequest
|
3, // 5: portal.Portal.ServiceRestart:input_type -> portal.ServiceRequest
|
||||||
3, // 6: portal.Portal.ServiceStop:input_type -> portal.ServiceRequest
|
3, // 6: portal.Portal.ServiceStart:input_type -> portal.ServiceRequest
|
||||||
3, // 7: portal.Portal.ServiceStatus:input_type -> portal.ServiceRequest
|
3, // 7: portal.Portal.ServiceStop:input_type -> portal.ServiceRequest
|
||||||
1, // 8: portal.Portal.RunCommand:input_type -> portal.CommandRequest
|
3, // 8: portal.Portal.ServiceStatus:input_type -> portal.ServiceRequest
|
||||||
6, // 9: portal.Portal.CPUusage:input_type -> portal.CPUusageRequest
|
1, // 9: portal.Portal.RunCommand:input_type -> portal.CommandRequest
|
||||||
8, // 10: portal.Portal.FileRead:input_type -> portal.FileReadRequest
|
6, // 10: portal.Portal.CPUusage:input_type -> portal.CPUusageRequest
|
||||||
4, // 11: portal.Portal.ServiceRestart:output_type -> portal.ServiceResponse
|
8, // 11: portal.Portal.FileRead:input_type -> portal.FileReadRequest
|
||||||
4, // 12: portal.Portal.ServiceStart:output_type -> portal.ServiceResponse
|
10, // 12: portal.Portal.SystemReboot:input_type -> portal.SystemRebootRequest
|
||||||
4, // 13: portal.Portal.ServiceStop:output_type -> portal.ServiceResponse
|
4, // 13: portal.Portal.ServiceRestart:output_type -> portal.ServiceResponse
|
||||||
5, // 14: portal.Portal.ServiceStatus:output_type -> portal.ServiceStatusResponse
|
4, // 14: portal.Portal.ServiceStart:output_type -> portal.ServiceResponse
|
||||||
2, // 15: portal.Portal.RunCommand:output_type -> portal.CommandResponse
|
4, // 15: portal.Portal.ServiceStop:output_type -> portal.ServiceResponse
|
||||||
7, // 16: portal.Portal.CPUusage:output_type -> portal.CPUusageResponse
|
5, // 16: portal.Portal.ServiceStatus:output_type -> portal.ServiceStatusResponse
|
||||||
9, // 17: portal.Portal.FileRead:output_type -> portal.FileReadResponse
|
2, // 17: portal.Portal.RunCommand:output_type -> portal.CommandResponse
|
||||||
11, // [11:18] is the sub-list for method output_type
|
7, // 18: portal.Portal.CPUusage:output_type -> portal.CPUusageResponse
|
||||||
4, // [4:11] is the sub-list for method input_type
|
9, // 19: portal.Portal.FileRead:output_type -> portal.FileReadResponse
|
||||||
4, // [4:4] is the sub-list for extension type_name
|
11, // 20: portal.Portal.SystemReboot:output_type -> portal.SystemRebootResponse
|
||||||
4, // [4:4] is the sub-list for extension extendee
|
13, // [13:21] is the sub-list for method output_type
|
||||||
0, // [0:4] is the sub-list for field type_name
|
5, // [5:13] is the sub-list for method input_type
|
||||||
|
5, // [5:5] is the sub-list for extension type_name
|
||||||
|
5, // [5:5] is the sub-list for extension extendee
|
||||||
|
0, // [0:5] is the sub-list for field type_name
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() { file_portal_portal_proto_init() }
|
func init() { file_portal_portal_proto_init() }
|
||||||
@@ -806,6 +916,30 @@ func file_portal_portal_proto_init() {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
file_portal_portal_proto_msgTypes[9].Exporter = func(v interface{}, i int) interface{} {
|
||||||
|
switch v := v.(*SystemRebootRequest); i {
|
||||||
|
case 0:
|
||||||
|
return &v.state
|
||||||
|
case 1:
|
||||||
|
return &v.sizeCache
|
||||||
|
case 2:
|
||||||
|
return &v.unknownFields
|
||||||
|
default:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
file_portal_portal_proto_msgTypes[10].Exporter = func(v interface{}, i int) interface{} {
|
||||||
|
switch v := v.(*SystemRebootResponse); i {
|
||||||
|
case 0:
|
||||||
|
return &v.state
|
||||||
|
case 1:
|
||||||
|
return &v.sizeCache
|
||||||
|
case 2:
|
||||||
|
return &v.unknownFields
|
||||||
|
default:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
type x struct{}
|
type x struct{}
|
||||||
out := protoimpl.TypeBuilder{
|
out := protoimpl.TypeBuilder{
|
||||||
@@ -813,7 +947,7 @@ func file_portal_portal_proto_init() {
|
|||||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||||
RawDescriptor: file_portal_portal_proto_rawDesc,
|
RawDescriptor: file_portal_portal_proto_rawDesc,
|
||||||
NumEnums: 1,
|
NumEnums: 1,
|
||||||
NumMessages: 9,
|
NumMessages: 11,
|
||||||
NumExtensions: 0,
|
NumExtensions: 0,
|
||||||
NumServices: 1,
|
NumServices: 1,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -51,6 +51,13 @@ message FileReadResponse {
|
|||||||
string content = 2;
|
string content = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message SystemRebootRequest {}
|
||||||
|
|
||||||
|
message SystemRebootResponse {
|
||||||
|
State state = 1;
|
||||||
|
string message = 2;
|
||||||
|
}
|
||||||
|
|
||||||
service Portal {
|
service Portal {
|
||||||
rpc ServiceRestart(ServiceRequest) returns (ServiceResponse) {}
|
rpc ServiceRestart(ServiceRequest) returns (ServiceResponse) {}
|
||||||
rpc ServiceStart(ServiceRequest) returns (ServiceResponse) {}
|
rpc ServiceStart(ServiceRequest) returns (ServiceResponse) {}
|
||||||
@@ -59,6 +66,7 @@ service Portal {
|
|||||||
rpc RunCommand(CommandRequest) returns (CommandResponse) {}
|
rpc RunCommand(CommandRequest) returns (CommandResponse) {}
|
||||||
rpc CPUusage(CPUusageRequest) returns (CPUusageResponse) {}
|
rpc CPUusage(CPUusageRequest) returns (CPUusageResponse) {}
|
||||||
rpc FileRead(FileReadRequest) returns (FileReadResponse) {}
|
rpc FileRead(FileReadRequest) returns (FileReadResponse) {}
|
||||||
|
rpc SystemReboot(SystemRebootRequest) returns (SystemRebootResponse) {}
|
||||||
// --target group1 --target group2
|
// --target group1 --target group2
|
||||||
// rpc CPUProfile(CPUProfileRequest) returns (CPUProfileResponse) {}
|
// rpc CPUProfile(CPUProfileRequest) returns (CPUProfileResponse) {}
|
||||||
// rpc MemProfile(MemProfileRequest) returns (MemProfileResponse) {}
|
// rpc MemProfile(MemProfileRequest) returns (MemProfileResponse) {}
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ type DRPCPortalClient interface {
|
|||||||
RunCommand(ctx context.Context, in *CommandRequest) (*CommandResponse, error)
|
RunCommand(ctx context.Context, in *CommandRequest) (*CommandResponse, error)
|
||||||
CPUusage(ctx context.Context, in *CPUusageRequest) (*CPUusageResponse, error)
|
CPUusage(ctx context.Context, in *CPUusageRequest) (*CPUusageResponse, error)
|
||||||
FileRead(ctx context.Context, in *FileReadRequest) (*FileReadResponse, error)
|
FileRead(ctx context.Context, in *FileReadRequest) (*FileReadResponse, error)
|
||||||
|
SystemReboot(ctx context.Context, in *SystemRebootRequest) (*SystemRebootResponse, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type drpcPortalClient struct {
|
type drpcPortalClient struct {
|
||||||
@@ -120,6 +121,15 @@ func (c *drpcPortalClient) FileRead(ctx context.Context, in *FileReadRequest) (*
|
|||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *drpcPortalClient) SystemReboot(ctx context.Context, in *SystemRebootRequest) (*SystemRebootResponse, error) {
|
||||||
|
out := new(SystemRebootResponse)
|
||||||
|
err := c.cc.Invoke(ctx, "/portal.Portal/SystemReboot", drpcEncoding_File_portal_portal_proto{}, in, out)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
type DRPCPortalServer interface {
|
type DRPCPortalServer interface {
|
||||||
ServiceRestart(context.Context, *ServiceRequest) (*ServiceResponse, error)
|
ServiceRestart(context.Context, *ServiceRequest) (*ServiceResponse, error)
|
||||||
ServiceStart(context.Context, *ServiceRequest) (*ServiceResponse, error)
|
ServiceStart(context.Context, *ServiceRequest) (*ServiceResponse, error)
|
||||||
@@ -128,6 +138,7 @@ type DRPCPortalServer interface {
|
|||||||
RunCommand(context.Context, *CommandRequest) (*CommandResponse, error)
|
RunCommand(context.Context, *CommandRequest) (*CommandResponse, error)
|
||||||
CPUusage(context.Context, *CPUusageRequest) (*CPUusageResponse, error)
|
CPUusage(context.Context, *CPUusageRequest) (*CPUusageResponse, error)
|
||||||
FileRead(context.Context, *FileReadRequest) (*FileReadResponse, error)
|
FileRead(context.Context, *FileReadRequest) (*FileReadResponse, error)
|
||||||
|
SystemReboot(context.Context, *SystemRebootRequest) (*SystemRebootResponse, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type DRPCPortalUnimplementedServer struct{}
|
type DRPCPortalUnimplementedServer struct{}
|
||||||
@@ -160,9 +171,13 @@ func (s *DRPCPortalUnimplementedServer) FileRead(context.Context, *FileReadReque
|
|||||||
return nil, drpcerr.WithCode(errors.New("Unimplemented"), drpcerr.Unimplemented)
|
return nil, drpcerr.WithCode(errors.New("Unimplemented"), drpcerr.Unimplemented)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *DRPCPortalUnimplementedServer) SystemReboot(context.Context, *SystemRebootRequest) (*SystemRebootResponse, error) {
|
||||||
|
return nil, drpcerr.WithCode(errors.New("Unimplemented"), drpcerr.Unimplemented)
|
||||||
|
}
|
||||||
|
|
||||||
type DRPCPortalDescription struct{}
|
type DRPCPortalDescription struct{}
|
||||||
|
|
||||||
func (DRPCPortalDescription) NumMethods() int { return 7 }
|
func (DRPCPortalDescription) NumMethods() int { return 8 }
|
||||||
|
|
||||||
func (DRPCPortalDescription) Method(n int) (string, drpc.Encoding, drpc.Receiver, interface{}, bool) {
|
func (DRPCPortalDescription) Method(n int) (string, drpc.Encoding, drpc.Receiver, interface{}, bool) {
|
||||||
switch n {
|
switch n {
|
||||||
@@ -229,6 +244,15 @@ func (DRPCPortalDescription) Method(n int) (string, drpc.Encoding, drpc.Receiver
|
|||||||
in1.(*FileReadRequest),
|
in1.(*FileReadRequest),
|
||||||
)
|
)
|
||||||
}, DRPCPortalServer.FileRead, true
|
}, DRPCPortalServer.FileRead, true
|
||||||
|
case 7:
|
||||||
|
return "/portal.Portal/SystemReboot", drpcEncoding_File_portal_portal_proto{},
|
||||||
|
func(srv interface{}, ctx context.Context, in1, in2 interface{}) (drpc.Message, error) {
|
||||||
|
return srv.(DRPCPortalServer).
|
||||||
|
SystemReboot(
|
||||||
|
ctx,
|
||||||
|
in1.(*SystemRebootRequest),
|
||||||
|
)
|
||||||
|
}, DRPCPortalServer.SystemReboot, true
|
||||||
default:
|
default:
|
||||||
return "", nil, nil, nil, false
|
return "", nil, nil, nil, false
|
||||||
}
|
}
|
||||||
@@ -349,3 +373,19 @@ func (x *drpcPortal_FileReadStream) SendAndClose(m *FileReadResponse) error {
|
|||||||
}
|
}
|
||||||
return x.CloseSend()
|
return x.CloseSend()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type DRPCPortal_SystemRebootStream interface {
|
||||||
|
drpc.Stream
|
||||||
|
SendAndClose(*SystemRebootResponse) error
|
||||||
|
}
|
||||||
|
|
||||||
|
type drpcPortal_SystemRebootStream struct {
|
||||||
|
drpc.Stream
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *drpcPortal_SystemRebootStream) SendAndClose(m *SystemRebootResponse) error {
|
||||||
|
if err := x.MsgSend(m, drpcEncoding_File_portal_portal_proto{}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return x.CloseSend()
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user