-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Without this, a bit of the validation is done in main, while the rest is done in each constructor. We create a new global constructor in checkers/reboot to solve all the cases and bubble up the errors.
- Loading branch information
Showing
6 changed files
with
68 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,27 @@ | ||
package reboot | ||
|
||
import ( | ||
"fmt" | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
// Rebooter is the standard interface to use to execute | ||
// the reboot, after it has been considered as necessary. | ||
// 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() | ||
} | ||
|
||
func NewRebooter(rebootMethod string, rebootCommand string, rebootSignal int) (Rebooter, error) { | ||
switch { | ||
case rebootMethod == "command": | ||
log.Infof("Reboot command: %s", rebootCommand) | ||
return NewCommandRebooter(rebootCommand) | ||
case rebootMethod == "signal": | ||
log.Infof("Reboot signal: %d", rebootSignal) | ||
return NewSignalRebooter(rebootSignal) | ||
default: | ||
return nil, fmt.Errorf("invalid reboot-method configured %s, expected signal or command", rebootMethod) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters