blob: 21ca70853c8ef6d78dc5ec164d09f9d875bc46aa [file] [log] [blame]
Tim Windelschmidt6d33a432025-02-04 14:34:25 +01001// Copyright The Monogon Project Authors.
2// SPDX-License-Identifier: Apache-2.0
3
Tim Windelschmidt7a1b27d2024-02-22 23:54:58 +01004package main
5
6import (
7 "context"
8 "os"
9 "path/filepath"
10 "time"
11
12 "golang.org/x/sys/unix"
13
14 "source.monogon.dev/metropolis/node/core/devmgr"
15 "source.monogon.dev/osbase/supervisor"
16)
17
18// Main runnable for the installer.
19func takeoverRunnable(ctx context.Context) error {
20 l := supervisor.Logger(ctx)
21
22 devmgrSvc := devmgr.New()
23 supervisor.Run(ctx, "devmgr", devmgrSvc.Run)
24 supervisor.Signal(ctx, supervisor.SignalHealthy)
25
26 for {
27 devicePath := filepath.Join("/dev", os.Getenv(EnvInstallTarget))
28 l.Infof("Waiting for device: %s", devicePath)
29 _, err := os.Stat(devicePath)
30 if os.IsNotExist(err) {
31 time.Sleep(1 * time.Second)
32 continue
33 } else if err != nil {
34 return err
35 }
36 break
37 }
38
39 if err := installMetropolis(l); err != nil {
40 l.Errorf("Installation failed: %v", err)
41 } else {
42 l.Info("Installation succeeded")
43 }
44
45 time.Sleep(1 * time.Second)
46 unix.Sync()
47 unix.Reboot(unix.LINUX_REBOOT_CMD_RESTART)
48
49 return nil
50}