diff --git a/dracut/28immucore/generator.sh b/dracut/28immucore/generator.sh index a0bd62e..5afca84 100755 --- a/dracut/28immucore/generator.sh +++ b/dracut/28immucore/generator.sh @@ -29,15 +29,4 @@ cos_img=$(getarg cos-img/filename=) echo "Options=ro,suid,dev,exec,auto,nouser,async" } > "$GENERATOR_DIR"/sysroot.mount -## END GENERATE SYSROOT - -# set sentinel file for boot mode -mkdir -p /run/cos -case "${cos_img}" in - *recovery*) - echo -n 1 > /run/cos/recovery_mode ;; - *active*) - echo -n 1 > /run/cos/active_mode ;; - *passive*) - echo -n 1 > /run/cos/passive_mode ;; -esac \ No newline at end of file +## END GENERATE SYSROOT \ No newline at end of file diff --git a/go.sum b/go.sum index 2877ede..98fd568 100644 --- a/go.sum +++ b/go.sum @@ -164,8 +164,6 @@ github.com/containerd/containerd v1.5.0-beta.4/go.mod h1:GmdgZd2zA2GYIBZ0w09Zvgq github.com/containerd/containerd v1.5.0-rc.0/go.mod h1:V/IXoMqNGgBlabz3tHD2TWDoTJseu1FGOKuoA4nNb2s= github.com/containerd/containerd v1.5.1/go.mod h1:0DOxVqwDy2iZvrZp2JUx/E+hS0UNTVn7dJnIOwtYR4g= github.com/containerd/containerd v1.5.7/go.mod h1:gyvv6+ugqY25TiXxcZC3L5yOeYgEw0QMhscqVp1AR9c= -github.com/containerd/containerd v1.6.16 h1:0H5xH6ABsN7XTrxIAKxFpBkFCBtrZ/OSORhCpUnHjrc= -github.com/containerd/containerd v1.6.16/go.mod h1:1RdCUu95+gc2v9t3IL+zIlpClSmew7/0YS8O5eQZrOw= github.com/containerd/containerd v1.6.17 h1:XDnJIeJW0cLf6v7/+N+6L9kGrChHeXekZp2VHu6OpiY= github.com/containerd/containerd v1.6.17/go.mod h1:1RdCUu95+gc2v9t3IL+zIlpClSmew7/0YS8O5eQZrOw= github.com/containerd/continuity v0.0.0-20190426062206-aaeac12a7ffc/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y= diff --git a/internal/cmd/commands.go b/internal/cmd/commands.go index 47de852..31b9895 100644 --- a/internal/cmd/commands.go +++ b/internal/cmd/commands.go @@ -38,6 +38,13 @@ Sends a generic event payload with the configuration found in the scanned direct zerolog.SetGlobalLevel(zerolog.DebugLevel) } + // First set the sentinel file + err = utils.SetSentinelFile() + if err != nil { + log.Logger.Err(err).Send() + return err + } + // If we boot from CD, we do nothing cdBoot, err := utils.BootedFromCD() if err != nil { diff --git a/internal/utils/common.go b/internal/utils/common.go index b52259b..6986e76 100644 --- a/internal/utils/common.go +++ b/internal/utils/common.go @@ -4,6 +4,7 @@ import ( "github.com/joho/godotenv" "github.com/kairos-io/kairos/sdk/state" "os" + "path/filepath" "strings" ) @@ -118,3 +119,36 @@ func CleanupSlice(slice []string) []string { } return cleanSlice } + +// SetSentinelFile sets the sentinel file to identify the boot mode. +// This is used by several things to know in which state they are, for example cloud configs +func SetSentinelFile() error { + var sentinel string + + err := CreateIfNotExists("/run/cos/") + if err != nil { + return err + } + runtime, err := state.NewRuntime() + if err != nil { + return err + } + + switch runtime.BootState { + case state.Active: + sentinel = "active_mode" + case state.Passive: + sentinel = "passive_mode" + case state.Recovery: + sentinel = "recovery_mode" + case state.LiveCD: + sentinel = "live_mode" + default: + sentinel = string(state.Unknown) + } + err = os.WriteFile(filepath.Join("/run/cos/", sentinel), []byte("1"), os.ModePerm) + if err != nil { + return err + } + return nil +} \ No newline at end of file