art: Make sure the agent doesn't start when performing auto-installs

This commit is contained in:
Ettore Di Giacinto
2022-07-20 22:31:40 +00:00
committed by Itxaka
parent 602d086ce4
commit 6c08ac78a8
2 changed files with 38 additions and 0 deletions

View File

@@ -24,6 +24,12 @@ func Run(apiAddress string, dir []string, force bool) error {
if err != nil {
return err
}
bf := machine.BootFrom()
if c.Install != nil && c.Install.Auto && (bf == machine.NetBoot || bf == machine.LiveCDBoot) {
// Don't go ahead if we are asked to install from a booting live medium
fmt.Println("Agent run aborted. Installation being performed from live medium")
return nil
}
os.MkdirAll("/var/log/c3os", 0600)
fileName := filepath.Join("/var/log/c3os", "agent-provider.log")

View File

@@ -4,6 +4,7 @@ import (
"fmt"
"io/ioutil"
"os"
"strings"
"github.com/c3os-io/c3os/internal/machine/openrc"
"github.com/c3os-io/c3os/internal/machine/systemd"
@@ -20,6 +21,37 @@ type Service interface {
Restart() error
}
const (
PassiveBoot = "passive"
ActiveBoot = "active"
RecoveryBoot = "recovery"
LiveCDBoot = "liveCD"
NetBoot = "netboot"
UnknownBoot = "unknown"
)
// BootFrom returns the booting partition of the SUT
func BootFrom() string {
out, err := utils.SH("cat /proc/cmdline")
if err != nil {
return UnknownBoot
}
switch {
case strings.Contains(out, "COS_ACTIVE"):
return ActiveBoot
case strings.Contains(out, "COS_PASSIVE"):
return PassiveBoot
case strings.Contains(out, "COS_RECOVERY"), strings.Contains(out, "COS_SYSTEM"):
return RecoveryBoot
case strings.Contains(out, "live:CDLABEL"):
return LiveCDBoot
case strings.Contains(out, "netboot"):
return NetBoot
default:
return UnknownBoot
}
}
func EdgeVPN(instance, rootDir string) (Service, error) {
if utils.IsOpenRCBased() {
return openrc.NewService(