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.
orion/reach/reboot_now.go

44 lines
847 B
Go
Raw Normal View History

package reach
import (
"sync"
"forge.cadoles.com/Pyxis/golang-socketio"
"github.com/pkg/errors"
)
const (
eventReboot = "reboot now"
)
// RebootNow asks the ReachRS module to reboot now
func (u *Updater) RebootNow(waitDisconnect bool) error {
var err error
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)
}
}
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)
if waitDisconnect {
wg.Wait()
}
return err
}