mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-06-11 20:11:42 +00:00
Merge pull request #4 from resin-io/RES-1304-investigate-use-of-logfatal-and
Prevent non-fatal errors from closing the supervisor.
This commit is contained in:
@ -120,7 +120,12 @@ func inASecond(theFunc func()) {
|
|||||||
//RebootHandler Reboots the device using Systemd
|
//RebootHandler Reboots the device using Systemd
|
||||||
func RebootHandler(writer http.ResponseWriter, request *http.Request) {
|
func RebootHandler(writer http.ResponseWriter, request *http.Request) {
|
||||||
log.Println("Rebooting")
|
log.Println("Rebooting")
|
||||||
sendResponse, _ := responseSenders(writer)
|
|
||||||
|
sendResponse, sendError := responseSenders(writer)
|
||||||
|
if systemd.Logind == nil {
|
||||||
|
sendError(fmt.Errorf("Logind unavailable, cannot reboot."))
|
||||||
|
return
|
||||||
|
}
|
||||||
sendResponse("OK", "", http.StatusAccepted)
|
sendResponse("OK", "", http.StatusAccepted)
|
||||||
go inASecond(func() { systemd.Logind.Reboot(false) })
|
go inASecond(func() { systemd.Logind.Reboot(false) })
|
||||||
}
|
}
|
||||||
@ -129,7 +134,11 @@ func RebootHandler(writer http.ResponseWriter, request *http.Request) {
|
|||||||
func ShutdownHandler(writer http.ResponseWriter, request *http.Request) {
|
func ShutdownHandler(writer http.ResponseWriter, request *http.Request) {
|
||||||
log.Println("Shutting down")
|
log.Println("Shutting down")
|
||||||
|
|
||||||
sendResponse, _ := responseSenders(writer)
|
sendResponse, sendError := responseSenders(writer)
|
||||||
|
if systemd.Logind == nil {
|
||||||
|
sendError(fmt.Errorf("Logind unavailable, cannot shut down."))
|
||||||
|
return
|
||||||
|
}
|
||||||
sendResponse("OK", "", http.StatusAccepted)
|
sendResponse("OK", "", http.StatusAccepted)
|
||||||
go inASecond(func() { systemd.Logind.PowerOff(false) })
|
go inASecond(func() { systemd.Logind.PowerOff(false) })
|
||||||
}
|
}
|
||||||
@ -192,6 +201,12 @@ func VPNControl(writer http.ResponseWriter, request *http.Request) {
|
|||||||
sendResponse("Error", err.Error(), http.StatusBadRequest)
|
sendResponse("Error", err.Error(), http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if systemd.Dbus == nil {
|
||||||
|
sendError(fmt.Errorf("Systemd dbus unavailable, cannot set VPN state."))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
action := systemd.Dbus.StopUnit
|
action := systemd.Dbus.StopUnit
|
||||||
actionDescr := "VPN Disable"
|
actionDescr := "VPN Disable"
|
||||||
if body.Enable {
|
if body.Enable {
|
||||||
|
@ -17,9 +17,9 @@ var (
|
|||||||
func init() {
|
func init() {
|
||||||
var err error
|
var err error
|
||||||
if Logind, err = login1.New(); err != nil {
|
if Logind, err = login1.New(); err != nil {
|
||||||
log.Fatalf("Failed to connect to host system bus: %s", err)
|
log.Printf("Failed to connect to host system bus: %s", err)
|
||||||
}
|
}
|
||||||
if Dbus, err = dbus.New(); err != nil {
|
if Dbus, err = dbus.New(); err != nil {
|
||||||
log.Fatalf("Failed to connect to host DBUS: %s", err)
|
log.Printf("Failed to connect to host DBUS: %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user