Files
kairos-agent/cmd/agent/agent.go
Ettore Di Giacinto c7cbb37b24 gear: Extract netboot artifacts
This changeset also adds a `config_url` and `options` keyword in the c3os config.
Along with that the config logic is changed so the configuration is taken also from boot commands and merged in the final installed config file.
2022-07-07 16:57:38 +00:00

59 lines
1.2 KiB
Go

package main
import (
"fmt"
"io/ioutil"
"os"
"syscall"
"github.com/c3os-io/c3os/internal/bus"
"github.com/c3os-io/c3os/internal/utils"
events "github.com/c3os-io/c3os/pkg/bus"
config "github.com/c3os-io/c3os/pkg/config"
"github.com/nxadm/tail"
)
// setup needs edgevpn and k3s installed locally
// (both k3s and k3s-agent systemd services)
func agent(apiAddress string, dir []string, force bool) error {
os.MkdirAll("/usr/local/.c3os", 0600)
// Reads config
c, err := config.Scan(config.Directories(dir...))
if err != nil {
return err
}
// TODO: Proper cleanup the log file
f, err := ioutil.TempFile(os.TempDir(), "c3os")
if err != nil {
return err
}
err = ioutil.WriteFile(f.Name(), []byte{}, os.ModePerm)
if err != nil {
return err
}
t, err := tail.TailFile(f.Name(), tail.Config{Follow: true})
if err != nil {
return err
}
defer os.RemoveAll(f.Name())
utils.OnSignal(func() {
os.RemoveAll(f.Name())
}, syscall.SIGINT, syscall.SIGTERM)
go func() {
for line := range t.Lines {
fmt.Println(line.Text)
}
}()
_, err = bus.Manager.Publish(events.EventBootstrap, events.BootstrapPayload{APIAddress: apiAddress, Config: c.String(), Logfile: f.Name()})
return err
}