mirror of
https://github.com/kubereboot/kured.git
synced 2026-08-23 21:36:33 +00:00
Add error to reboot interface
Without this, impossible to bubble up errors to main Signed-off-by: Jean-Philippe Evrard <open-source@a.spamming.party>
This commit is contained in:
+5
-1
@@ -710,7 +710,11 @@ func rebootAsRequired(nodeID string, rebooter reboot.Rebooter, checker checkers.
|
||||
}
|
||||
}
|
||||
log.Infof("Triggering reboot for node %v", nodeID)
|
||||
rebooter.Reboot()
|
||||
|
||||
err = rebooter.Reboot()
|
||||
if err != nil {
|
||||
log.Fatalf("Unable to reboot node: %v", err)
|
||||
}
|
||||
for {
|
||||
log.Infof("Waiting for reboot")
|
||||
time.Sleep(time.Minute)
|
||||
|
||||
@@ -13,11 +13,12 @@ type CommandRebooter struct {
|
||||
}
|
||||
|
||||
// Reboot triggers the reboot command
|
||||
func (c CommandRebooter) Reboot() {
|
||||
func (c CommandRebooter) Reboot() error {
|
||||
log.Infof("Invoking command: %s", c.RebootCommand)
|
||||
if err := util.NewCommand(c.RebootCommand[0], c.RebootCommand[1:]...).Run(); err != nil {
|
||||
log.Fatalf("Error invoking reboot command: %v", err)
|
||||
return fmt.Errorf("error invoking reboot command %s: %v", c.RebootCommand, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewCommandRebooter is the constructor to create a CommandRebooter from a string not
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
// The Reboot method does not expect any return, yet should
|
||||
// most likely be refactored in the future to return an error
|
||||
type Rebooter interface {
|
||||
Reboot()
|
||||
Reboot() error
|
||||
}
|
||||
|
||||
// NewRebooter validates the rebootMethod, rebootCommand, and rebootSignal input,
|
||||
|
||||
@@ -4,8 +4,6 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"syscall"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// SignalRebooter holds context-information for a signal reboot.
|
||||
@@ -14,20 +12,19 @@ type SignalRebooter struct {
|
||||
}
|
||||
|
||||
// Reboot triggers the reboot signal
|
||||
func (c SignalRebooter) Reboot() {
|
||||
log.Infof("Invoking signal: %v", c.Signal)
|
||||
|
||||
func (c SignalRebooter) Reboot() error {
|
||||
process, err := os.FindProcess(1)
|
||||
if err != nil {
|
||||
log.Fatalf("Not running on Unix: %v", err)
|
||||
return fmt.Errorf("not running on Unix: %v", err)
|
||||
}
|
||||
|
||||
err = process.Signal(syscall.Signal(c.Signal))
|
||||
// Either PID does not exist, or the signal does not work. Hoping for
|
||||
// a decent enough error.
|
||||
if err != nil {
|
||||
log.Fatalf("Signal of SIGRTMIN+5 failed: %v", err)
|
||||
return fmt.Errorf("signal of SIGRTMIN+5 failed: %v", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewSignalRebooter is the constructor which sets the signal number.
|
||||
|
||||
Reference in New Issue
Block a user