blob: 6a7e13e85f5d2695af765dfa6520186b38f46354 [file] [log] [blame]
Lorenz Brun35fcf032023-06-29 04:15:58 +02001package mgmt
2
3import (
4 "context"
Lorenz Brun35fcf032023-06-29 04:15:58 +02005
6 "golang.org/x/sys/unix"
7 "google.golang.org/grpc/codes"
8 "google.golang.org/grpc/status"
9
10 apb "source.monogon.dev/metropolis/proto/api"
11)
12
13func (s *Service) UpdateNode(ctx context.Context, req *apb.UpdateNodeRequest) (*apb.UpdateNodeResponse, error) {
Lorenz Brund14be0e2023-07-31 16:46:14 +020014 ok := s.updateMutex.TryLock()
15 if ok {
16 defer s.updateMutex.Unlock()
17 } else {
18 return nil, status.Error(codes.Aborted, "another UpdateNode RPC is in progress on this node")
19 }
Tim Windelschmidta10d0cb2025-01-13 14:44:15 +010020 if req.ActivationMode == apb.ActivationMode_ACTIVATION_MODE_INVALID {
Lorenz Brund14be0e2023-07-31 16:46:14 +020021 return nil, status.Errorf(codes.InvalidArgument, "activation_mode needs to be explicitly specified")
22 }
Tim Windelschmidta10d0cb2025-01-13 14:44:15 +010023 if err := s.UpdateService.InstallBundle(ctx, req.BundleUrl, req.ActivationMode == apb.ActivationMode_ACTIVATION_MODE_KEXEC); err != nil {
Lorenz Brun35fcf032023-06-29 04:15:58 +020024 return nil, status.Errorf(codes.Unavailable, "error installing update: %v", err)
25 }
Tim Windelschmidta10d0cb2025-01-13 14:44:15 +010026 if req.ActivationMode != apb.ActivationMode_ACTIVATION_MODE_NONE {
Tim Windelschmidt45d6f182023-08-07 13:19:41 +000027
28 methodString, method := "reboot", unix.LINUX_REBOOT_CMD_RESTART
Tim Windelschmidta10d0cb2025-01-13 14:44:15 +010029 if req.ActivationMode == apb.ActivationMode_ACTIVATION_MODE_KEXEC {
Tim Windelschmidt45d6f182023-08-07 13:19:41 +000030 methodString = "kexec"
31 method = unix.LINUX_REBOOT_CMD_KEXEC
32 }
33
34 s.LogTree.MustLeveledFor("update").Infof("activating update with method: %s", methodString)
Lorenz Bruna036c4e2024-09-10 19:11:57 +020035 s.initiateReboot(method)
Lorenz Brun35fcf032023-06-29 04:15:58 +020036 }
Lorenz Brund14be0e2023-07-31 16:46:14 +020037
Lorenz Brun35fcf032023-06-29 04:15:58 +020038 return &apb.UpdateNodeResponse{}, nil
39}