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