Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the agent behave more like an agent #165

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions internal/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package agent
import (
"fmt"
"os"
"os/signal"
"path/filepath"
"time"

v1 "github.com/kairos-io/kairos-agent/v2/pkg/types/v1"

Expand All @@ -19,6 +21,17 @@ import (

// Run starts the agent provider emitting the bootstrap event.
func Run(opts ...Option) error {
// capture ctrl+c and exit cleanly
channel := make(chan os.Signal, 1)
signal.Notify(channel, os.Interrupt)
go func() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will spawn up a goroutine and grow indefinetly on each time Run is called again

for sig := range channel {
// sig is a ^C, handle it
fmt.Printf("Got %s signal, exiting\n", sig)
os.Exit(1)
}
}()

o := &Options{}
if err := o.Apply(opts...); err != nil {
return err
Expand All @@ -27,7 +40,7 @@ func Run(opts ...Option) error {
os.MkdirAll("/usr/local/.kairos", 0600) //nolint:errcheck

// Reads config
c, err := config.Scan(collector.Directories(o.Dir...))
c, err := config.Scan(collector.Directories(o.Dir...), collector.NoLogs)
if err != nil {
return err
}
Expand Down Expand Up @@ -93,5 +106,7 @@ func Run(opts ...Option) error {
fmt.Println("Warning: Agent failed, restarting: ", err.Error())
return Run(opts...)
}
return err
fmt.Printf("Nothing done, sleeping 10 seconds and checking again\n")
time.Sleep(10 * time.Second)
return Run(opts...)
}