Fix race during daemon restart

Signed-off-by: Steffen Vogel <post@steffenvogel.de>
This commit is contained in:
Steffen Vogel
2023-07-06 08:36:59 +02:00
parent 612fb806b3
commit a7a7b6aa9d
8 changed files with 181 additions and 154 deletions

View File

@@ -9,7 +9,7 @@ import (
"github.com/spf13/cobra"
"github.com/stv0g/cunicu/pkg/proto"
"github.com/stv0g/cunicu/pkg/proto/rpc"
)
func init() { //nolint:gochecknoinits
@@ -24,7 +24,9 @@ func init() { //nolint:gochecknoinits
}
func restart(_ *cobra.Command, _ []string) error {
if _, err := rpcClient.DaemonClient.Restart(context.Background(), &proto.Empty{}); err != nil {
if _, err := rpcClient.DaemonClient.Shutdown(context.Background(), &rpc.ShutdownParams{
Restart: true,
}); err != nil {
return fmt.Errorf("failed RPC request: %w", err)
}

View File

@@ -9,7 +9,7 @@ import (
"github.com/spf13/cobra"
"github.com/stv0g/cunicu/pkg/proto"
"github.com/stv0g/cunicu/pkg/proto/rpc"
)
func init() { //nolint:gochecknoinits
@@ -24,7 +24,9 @@ func init() { //nolint:gochecknoinits
}
func stop(_ *cobra.Command, _ []string) error {
if _, err := rpcClient.Stop(context.Background(), &proto.Empty{}); err != nil {
if _, err := rpcClient.Shutdown(context.Background(), &rpc.ShutdownParams{
Restart: false,
}); err != nil {
return fmt.Errorf("failed RPC request: %w", err)
}

View File

@@ -122,15 +122,20 @@ out:
}
// Stop stops the daemon
func (d *Daemon) Stop() {
close(d.stop)
d.logger.Debug("Stopping daemon")
}
func (d *Daemon) Shutdown(restart bool) {
if d.stop == nil {
return
}
func (d *Daemon) Restart() {
d.reexecOnClose = true
close(d.stop)
d.logger.Debug("Restarting daemon")
d.stop = nil
if restart {
d.reexecOnClose = true
d.logger.Debug("Restarting daemon")
} else {
d.logger.Debug("Stopping daemon")
}
}
func (d *Daemon) Sync() error {
@@ -173,7 +178,6 @@ func (d *Daemon) Close() error {
}
if d.reexecOnClose {
d.logger.Debug("Restarting daemon")
return osx.ReexecSelf()
}

View File

@@ -386,6 +386,53 @@ func (x *AddPeerResp) GetInterface() *core.Interface {
return nil
}
type ShutdownParams struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Restart bool `protobuf:"varint,1,opt,name=restart,proto3" json:"restart,omitempty"`
}
func (x *ShutdownParams) Reset() {
*x = ShutdownParams{}
if protoimpl.UnsafeEnabled {
mi := &file_rpc_daemon_proto_msgTypes[7]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *ShutdownParams) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*ShutdownParams) ProtoMessage() {}
func (x *ShutdownParams) ProtoReflect() protoreflect.Message {
mi := &file_rpc_daemon_proto_msgTypes[7]
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 ShutdownParams.ProtoReflect.Descriptor instead.
func (*ShutdownParams) Descriptor() ([]byte, []int) {
return file_rpc_daemon_proto_rawDescGZIP(), []int{7}
}
func (x *ShutdownParams) GetRestart() bool {
if x != nil {
return x.Restart
}
return false
}
var File_rpc_daemon_proto protoreflect.FileDescriptor
var file_rpc_daemon_proto_rawDesc = []byte{
@@ -440,47 +487,48 @@ var file_rpc_daemon_proto_rawDesc = []byte{
0x0a, 0x09, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28,
0x0b, 0x32, 0x16, 0x2e, 0x63, 0x75, 0x6e, 0x69, 0x63, 0x75, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e,
0x49, 0x6e, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x52, 0x09, 0x69, 0x6e, 0x74, 0x65, 0x72,
0x66, 0x61, 0x63, 0x65, 0x32, 0xd1, 0x04, 0x0a, 0x06, 0x44, 0x61, 0x65, 0x6d, 0x6f, 0x6e, 0x12,
0x32, 0x0a, 0x0c, 0x47, 0x65, 0x74, 0x42, 0x75, 0x69, 0x6c, 0x64, 0x49, 0x6e, 0x66, 0x6f, 0x12,
0x66, 0x61, 0x63, 0x65, 0x22, 0x2a, 0x0a, 0x0e, 0x53, 0x68, 0x75, 0x74, 0x64, 0x6f, 0x77, 0x6e,
0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x12, 0x18, 0x0a, 0x07, 0x72, 0x65, 0x73, 0x74, 0x61, 0x72,
0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x72, 0x65, 0x73, 0x74, 0x61, 0x72, 0x74,
0x32, 0xb7, 0x04, 0x0a, 0x06, 0x44, 0x61, 0x65, 0x6d, 0x6f, 0x6e, 0x12, 0x32, 0x0a, 0x0c, 0x47,
0x65, 0x74, 0x42, 0x75, 0x69, 0x6c, 0x64, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x0d, 0x2e, 0x63, 0x75,
0x6e, 0x69, 0x63, 0x75, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x11, 0x2e, 0x63, 0x75, 0x6e,
0x69, 0x63, 0x75, 0x2e, 0x42, 0x75, 0x69, 0x6c, 0x64, 0x49, 0x6e, 0x66, 0x6f, 0x22, 0x00, 0x12,
0x34, 0x0a, 0x0c, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x12,
0x0d, 0x2e, 0x63, 0x75, 0x6e, 0x69, 0x63, 0x75, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x11,
0x2e, 0x63, 0x75, 0x6e, 0x69, 0x63, 0x75, 0x2e, 0x42, 0x75, 0x69, 0x6c, 0x64, 0x49, 0x6e, 0x66,
0x6f, 0x22, 0x00, 0x12, 0x34, 0x0a, 0x0c, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x45, 0x76, 0x65,
0x6e, 0x74, 0x73, 0x12, 0x0d, 0x2e, 0x63, 0x75, 0x6e, 0x69, 0x63, 0x75, 0x2e, 0x45, 0x6d, 0x70,
0x74, 0x79, 0x1a, 0x11, 0x2e, 0x63, 0x75, 0x6e, 0x69, 0x63, 0x75, 0x2e, 0x72, 0x70, 0x63, 0x2e,
0x45, 0x76, 0x65, 0x6e, 0x74, 0x22, 0x00, 0x30, 0x01, 0x12, 0x28, 0x0a, 0x06, 0x55, 0x6e, 0x57,
0x61, 0x69, 0x74, 0x12, 0x0d, 0x2e, 0x63, 0x75, 0x6e, 0x69, 0x63, 0x75, 0x2e, 0x45, 0x6d, 0x70,
0x74, 0x79, 0x1a, 0x0d, 0x2e, 0x63, 0x75, 0x6e, 0x69, 0x63, 0x75, 0x2e, 0x45, 0x6d, 0x70, 0x74,
0x79, 0x22, 0x00, 0x12, 0x26, 0x0a, 0x04, 0x53, 0x74, 0x6f, 0x70, 0x12, 0x0d, 0x2e, 0x63, 0x75,
0x6e, 0x69, 0x63, 0x75, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x0d, 0x2e, 0x63, 0x75, 0x6e,
0x69, 0x63, 0x75, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x00, 0x12, 0x29, 0x0a, 0x07, 0x52,
0x65, 0x73, 0x74, 0x61, 0x72, 0x74, 0x12, 0x0d, 0x2e, 0x63, 0x75, 0x6e, 0x69, 0x63, 0x75, 0x2e,
0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x0d, 0x2e, 0x63, 0x75, 0x6e, 0x69, 0x63, 0x75, 0x2e, 0x45,
0x6d, 0x70, 0x74, 0x79, 0x22, 0x00, 0x12, 0x26, 0x0a, 0x04, 0x53, 0x79, 0x6e, 0x63, 0x12, 0x0d,
0x2e, 0x63, 0x75, 0x6e, 0x69, 0x63, 0x75, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x0d, 0x2e,
0x63, 0x75, 0x6e, 0x69, 0x63, 0x75, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x00, 0x12, 0x45,
0x0a, 0x09, 0x47, 0x65, 0x74, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x1b, 0x2e, 0x63, 0x75,
0x6e, 0x69, 0x63, 0x75, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x53, 0x74, 0x61, 0x74,
0x75, 0x73, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x1a, 0x19, 0x2e, 0x63, 0x75, 0x6e, 0x69, 0x63,
0x75, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52,
0x65, 0x73, 0x70, 0x22, 0x00, 0x12, 0x39, 0x0a, 0x09, 0x53, 0x65, 0x74, 0x43, 0x6f, 0x6e, 0x66,
0x69, 0x67, 0x12, 0x1b, 0x2e, 0x63, 0x75, 0x6e, 0x69, 0x63, 0x75, 0x2e, 0x72, 0x70, 0x63, 0x2e,
0x53, 0x65, 0x74, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x1a,
0x2e, 0x63, 0x75, 0x6e, 0x69, 0x63, 0x75, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x45, 0x76, 0x65, 0x6e,
0x74, 0x22, 0x00, 0x30, 0x01, 0x12, 0x28, 0x0a, 0x06, 0x55, 0x6e, 0x57, 0x61, 0x69, 0x74, 0x12,
0x0d, 0x2e, 0x63, 0x75, 0x6e, 0x69, 0x63, 0x75, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x0d,
0x2e, 0x63, 0x75, 0x6e, 0x69, 0x63, 0x75, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x00, 0x12,
0x37, 0x0a, 0x08, 0x53, 0x68, 0x75, 0x74, 0x64, 0x6f, 0x77, 0x6e, 0x12, 0x1a, 0x2e, 0x63, 0x75,
0x6e, 0x69, 0x63, 0x75, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x53, 0x68, 0x75, 0x74, 0x64, 0x6f, 0x77,
0x6e, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x1a, 0x0d, 0x2e, 0x63, 0x75, 0x6e, 0x69, 0x63, 0x75,
0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x00, 0x12, 0x26, 0x0a, 0x04, 0x53, 0x79, 0x6e, 0x63,
0x12, 0x0d, 0x2e, 0x63, 0x75, 0x6e, 0x69, 0x63, 0x75, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a,
0x0d, 0x2e, 0x63, 0x75, 0x6e, 0x69, 0x63, 0x75, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x00,
0x12, 0x45, 0x0a, 0x09, 0x47, 0x65, 0x74, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x1b, 0x2e,
0x63, 0x75, 0x6e, 0x69, 0x63, 0x75, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x43, 0x6f,
0x6e, 0x66, 0x69, 0x67, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x1a, 0x19, 0x2e, 0x63, 0x75, 0x6e,
0x69, 0x63, 0x75, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x43, 0x6f, 0x6e, 0x66, 0x69,
0x67, 0x52, 0x65, 0x73, 0x70, 0x22, 0x00, 0x12, 0x2e, 0x0a, 0x0c, 0x52, 0x65, 0x6c, 0x6f, 0x61,
0x64, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x0d, 0x2e, 0x63, 0x75, 0x6e, 0x69, 0x63, 0x75,
0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x0d, 0x2e, 0x63, 0x75, 0x6e, 0x69, 0x63, 0x75, 0x2e,
0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x00, 0x12, 0x3f, 0x0a, 0x07, 0x41, 0x64, 0x64, 0x50, 0x65,
0x65, 0x72, 0x12, 0x19, 0x2e, 0x63, 0x75, 0x6e, 0x69, 0x63, 0x75, 0x2e, 0x72, 0x70, 0x63, 0x2e,
0x41, 0x64, 0x64, 0x50, 0x65, 0x65, 0x72, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x1a, 0x17, 0x2e,
0x63, 0x75, 0x6e, 0x69, 0x63, 0x75, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x41, 0x64, 0x64, 0x50, 0x65,
0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x22, 0x00, 0x42, 0x27, 0x5a, 0x25, 0x67, 0x69, 0x74, 0x68,
0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x73, 0x74, 0x76, 0x30, 0x67, 0x2f, 0x63, 0x75, 0x6e,
0x69, 0x63, 0x75, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x72, 0x70,
0x63, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
0x12, 0x45, 0x0a, 0x09, 0x47, 0x65, 0x74, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x1b, 0x2e,
0x63, 0x75, 0x6e, 0x69, 0x63, 0x75, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x53, 0x74,
0x61, 0x74, 0x75, 0x73, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x1a, 0x19, 0x2e, 0x63, 0x75, 0x6e,
0x69, 0x63, 0x75, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x53, 0x74, 0x61, 0x74, 0x75,
0x73, 0x52, 0x65, 0x73, 0x70, 0x22, 0x00, 0x12, 0x39, 0x0a, 0x09, 0x53, 0x65, 0x74, 0x43, 0x6f,
0x6e, 0x66, 0x69, 0x67, 0x12, 0x1b, 0x2e, 0x63, 0x75, 0x6e, 0x69, 0x63, 0x75, 0x2e, 0x72, 0x70,
0x63, 0x2e, 0x53, 0x65, 0x74, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x50, 0x61, 0x72, 0x61, 0x6d,
0x73, 0x1a, 0x0d, 0x2e, 0x63, 0x75, 0x6e, 0x69, 0x63, 0x75, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79,
0x22, 0x00, 0x12, 0x45, 0x0a, 0x09, 0x47, 0x65, 0x74, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12,
0x1b, 0x2e, 0x63, 0x75, 0x6e, 0x69, 0x63, 0x75, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x47, 0x65, 0x74,
0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x1a, 0x19, 0x2e, 0x63,
0x75, 0x6e, 0x69, 0x63, 0x75, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x43, 0x6f, 0x6e,
0x66, 0x69, 0x67, 0x52, 0x65, 0x73, 0x70, 0x22, 0x00, 0x12, 0x2e, 0x0a, 0x0c, 0x52, 0x65, 0x6c,
0x6f, 0x61, 0x64, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x0d, 0x2e, 0x63, 0x75, 0x6e, 0x69,
0x63, 0x75, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x0d, 0x2e, 0x63, 0x75, 0x6e, 0x69, 0x63,
0x75, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x00, 0x12, 0x3f, 0x0a, 0x07, 0x41, 0x64, 0x64,
0x50, 0x65, 0x65, 0x72, 0x12, 0x19, 0x2e, 0x63, 0x75, 0x6e, 0x69, 0x63, 0x75, 0x2e, 0x72, 0x70,
0x63, 0x2e, 0x41, 0x64, 0x64, 0x50, 0x65, 0x65, 0x72, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x1a,
0x17, 0x2e, 0x63, 0x75, 0x6e, 0x69, 0x63, 0x75, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x41, 0x64, 0x64,
0x50, 0x65, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x22, 0x00, 0x42, 0x27, 0x5a, 0x25, 0x67, 0x69,
0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x73, 0x74, 0x76, 0x30, 0x67, 0x2f, 0x63,
0x75, 0x6e, 0x69, 0x63, 0x75, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f,
0x72, 0x70, 0x63, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
@@ -495,7 +543,7 @@ func file_rpc_daemon_proto_rawDescGZIP() []byte {
return file_rpc_daemon_proto_rawDescData
}
var file_rpc_daemon_proto_msgTypes = make([]protoimpl.MessageInfo, 9)
var file_rpc_daemon_proto_msgTypes = make([]protoimpl.MessageInfo, 10)
var file_rpc_daemon_proto_goTypes = []interface{}{
(*GetStatusParams)(nil), // 0: cunicu.rpc.GetStatusParams
(*GetStatusResp)(nil), // 1: cunicu.rpc.GetStatusResp
@@ -504,44 +552,43 @@ var file_rpc_daemon_proto_goTypes = []interface{}{
(*GetConfigResp)(nil), // 4: cunicu.rpc.GetConfigResp
(*AddPeerParams)(nil), // 5: cunicu.rpc.AddPeerParams
(*AddPeerResp)(nil), // 6: cunicu.rpc.AddPeerResp
nil, // 7: cunicu.rpc.SetConfigParams.SettingsEntry
nil, // 8: cunicu.rpc.GetConfigResp.SettingsEntry
(*core.Interface)(nil), // 9: cunicu.core.Interface
(*Invitation)(nil), // 10: cunicu.rpc.Invitation
(*proto.Empty)(nil), // 11: cunicu.Empty
(*proto.BuildInfo)(nil), // 12: cunicu.BuildInfo
(*Event)(nil), // 13: cunicu.rpc.Event
(*ShutdownParams)(nil), // 7: cunicu.rpc.ShutdownParams
nil, // 8: cunicu.rpc.SetConfigParams.SettingsEntry
nil, // 9: cunicu.rpc.GetConfigResp.SettingsEntry
(*core.Interface)(nil), // 10: cunicu.core.Interface
(*Invitation)(nil), // 11: cunicu.rpc.Invitation
(*proto.Empty)(nil), // 12: cunicu.Empty
(*proto.BuildInfo)(nil), // 13: cunicu.BuildInfo
(*Event)(nil), // 14: cunicu.rpc.Event
}
var file_rpc_daemon_proto_depIdxs = []int32{
9, // 0: cunicu.rpc.GetStatusResp.interfaces:type_name -> cunicu.core.Interface
7, // 1: cunicu.rpc.SetConfigParams.settings:type_name -> cunicu.rpc.SetConfigParams.SettingsEntry
8, // 2: cunicu.rpc.GetConfigResp.settings:type_name -> cunicu.rpc.GetConfigResp.SettingsEntry
10, // 3: cunicu.rpc.AddPeerResp.invitation:type_name -> cunicu.rpc.Invitation
9, // 4: cunicu.rpc.AddPeerResp.interface:type_name -> cunicu.core.Interface
11, // 5: cunicu.rpc.Daemon.GetBuildInfo:input_type -> cunicu.Empty
11, // 6: cunicu.rpc.Daemon.StreamEvents:input_type -> cunicu.Empty
11, // 7: cunicu.rpc.Daemon.UnWait:input_type -> cunicu.Empty
11, // 8: cunicu.rpc.Daemon.Stop:input_type -> cunicu.Empty
11, // 9: cunicu.rpc.Daemon.Restart:input_type -> cunicu.Empty
11, // 10: cunicu.rpc.Daemon.Sync:input_type -> cunicu.Empty
0, // 11: cunicu.rpc.Daemon.GetStatus:input_type -> cunicu.rpc.GetStatusParams
2, // 12: cunicu.rpc.Daemon.SetConfig:input_type -> cunicu.rpc.SetConfigParams
3, // 13: cunicu.rpc.Daemon.GetConfig:input_type -> cunicu.rpc.GetConfigParams
11, // 14: cunicu.rpc.Daemon.ReloadConfig:input_type -> cunicu.Empty
5, // 15: cunicu.rpc.Daemon.AddPeer:input_type -> cunicu.rpc.AddPeerParams
12, // 16: cunicu.rpc.Daemon.GetBuildInfo:output_type -> cunicu.BuildInfo
13, // 17: cunicu.rpc.Daemon.StreamEvents:output_type -> cunicu.rpc.Event
11, // 18: cunicu.rpc.Daemon.UnWait:output_type -> cunicu.Empty
11, // 19: cunicu.rpc.Daemon.Stop:output_type -> cunicu.Empty
11, // 20: cunicu.rpc.Daemon.Restart:output_type -> cunicu.Empty
11, // 21: cunicu.rpc.Daemon.Sync:output_type -> cunicu.Empty
1, // 22: cunicu.rpc.Daemon.GetStatus:output_type -> cunicu.rpc.GetStatusResp
11, // 23: cunicu.rpc.Daemon.SetConfig:output_type -> cunicu.Empty
4, // 24: cunicu.rpc.Daemon.GetConfig:output_type -> cunicu.rpc.GetConfigResp
11, // 25: cunicu.rpc.Daemon.ReloadConfig:output_type -> cunicu.Empty
6, // 26: cunicu.rpc.Daemon.AddPeer:output_type -> cunicu.rpc.AddPeerResp
16, // [16:27] is the sub-list for method output_type
5, // [5:16] is the sub-list for method input_type
10, // 0: cunicu.rpc.GetStatusResp.interfaces:type_name -> cunicu.core.Interface
8, // 1: cunicu.rpc.SetConfigParams.settings:type_name -> cunicu.rpc.SetConfigParams.SettingsEntry
9, // 2: cunicu.rpc.GetConfigResp.settings:type_name -> cunicu.rpc.GetConfigResp.SettingsEntry
11, // 3: cunicu.rpc.AddPeerResp.invitation:type_name -> cunicu.rpc.Invitation
10, // 4: cunicu.rpc.AddPeerResp.interface:type_name -> cunicu.core.Interface
12, // 5: cunicu.rpc.Daemon.GetBuildInfo:input_type -> cunicu.Empty
12, // 6: cunicu.rpc.Daemon.StreamEvents:input_type -> cunicu.Empty
12, // 7: cunicu.rpc.Daemon.UnWait:input_type -> cunicu.Empty
7, // 8: cunicu.rpc.Daemon.Shutdown:input_type -> cunicu.rpc.ShutdownParams
12, // 9: cunicu.rpc.Daemon.Sync:input_type -> cunicu.Empty
0, // 10: cunicu.rpc.Daemon.GetStatus:input_type -> cunicu.rpc.GetStatusParams
2, // 11: cunicu.rpc.Daemon.SetConfig:input_type -> cunicu.rpc.SetConfigParams
3, // 12: cunicu.rpc.Daemon.GetConfig:input_type -> cunicu.rpc.GetConfigParams
12, // 13: cunicu.rpc.Daemon.ReloadConfig:input_type -> cunicu.Empty
5, // 14: cunicu.rpc.Daemon.AddPeer:input_type -> cunicu.rpc.AddPeerParams
13, // 15: cunicu.rpc.Daemon.GetBuildInfo:output_type -> cunicu.BuildInfo
14, // 16: cunicu.rpc.Daemon.StreamEvents:output_type -> cunicu.rpc.Event
12, // 17: cunicu.rpc.Daemon.UnWait:output_type -> cunicu.Empty
12, // 18: cunicu.rpc.Daemon.Shutdown:output_type -> cunicu.Empty
12, // 19: cunicu.rpc.Daemon.Sync:output_type -> cunicu.Empty
1, // 20: cunicu.rpc.Daemon.GetStatus:output_type -> cunicu.rpc.GetStatusResp
12, // 21: cunicu.rpc.Daemon.SetConfig:output_type -> cunicu.Empty
4, // 22: cunicu.rpc.Daemon.GetConfig:output_type -> cunicu.rpc.GetConfigResp
12, // 23: cunicu.rpc.Daemon.ReloadConfig:output_type -> cunicu.Empty
6, // 24: cunicu.rpc.Daemon.AddPeer:output_type -> cunicu.rpc.AddPeerResp
15, // [15:25] is the sub-list for method output_type
5, // [5:15] 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
@@ -639,6 +686,18 @@ func file_rpc_daemon_proto_init() {
return nil
}
}
file_rpc_daemon_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*ShutdownParams); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
@@ -646,7 +705,7 @@ func file_rpc_daemon_proto_init() {
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_rpc_daemon_proto_rawDesc,
NumEnums: 0,
NumMessages: 9,
NumMessages: 10,
NumExtensions: 0,
NumServices: 1,
},

View File

@@ -26,8 +26,7 @@ const (
Daemon_GetBuildInfo_FullMethodName = "/cunicu.rpc.Daemon/GetBuildInfo"
Daemon_StreamEvents_FullMethodName = "/cunicu.rpc.Daemon/StreamEvents"
Daemon_UnWait_FullMethodName = "/cunicu.rpc.Daemon/UnWait"
Daemon_Stop_FullMethodName = "/cunicu.rpc.Daemon/Stop"
Daemon_Restart_FullMethodName = "/cunicu.rpc.Daemon/Restart"
Daemon_Shutdown_FullMethodName = "/cunicu.rpc.Daemon/Shutdown"
Daemon_Sync_FullMethodName = "/cunicu.rpc.Daemon/Sync"
Daemon_GetStatus_FullMethodName = "/cunicu.rpc.Daemon/GetStatus"
Daemon_SetConfig_FullMethodName = "/cunicu.rpc.Daemon/SetConfig"
@@ -43,8 +42,7 @@ type DaemonClient interface {
GetBuildInfo(ctx context.Context, in *proto.Empty, opts ...grpc.CallOption) (*proto.BuildInfo, error)
StreamEvents(ctx context.Context, in *proto.Empty, opts ...grpc.CallOption) (Daemon_StreamEventsClient, error)
UnWait(ctx context.Context, in *proto.Empty, opts ...grpc.CallOption) (*proto.Empty, error)
Stop(ctx context.Context, in *proto.Empty, opts ...grpc.CallOption) (*proto.Empty, error)
Restart(ctx context.Context, in *proto.Empty, opts ...grpc.CallOption) (*proto.Empty, error)
Shutdown(ctx context.Context, in *ShutdownParams, opts ...grpc.CallOption) (*proto.Empty, error)
Sync(ctx context.Context, in *proto.Empty, opts ...grpc.CallOption) (*proto.Empty, error)
GetStatus(ctx context.Context, in *GetStatusParams, opts ...grpc.CallOption) (*GetStatusResp, error)
SetConfig(ctx context.Context, in *SetConfigParams, opts ...grpc.CallOption) (*proto.Empty, error)
@@ -111,18 +109,9 @@ func (c *daemonClient) UnWait(ctx context.Context, in *proto.Empty, opts ...grpc
return out, nil
}
func (c *daemonClient) Stop(ctx context.Context, in *proto.Empty, opts ...grpc.CallOption) (*proto.Empty, error) {
func (c *daemonClient) Shutdown(ctx context.Context, in *ShutdownParams, opts ...grpc.CallOption) (*proto.Empty, error) {
out := new(proto.Empty)
err := c.cc.Invoke(ctx, Daemon_Stop_FullMethodName, in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *daemonClient) Restart(ctx context.Context, in *proto.Empty, opts ...grpc.CallOption) (*proto.Empty, error) {
out := new(proto.Empty)
err := c.cc.Invoke(ctx, Daemon_Restart_FullMethodName, in, out, opts...)
err := c.cc.Invoke(ctx, Daemon_Shutdown_FullMethodName, in, out, opts...)
if err != nil {
return nil, err
}
@@ -190,8 +179,7 @@ type DaemonServer interface {
GetBuildInfo(context.Context, *proto.Empty) (*proto.BuildInfo, error)
StreamEvents(*proto.Empty, Daemon_StreamEventsServer) error
UnWait(context.Context, *proto.Empty) (*proto.Empty, error)
Stop(context.Context, *proto.Empty) (*proto.Empty, error)
Restart(context.Context, *proto.Empty) (*proto.Empty, error)
Shutdown(context.Context, *ShutdownParams) (*proto.Empty, error)
Sync(context.Context, *proto.Empty) (*proto.Empty, error)
GetStatus(context.Context, *GetStatusParams) (*GetStatusResp, error)
SetConfig(context.Context, *SetConfigParams) (*proto.Empty, error)
@@ -214,11 +202,8 @@ func (UnimplementedDaemonServer) StreamEvents(*proto.Empty, Daemon_StreamEventsS
func (UnimplementedDaemonServer) UnWait(context.Context, *proto.Empty) (*proto.Empty, error) {
return nil, status.Errorf(codes.Unimplemented, "method UnWait not implemented")
}
func (UnimplementedDaemonServer) Stop(context.Context, *proto.Empty) (*proto.Empty, error) {
return nil, status.Errorf(codes.Unimplemented, "method Stop not implemented")
}
func (UnimplementedDaemonServer) Restart(context.Context, *proto.Empty) (*proto.Empty, error) {
return nil, status.Errorf(codes.Unimplemented, "method Restart not implemented")
func (UnimplementedDaemonServer) Shutdown(context.Context, *ShutdownParams) (*proto.Empty, error) {
return nil, status.Errorf(codes.Unimplemented, "method Shutdown not implemented")
}
func (UnimplementedDaemonServer) Sync(context.Context, *proto.Empty) (*proto.Empty, error) {
return nil, status.Errorf(codes.Unimplemented, "method Sync not implemented")
@@ -308,38 +293,20 @@ func _Daemon_UnWait_Handler(srv interface{}, ctx context.Context, dec func(inter
return interceptor(ctx, in, info, handler)
}
func _Daemon_Stop_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(proto.Empty)
func _Daemon_Shutdown_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(ShutdownParams)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(DaemonServer).Stop(ctx, in)
return srv.(DaemonServer).Shutdown(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: Daemon_Stop_FullMethodName,
FullMethod: Daemon_Shutdown_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(DaemonServer).Stop(ctx, req.(*proto.Empty))
}
return interceptor(ctx, in, info, handler)
}
func _Daemon_Restart_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(proto.Empty)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(DaemonServer).Restart(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: Daemon_Restart_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(DaemonServer).Restart(ctx, req.(*proto.Empty))
return srv.(DaemonServer).Shutdown(ctx, req.(*ShutdownParams))
}
return interceptor(ctx, in, info, handler)
}
@@ -468,12 +435,8 @@ var Daemon_ServiceDesc = grpc.ServiceDesc{
Handler: _Daemon_UnWait_Handler,
},
{
MethodName: "Stop",
Handler: _Daemon_Stop_Handler,
},
{
MethodName: "Restart",
Handler: _Daemon_Restart_Handler,
MethodName: "Shutdown",
Handler: _Daemon_Shutdown_Handler,
},
{
MethodName: "Sync",

View File

@@ -96,19 +96,13 @@ func (s *DaemonServer) UnWait(_ context.Context, _ *proto.Empty) (*proto.Empty,
return &proto.Empty{}, err
}
func (s *DaemonServer) Stop(_ context.Context, _ *proto.Empty) (*proto.Empty, error) {
s.Daemon.Stop()
return &proto.Empty{}, nil
}
func (s *DaemonServer) Restart(_ context.Context, _ *proto.Empty) (*proto.Empty, error) {
if osx.ReexecSelfSupported {
s.Daemon.Restart()
} else {
func (s *DaemonServer) Shutdown(_ context.Context, params *rpcproto.ShutdownParams) (*proto.Empty, error) {
if params.Restart && !osx.ReexecSelfSupported {
return nil, status.Error(codes.Unimplemented, "not supported on this platform")
}
s.Daemon.Shutdown(params.Restart)
return &proto.Empty{}, nil
}

View File

@@ -43,12 +43,15 @@ message AddPeerResp {
core.Interface interface = 2;
}
message ShutdownParams {
bool restart = 1;
}
service Daemon {
rpc GetBuildInfo(Empty) returns (BuildInfo) {}
rpc StreamEvents(Empty) returns (stream Event) {}
rpc UnWait(Empty) returns (Empty) {}
rpc Stop(Empty) returns (Empty) {}
rpc Restart(Empty) returns (Empty) {}
rpc Shutdown(ShutdownParams) returns (Empty) {}
rpc Sync(Empty) returns (Empty) {}
rpc GetStatus(GetStatusParams) returns (GetStatusResp) {}

View File

@@ -14,7 +14,7 @@ import (
"github.com/stv0g/cunicu/pkg/crypto"
netx "github.com/stv0g/cunicu/pkg/net"
"github.com/stv0g/cunicu/pkg/proto"
"github.com/stv0g/cunicu/pkg/proto/rpc"
"github.com/stv0g/cunicu/pkg/wg"
"github.com/stv0g/cunicu/test/e2e/nodes"
opt "github.com/stv0g/cunicu/test/e2e/nodes/options"
@@ -248,7 +248,7 @@ var _ = Context("restart: Restart ICE agents", func() {
By("Initiating agent restart via RPC")
_, err = n1.Client.Restart(ctx, &proto.Empty{})
_, err = n1.Client.Shutdown(ctx, &rpc.ShutdownParams{Restart: true})
Expect(err).To(Succeed(), "Failed to restart peer: %s", err)
})
})