backend should exit after parent

This commit is contained in:
Ted Unangst 2022-02-23 15:24:58 -05:00
parent 2a3da4bcdf
commit f43343cdcb
2 changed files with 15 additions and 2 deletions

View File

@ -74,8 +74,16 @@ func shrinkit(data []byte) (*image.Image, error) {
var backendhooks []func() var backendhooks []func()
func orphancheck() {
var b [1]byte
os.Stdin.Read(b[:])
dlog.Printf("backend shutting down")
os.Exit(0)
}
func backendServer() { func backendServer() {
dlog.Printf("backend server running") dlog.Printf("backend server running")
go orphancheck()
shrinker := new(Shrinker) shrinker := new(Shrinker)
srv := rpc.NewServer() srv := rpc.NewServer()
err := srv.Register(shrinker) err := srv.Register(shrinker)
@ -104,10 +112,15 @@ func backendServer() {
} }
func runBackendServer() { func runBackendServer() {
r, _, err := os.Pipe()
if err != nil {
elog.Panicf("can't pipe: %s", err)
}
proc := exec.Command(os.Args[0], reexecArgs("backend")...) proc := exec.Command(os.Args[0], reexecArgs("backend")...)
proc.Stdout = os.Stdout proc.Stdout = os.Stdout
proc.Stderr = os.Stderr proc.Stderr = os.Stderr
err := proc.Start() proc.Stdin = r
err = proc.Start()
if err != nil { if err != nil {
elog.Panicf("can't exec backend: %s", err) elog.Panicf("can't exec backend: %s", err)
} }

View File

@ -100,7 +100,7 @@ type Honk struct {
Mentions []Mention Mentions []Mention
Badonks []Badonk Badonks []Badonk
Wonkles string Wonkles string
Guesses template.HTML Guesses template.HTML
} }
type Badonk struct { type Badonk struct {