mirror of
https://github.com/kairos-io/provider-kairos.git
synced 2025-09-18 08:19:54 +00:00
Don't write an empty k3s service on disk (#519)
just use the one that was created by the k3s installer script Fixes: https://github.com/kairos-io/kairos/issues/2125 Signed-off-by: Dimitris Karakasilis <dimitris@spectrocloud.com> Co-authored-by: Mauro Morales <mauro.morales@spectrocloud.com>
This commit is contained in:
committed by
GitHub
parent
874beb3c9a
commit
05d3833dd9
@@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
logging "github.com/ipfs/go-log"
|
||||
@@ -198,44 +197,24 @@ func oneTimeBootstrap(l logging.StandardLogger, c *providerConfig.Config, vpnSet
|
||||
}
|
||||
|
||||
if utils.IsOpenRCBased() {
|
||||
// Instead of creating an empty file, let's use the one generated by the k3s installer
|
||||
content, err := os.ReadFile("/etc/init.d/k3s")
|
||||
if err != nil {
|
||||
l.Errorf("Failed to read init file: %s", err.Error())
|
||||
return err
|
||||
}
|
||||
|
||||
if len(content) == 0 {
|
||||
err = fmt.Errorf("empty init file for k3s")
|
||||
l.Errorf("openrc error: %s", err.Error())
|
||||
return err
|
||||
}
|
||||
|
||||
svc, err = openrc.NewService(
|
||||
openrc.WithName(svcName),
|
||||
openrc.WithUnitContent(string(content)),
|
||||
)
|
||||
if err != nil {
|
||||
l.Errorf("Failed to create service: %s", err.Error())
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
svc, err = systemd.NewService(
|
||||
systemd.WithName(svcName),
|
||||
systemd.WithUnitContent("[Service]\nExecStart="),
|
||||
)
|
||||
if err != nil {
|
||||
l.Errorf("Failed to create service: %s", err.Error())
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
envFile := machine.K3sEnvUnit(svcName)
|
||||
if err != nil {
|
||||
l.Errorf("Failed to instanitate service: %s", err.Error())
|
||||
return err
|
||||
}
|
||||
if svc == nil {
|
||||
return fmt.Errorf("could not detect OS")
|
||||
}
|
||||
|
||||
// Setup systemd unit and starts it
|
||||
// Setup k3s service env file
|
||||
envFile := machine.K3sEnvUnit(svcName)
|
||||
if err := utils.WriteEnv(envFile,
|
||||
k3sConfig.Env,
|
||||
); err != nil {
|
||||
@@ -248,22 +227,18 @@ func oneTimeBootstrap(l logging.StandardLogger, c *providerConfig.Config, vpnSet
|
||||
l.Errorf("no k3s binary found (?)")
|
||||
return fmt.Errorf("no k3s binary found (?)")
|
||||
}
|
||||
|
||||
if err := svc.OverrideCmd(fmt.Sprintf("%s %s %s", k3sbin, svcRole, strings.Join(k3sConfig.Args, " "))); err != nil {
|
||||
l.Errorf("Failed to override k3s command: %s", err.Error())
|
||||
return err
|
||||
}
|
||||
|
||||
err = svc.WriteUnit()
|
||||
if err != nil {
|
||||
l.Errorf("Failed to write service: %s", err.Error())
|
||||
return err
|
||||
}
|
||||
|
||||
if err := svc.Start(); err != nil {
|
||||
l.Errorf("Failed to start service: %s", err.Error())
|
||||
return err
|
||||
}
|
||||
|
||||
// NOTE: When this fails, it doesn't produce an error!
|
||||
if err := svc.Enable(); err != nil {
|
||||
l.Errorf("Failed to enable service: %s", err.Error())
|
||||
return err
|
||||
|
Reference in New Issue
Block a user