update: introduce a /bootonly handler for bakery

Regular updates hit /boot, /root, then /switch.

bakery only updates /boot, so we need to take care of persisting the active root
partition across /boot updates.
This commit is contained in:
Michael Stapelberg 2018-05-17 09:08:25 +02:00
parent 50b9390a43
commit 6063608b2b

View File

@ -130,6 +130,17 @@ func initUpdate() error {
http.HandleFunc("/update/boot", nonConcurrentUpdateHandler("/dev/mmcblk0p1"))
http.HandleFunc("/update/root", nonConcurrentUpdateHandler("/dev/mmcblk0p"+inactiveRootPartition))
http.HandleFunc("/update/switch", nonConcurrentSwitchHandler(inactiveRootPartition))
// bakery updates only the boot partition, which would reset the active root
// partition to 2.
updateHandler := nonConcurrentUpdateHandler("/dev/mmcblk0p1")
http.HandleFunc("/update/bootonly", func(w http.ResponseWriter, r *http.Request) {
updateHandler(w, r)
if err := switchRootPartition(rootPartition); err != nil {
log.Printf("switching root partition to %q failed: %v", rootPartition, err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
})
http.HandleFunc("/reboot", func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
http.Error(w, "expected a POST request", http.StatusBadRequest)