This repository has been archived on 2024-08-02. You can view files and clone it, but cannot push or open issues or pull requests.
2018-09-21 12:31:52 +02:00
|
|
|
package updater
|
2018-09-19 17:13:45 +02:00
|
|
|
|
|
|
|
import (
|
2018-09-20 11:20:35 +02:00
|
|
|
"sync"
|
|
|
|
|
|
|
|
"forge.cadoles.com/Pyxis/golang-socketio"
|
2018-09-19 17:13:45 +02:00
|
|
|
"github.com/pkg/errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
eventReboot = "reboot now"
|
|
|
|
)
|
|
|
|
|
|
|
|
// RebootNow asks the ReachRS module to reboot now
|
2018-09-21 12:31:52 +02:00
|
|
|
func (c *Client) RebootNow(waitDisconnect bool) error {
|
2018-09-19 17:13:45 +02:00
|
|
|
|
|
|
|
var err error
|
2018-09-20 11:20:35 +02:00
|
|
|
var wg sync.WaitGroup
|
|
|
|
|
|
|
|
if waitDisconnect {
|
|
|
|
wg.Add(1)
|
2018-09-21 12:31:52 +02:00
|
|
|
err = c.On(gosocketio.OnDisconnection, func(h *gosocketio.Channel) {
|
|
|
|
c.Off(gosocketio.OnDisconnection)
|
2018-09-20 11:20:35 +02:00
|
|
|
wg.Done()
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrapf(err, "error while binding to '%s' event", gosocketio.OnDisconnection)
|
|
|
|
}
|
|
|
|
}
|
2018-09-19 17:13:45 +02:00
|
|
|
|
2018-09-21 12:31:52 +02:00
|
|
|
if err = c.Emit(eventReboot, nil); err != nil {
|
|
|
|
return err
|
2018-09-19 17:13:45 +02:00
|
|
|
}
|
|
|
|
|
2018-09-20 11:20:35 +02:00
|
|
|
if waitDisconnect {
|
|
|
|
wg.Wait()
|
|
|
|
}
|
|
|
|
|
2018-09-19 17:13:45 +02:00
|
|
|
return err
|
|
|
|
|
|
|
|
}
|