31 lines
621 B
Go
31 lines
621 B
Go
package power
|
|
|
|
import (
|
|
"net/http"
|
|
"os/exec"
|
|
|
|
"git.dubyatp.xyz/orphanage/client/httputil"
|
|
)
|
|
|
|
func RebootResponse(success bool) PowerActionResponse {
|
|
resp := PowerActionResponse{
|
|
APIVersion: APIVersion,
|
|
Action: "reboot",
|
|
Success: success,
|
|
}
|
|
return resp
|
|
}
|
|
|
|
func Reboot(next http.Handler) http.Handler {
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
cmd := exec.Command("systemctl", "reboot")
|
|
err := cmd.Run()
|
|
|
|
if err != nil {
|
|
httputil.WriteJSON(w, http.StatusOK, RebootResponse(false))
|
|
} else {
|
|
httputil.WriteJSON(w, http.StatusOK, RebootResponse(true))
|
|
}
|
|
})
|
|
}
|