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-19 17:13:45 +02:00
|
|
|
package reach
|
|
|
|
|
|
|
|
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-20 11:20:35 +02:00
|
|
|
func (u *Updater) 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)
|
|
|
|
err = u.conn.On(gosocketio.OnDisconnection, func(h *gosocketio.Channel) {
|
|
|
|
u.conn.Off(gosocketio.OnDisconnection)
|
|
|
|
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
|
|
|
|
|
|
|
u.logf("sending '%s' event", eventReboot)
|
|
|
|
if err = u.conn.Emit(eventReboot, nil); err != nil {
|
|
|
|
return errors.Wrapf(err, "error while emitting '%s' event", eventReboot)
|
|
|
|
}
|
|
|
|
u.logf("'%s' event sent", eventReboot)
|
|
|
|
|
2018-09-20 11:20:35 +02:00
|
|
|
if waitDisconnect {
|
|
|
|
wg.Wait()
|
|
|
|
}
|
|
|
|
|
2018-09-19 17:13:45 +02:00
|
|
|
return err
|
|
|
|
|
|
|
|
}
|