blob: eb838dd54255b976b082a3a0fed712cb2d8ca23a [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 }
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 Brun35fcf032023-06-29 04:15:58 +020024 return nil, status.Errorf(codes.Unavailable, "error installing update: %v", err)
25 }
Lorenz Brund14be0e2023-07-31 16:46:14 +020026 if req.ActivationMode != apb.ActivationMode_ACTIVATION_NONE {
Tim Windelschmidt45d6f182023-08-07 13:19:41 +000027
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 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}