| Lorenz Brun | 35fcf03 | 2023-06-29 04:15:58 +0200 | [diff] [blame] | 1 | package mgmt |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| Lorenz Brun | 35fcf03 | 2023-06-29 04:15:58 +0200 | [diff] [blame] | 5 | |
| 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 | |
| 13 | func (s *Service) UpdateNode(ctx context.Context, req *apb.UpdateNodeRequest) (*apb.UpdateNodeResponse, error) { |
| Lorenz Brun | d14be0e | 2023-07-31 16:46:14 +0200 | [diff] [blame] | 14 | 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 | } |
| 20 | if req.ActivationMode == apb.ActivationMode_ACTIVATION_INVALID { |
| 21 | return nil, status.Errorf(codes.InvalidArgument, "activation_mode needs to be explicitly specified") |
| 22 | } |
| 23 | if err := s.UpdateService.InstallBundle(ctx, req.BundleUrl, req.ActivationMode == apb.ActivationMode_ACTIVATION_KEXEC); err != nil { |
| Lorenz Brun | 35fcf03 | 2023-06-29 04:15:58 +0200 | [diff] [blame] | 24 | return nil, status.Errorf(codes.Unavailable, "error installing update: %v", err) |
| 25 | } |
| Lorenz Brun | d14be0e | 2023-07-31 16:46:14 +0200 | [diff] [blame] | 26 | if req.ActivationMode != apb.ActivationMode_ACTIVATION_NONE { |
| Tim Windelschmidt | 45d6f18 | 2023-08-07 13:19:41 +0000 | [diff] [blame] | 27 | |
| 28 | methodString, method := "reboot", unix.LINUX_REBOOT_CMD_RESTART |
| 29 | if req.ActivationMode == apb.ActivationMode_ACTIVATION_KEXEC { |
| 30 | methodString = "kexec" |
| 31 | method = unix.LINUX_REBOOT_CMD_KEXEC |
| 32 | } |
| 33 | |
| 34 | s.LogTree.MustLeveledFor("update").Infof("activating update with method: %s", methodString) |
| Lorenz Brun | a036c4e | 2024-09-10 19:11:57 +0200 | [diff] [blame] | 35 | s.initiateReboot(method) |
| Lorenz Brun | 35fcf03 | 2023-06-29 04:15:58 +0200 | [diff] [blame] | 36 | } |
| Lorenz Brun | d14be0e | 2023-07-31 16:46:14 +0200 | [diff] [blame] | 37 | |
| Lorenz Brun | 35fcf03 | 2023-06-29 04:15:58 +0200 | [diff] [blame] | 38 | return &apb.UpdateNodeResponse{}, nil |
| 39 | } |