mirror of
https://github.com/kairos-io/immucore.git
synced 2025-09-13 13:40:34 +00:00
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:
@@ -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
|
||||
}
|
Reference in New Issue
Block a user