blob: 28a2a0a6e065576b119eae3d9f5edae2bf45a405 [file] [log] [blame]
Lorenz Brun35fcf032023-06-29 04:15:58 +02001package mgmt
2
3import (
4 "context"
5 "time"
6
7 "golang.org/x/sys/unix"
8 "google.golang.org/grpc/codes"
9 "google.golang.org/grpc/status"
10
11 apb "source.monogon.dev/metropolis/proto/api"
12)
13
14func (s *Service) UpdateNode(ctx context.Context, req *apb.UpdateNodeRequest) (*apb.UpdateNodeResponse, error) {
15 if err := s.UpdateService.InstallBundle(ctx, req.BundleUrl); err != nil {
16 return nil, status.Errorf(codes.Unavailable, "error installing update: %v", err)
17 }
18 if !req.NoReboot {
19 // TODO(#253): Tell Supervisor to shut down gracefully and reboot
20 go func() {
21 time.Sleep(10 * time.Second)
22 unix.Sync()
23 unix.Reboot(unix.LINUX_REBOOT_CMD_RESTART)
24 }()
25 }
26 return &apb.UpdateNodeResponse{}, nil
27}