add hard restart for updates on *nix

reincarnates app.Restart() removed in
bbb0568cc4 as app.HardRestart().
pull/97/head
Harvey Tindall 4 years ago
parent b2b5083102
commit 0e21942cd6
No known key found for this signature in database
GPG Key ID: BBC65952848FB1A2

@ -1788,7 +1788,12 @@ func (app *appContext) ApplyUpdate(gc *gin.Context) {
respondBool(500, false, gc) respondBool(500, false, gc)
return return
} }
if PLATFORM == "windows" {
respondBool(500, true, gc)
return
}
respondBool(200, true, gc) respondBool(200, true, gc)
app.HardRestart()
} }
// @Summary Logout by deleting refresh token from cookies. // @Summary Logout by deleting refresh token from cookies.

@ -103,6 +103,7 @@
"sentAnnouncement": "Announcement sent.", "sentAnnouncement": "Announcement sent.",
"setOmbiDefaults": "Stored ombi defaults.", "setOmbiDefaults": "Stored ombi defaults.",
"updateApplied": "Update applied, please restart.", "updateApplied": "Update applied, please restart.",
"updateAppliedRefresh": "Update applied, please refresh.",
"errorConnection": "Couldn't connect to jfa-go.", "errorConnection": "Couldn't connect to jfa-go.",
"error401Unauthorized": "Unauthorized. Try refreshing the page.", "error401Unauthorized": "Unauthorized. Try refreshing the page.",
"errorSettingsAppliedNoHomescreenLayout": "Settings were applied, but applying homescreen layout may have failed.", "errorSettingsAppliedNoHomescreenLayout": "Settings were applied, but applying homescreen layout may have failed.",

@ -0,0 +1,32 @@
// +build !windows
package main
import (
"fmt"
"os"
"os/signal"
"syscall"
)
func (app *appContext) HardRestart() error {
defer func() {
if r := recover(); r != nil {
signal.Notify(app.quit, os.Interrupt)
<-app.quit
}
}()
args := os.Args
// After a single restart, args[0] gets messed up and isnt the real executable.
// JFA_DEEP tells the new process its a child, and JFA_EXEC is the real executable
if os.Getenv("JFA_DEEP") == "" {
os.Setenv("JFA_DEEP", "1")
os.Setenv("JFA_EXEC", args[0])
}
env := os.Environ()
err := syscall.Exec(os.Getenv("JFA_EXEC"), []string{""}, env)
if err != nil {
return err
}
panic(fmt.Errorf("r"))
}

@ -0,0 +1,7 @@
package main
import "fmt"
func (app *appContext) HardRestart() error {
return fmt.Errorf("hard restarts not available on windows")
}

@ -107,13 +107,20 @@ export class Updater implements updater {
_post("/config/update", null, (req: XMLHttpRequest) => { _post("/config/update", null, (req: XMLHttpRequest) => {
if (req.readyState == 4) { if (req.readyState == 4) {
toggleLoader(update); toggleLoader(update);
if (req.status != 200) { const success = req.response["success"] as Boolean;
if (req.status == 500 && success) {
window.notifications.customSuccess("applyUpdate", window.lang.notif("updateAppliedRefresh"));
} else if (req.status != 200) {
window.notifications.customError("applyUpdateError", window.lang.notif("errorApplyUpdate")); window.notifications.customError("applyUpdateError", window.lang.notif("errorApplyUpdate"));
} else { } else {
window.notifications.customSuccess("applyUpdate", window.lang.notif("updateApplied")); window.notifications.customSuccess("applyUpdate", window.lang.notif("updateAppliedRefresh"));
} }
window.modals.updateInfo.close(); window.modals.updateInfo.close();
} }
}, true, (req: XMLHttpRequest) => {
if (req.status == 0) {
window.notifications.customSuccess("applyUpdate", window.lang.notif("updateAppliedRefresh"));
}
}); });
}; };
this.checkForUpdates(() => { this.checkForUpdates(() => {

@ -440,7 +440,16 @@ func (ud *Updater) pullInternal(url string) (applyUpdate ApplyUpdate, status int
return return
} }
applyUpdate = func() error { applyUpdate = func() error {
return os.Rename(path+"_", path) oldName := path + "-" + version + "-" + commit
err := os.Rename(path, oldName)
if err != nil {
return err
}
err = os.Rename(path+"_", path)
if err != nil {
return err
}
return os.Remove(oldName)
} }
return return
} }

Loading…
Cancel
Save