Set the sentinel file from immucore directly

Also add a missing livecd sentinel file

Signed-off-by: Itxaka <itxaka.garcia@spectrocloud.com>
This commit is contained in:
Itxaka
2023-02-13 21:42:45 +01:00
parent 1d6572faaa
commit 076bba95dc
4 changed files with 42 additions and 14 deletions

View File

@@ -30,14 +30,3 @@ cos_img=$(getarg cos-img/filename=)
} > "$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

2
go.sum
View File

@@ -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=

View File

@@ -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 {

View File

@@ -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
}