mirror of https://github.com/hrfee/jfa-go
reincarnates app.Restart() removed in
bbb0568cc4
as app.HardRestart().
pull/97/head
parent
b2b5083102
commit
0e21942cd6
@ -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")
|
||||
}
|
Loading…
Reference in new issue