完善启动关闭顺序

master
ZGGSONG 3 years ago
parent c0c9bc6402
commit eb0dc08128

@ -10,25 +10,37 @@ import (
)
func main() {
chChomrDie := make(chan struct{})
chBackendDie := make(chan struct{})
go server.Run()
cmd := startBrowser()
go startBrowser(chChomrDie, chBackendDie)
chSingal := listen2Interrupt()
select {
case <-chSingal:
cmd.Process.Kill()
for {
select {
case <-chSingal:
chBackendDie <- struct{}{}
case <-chChomrDie:
os.Exit(0)
}
}
}
func startBrowser() *exec.Cmd {
func startBrowser(chChomrDie chan struct{}, chBackendDie chan struct{}) {
chromePath := "C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe"
cmd := exec.Command(chromePath, "--app=http://127.0.0.1:"+config.GetPort()+"/static/index.html")
cmd.Start()
return cmd
go func() {
<-chBackendDie
cmd.Process.Kill()
}()
go func() {
cmd.Wait()
chChomrDie <- struct{}{}
}()
}
//监听中断信号
func listen2Interrupt() chan os.Signal {
func listen2Interrupt() <-chan os.Signal {
chSignal := make(chan os.Signal, 1)
signal.Notify(chSignal, os.Interrupt)
return chSignal

Loading…
Cancel
Save