Download this file
| 1 | package host |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "github.com/carlosframework/platform/internal/hostbox" |
| 6 | "os" |
| 7 | "strings" |
| 8 | ) |
| 9 | |
| 10 | func verifyMigrationStopped(ctx context.Context, launches *hostbox.LaunchJournal, inventory *hostbox.StopInventoryDB, launch hostbox.LaunchInventory, roots map[string]string) error { |
| 11 | if os.Geteuid() != 0 { |
| 12 | return ErrClaimStopUnavailable |
| 13 | } |
| 14 | if err := verifyStopKernelMounts("/sys/fs/cgroup", "/proc"); err != nil { |
| 15 | return err |
| 16 | } |
| 17 | journal, err := launches.ReadStopKernelJournal(ctx, launch.Target) |
| 18 | if err != nil { |
| 19 | return err |
| 20 | } |
| 21 | if !journal.WritersClosed || len(journal.ProducerIDs) != 0 || journal.PendingRoles || !journal.Settled { |
| 22 | return ErrClaimStopInventory |
| 23 | } |
| 24 | raw, err := os.ReadFile("/proc/sys/kernel/random/boot_id") |
| 25 | if err != nil { |
| 26 | return err |
| 27 | } |
| 28 | boot := strings.TrimSpace(string(raw)) |
| 29 | if boot == launch.Target.BootID { |
| 30 | _, err = scanStopCgroups(ctx, "/sys/fs/cgroup", journal.Cgroups) |
| 31 | } else { |
| 32 | _, err = scanRebootCgroups(ctx, "/sys/fs/cgroup", journal.Cgroups, launch.Target.BootID, boot) |
| 33 | } |
| 34 | if err != nil { |
| 35 | return err |
| 36 | } |
| 37 | in, err := inventory.ReadExactStopInventory(ctx, launch.Target) |
| 38 | if err != nil { |
| 39 | return err |
| 40 | } |
| 41 | paths, err := (LinuxStopKernel{ManagedRoots: roots}).stopDescriptorPaths(in) |
| 42 | if err != nil { |
| 43 | return err |
| 44 | } |
| 45 | return scanStopDescriptors(ctx, "/proc", journal.Files, paths) |
| 46 | } |
| 47 | |