-
Notifications
You must be signed in to change notification settings - Fork 4
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
[APP-6886] Add option to reboot device after a certain amount of time #51
Changes from 5 commits
ad4dc74
cf3efec
a384c2f
9da45ca
0cfc15a
e8c6d20
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,8 +4,10 @@ import ( | |
"context" | ||
"errors" | ||
"os" | ||
"os/exec" | ||
"reflect" | ||
"sort" | ||
"syscall" | ||
"time" | ||
|
||
gnm "github.com/Otterverse/gonetworkmanager/v2" | ||
|
@@ -737,6 +739,20 @@ func (w *Provisioning) mainLoop(ctx context.Context) { | |
} | ||
} | ||
|
||
offlineRebootTimeout := w.cfg.DeviceRebootAfterOfflineMinutes > 0 && | ||
lastConnectivity.Before(now.Add(time.Duration(w.cfg.DeviceRebootAfterOfflineMinutes)*-1)) | ||
if offlineRebootTimeout { | ||
w.logger.Infof("device has been offline for more than %s minutes, rebooting", w.cfg.DeviceRebootAfterOfflineMinutes) | ||
|
||
syscall.Sync() // flush file system buffers | ||
cmd := exec.Command("systemctl", "reboot") | ||
output, err := cmd.CombinedOutput() | ||
if err != nil { | ||
w.logger.Error(errw.Wrapf(err, "running 'systemctl reboot' %s", output)) | ||
} | ||
time.Sleep(time.Second * 100) // systemd DefaultTimeoutStopSec defaults to 90 seconds | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't do this, or agent itself won't shut down when called and will just hang until the sleep is done. It will also fail healthchecks if the loop pauses here for too long. There's a function for pausing the loop though. See line 623 above for the previous use of the following:
May also need a slightly longer timeout, as I BELIEVE that systemd 90 second default is per service, so if it's shutting down multiple services, it can definitely take longer than that. I'd think 2 or maybe even 5 minutes, since this isn't going to handle the failure case (where reboot doesn't happen.) Regardless, I'd DEFINITELY suggest logging an error if the timeout expires (included in suggestion above... rewrite as needed) so the user knows things are off the rails. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. makes sense, thanks i missed there's a sleep on the main loop |
||
} | ||
|
||
hitOfflineTimeout := lastConnectivity.Before(now.Add(time.Duration(w.cfg.OfflineTimeout)*-1)) && | ||
pModeChange.Before(now.Add(time.Duration(w.cfg.OfflineTimeout)*-1)) | ||
// not in provisioning mode, so start it if not configured (/etc/viam.json) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't be needed when letting a normal shutdown happen. Filesystems will get synced/unmounted in their own ordering.