mirror of
https://github.com/kairos-io/kairos-agent.git
synced 2025-08-31 16:39:20 +00:00
Split off cli into separate binaries (#37)
* 🎨 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 #14 * 🤖 Add provider bin to releases * ⚙️ Handle signals * ⚙️ Reduce buildsize footprint * 🎨 Scan for providers also in /system/providers * 🤖 Run goreleaser * 🎨 Refactoring
This commit is contained in:
committed by
Itxaka
parent
74bfd373db
commit
63cd28d1cb
103
internal/machine/machine.go
Normal file
103
internal/machine/machine.go
Normal file
@@ -0,0 +1,103 @@
|
||||
package machine
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/c3os-io/c3os/internal/machine/openrc"
|
||||
"github.com/c3os-io/c3os/internal/machine/systemd"
|
||||
"github.com/denisbrodbeck/machineid"
|
||||
|
||||
"github.com/c3os-io/c3os/internal/utils"
|
||||
)
|
||||
|
||||
type Service interface {
|
||||
WriteUnit() error
|
||||
Start() error
|
||||
OverrideCmd(string) error
|
||||
Enable() error
|
||||
Restart() error
|
||||
}
|
||||
|
||||
func EdgeVPN(instance, rootDir string) (Service, error) {
|
||||
if utils.IsOpenRCBased() {
|
||||
return openrc.NewService(
|
||||
openrc.WithName("edgevpn"),
|
||||
openrc.WithUnitContent(openrc.EdgevpnUnit),
|
||||
openrc.WithRoot(rootDir),
|
||||
)
|
||||
} else {
|
||||
return systemd.NewService(
|
||||
systemd.WithName("edgevpn"),
|
||||
systemd.WithInstance(instance),
|
||||
systemd.WithUnitContent(systemd.EdgevpnUnit),
|
||||
systemd.WithRoot(rootDir),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
const EdgeVPNDefaultInstance string = "c3os"
|
||||
|
||||
type fakegetty struct{}
|
||||
|
||||
func (fakegetty) Restart() error { return nil }
|
||||
func (fakegetty) Enable() error { return nil }
|
||||
func (fakegetty) OverrideCmd(string) error { return nil }
|
||||
func (fakegetty) SetEnvFile(string) error { return nil }
|
||||
func (fakegetty) WriteUnit() error { return nil }
|
||||
func (fakegetty) Start() error {
|
||||
utils.SH("chvt 2")
|
||||
return nil
|
||||
}
|
||||
|
||||
func Getty(i int) (Service, error) {
|
||||
if utils.IsOpenRCBased() {
|
||||
return &fakegetty{}, nil
|
||||
} else {
|
||||
return systemd.NewService(
|
||||
systemd.WithName("getty"),
|
||||
systemd.WithInstance(fmt.Sprintf("tty%d", i)),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
func K3s() (Service, error) {
|
||||
if utils.IsOpenRCBased() {
|
||||
return openrc.NewService(
|
||||
openrc.WithName("k3s"),
|
||||
)
|
||||
} else {
|
||||
return systemd.NewService(
|
||||
systemd.WithName("k3s"),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
func K3sAgent() (Service, error) {
|
||||
if utils.IsOpenRCBased() {
|
||||
return openrc.NewService(
|
||||
openrc.WithName("k3s-agent"),
|
||||
)
|
||||
} else {
|
||||
return systemd.NewService(
|
||||
systemd.WithName("k3s-agent"),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
func K3sEnvUnit(unit string) string {
|
||||
if utils.IsOpenRCBased() {
|
||||
return fmt.Sprintf("/etc/rancher/k3s/%s.env", unit)
|
||||
} else {
|
||||
return fmt.Sprintf("/etc/sysconfig/%s", unit)
|
||||
}
|
||||
}
|
||||
|
||||
func UUID() string {
|
||||
if os.Getenv("UUID") != "" {
|
||||
return os.Getenv("UUID")
|
||||
}
|
||||
id, _ := machineid.ID()
|
||||
hostname, _ := os.Hostname()
|
||||
return fmt.Sprintf("%s-%s", id, hostname)
|
||||
}
|
Reference in New Issue
Block a user