Lorenz Brun | 35fcf03 | 2023-06-29 04:15:58 +0200 | [diff] [blame^] | 1 | package mgmt |
| 2 | |
| 3 | import ( |
| 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 | |
| 14 | func (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 | } |