1
0
mirror of https://github.com/kairos-io/kairos-agent.git synced 2025-05-07 07:46:46 +00:00
kairos-agent/cmd/agent/agent.go
Ettore Di Giacinto b2e49776a3 Split off cli into separate binaries ()
* 🎨 Split off cli into separate binaries

This commit splits off the cli into 3 binaries:
- agent
- cli
- provider

The provider now is a separate component that can be tested by itself
and have its own lifecycle. This paves the way to a ligher c3os variant,
HA support and other features that can be provided on runtime.

This is working, but still there are low hanging fruit to care about.

Fixes 

* 🤖 Add provider bin to releases

* ⚙️ Handle signals

* ⚙️ Reduce buildsize footprint

* 🎨 Scan for providers also in /system/providers

* 🤖 Run goreleaser

* 🎨 Refactoring
2022-07-04 22:39:34 +02:00

58 lines
1.1 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(dir...)
if err != nil {
return err
}
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
}