Skip to content

Commit

Permalink
windows do not has user1 signal
Browse files Browse the repository at this point in the history
  • Loading branch information
childe committed May 21, 2020
1 parent c95707c commit 442e09a
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 34 deletions.
35 changes: 1 addition & 34 deletions gohangout.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ import (
"net/http"
_ "net/http/pprof"
"os"
"os/signal"
"runtime"
"runtime/pprof"
"sync"
"syscall"

"github.com/childe/gohangout/input"
"github.com/childe/gohangout/topology"
Expand Down Expand Up @@ -158,7 +156,7 @@ func main() {
configChannel <- config
}

ListenSignal()
listenSignal()
}

var boxes []*input.InputBox
Expand All @@ -185,34 +183,3 @@ func StopBoxesBeat() {

boxes = make([]*input.InputBox, 0)
}

func ListenSignal() {
c := make(chan os.Signal, 1)
var stop bool
signal.Notify(c, syscall.SIGINT, syscall.SIGTERM, syscall.SIGUSR1)

defer glog.Infof("listen signal stop, exit...")

for sig := range c {
glog.Infof("capture signal: %v", sig)
switch sig {
case syscall.SIGINT, syscall.SIGTERM:
StopBoxesBeat()
close(configChannel)
stop = true
case syscall.SIGUSR1:
// `kill -USR1 pid`也会触发重新加载
config, err := parseConfig(options.config)
if err != nil {
glog.Errorf("could not parse config:%s", err)
continue
}
glog.Infof("config:\n%s", removeSensitiveInfo(config))
configChannel <- config
}

if stop {
break
}
}
}
40 changes: 40 additions & 0 deletions signalhandle_darwin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package main

import (
"os"
"os/signal"
"syscall"

"github.com/golang/glog"
)

func listenSignal() {
c := make(chan os.Signal, 1)
var stop bool
signal.Notify(c, syscall.SIGINT, syscall.SIGTERM, syscall.SIGUSR1)

defer glog.Infof("listen signal stop, exit...")

for sig := range c {
glog.Infof("capture signal: %v", sig)
switch sig {
case syscall.SIGINT, syscall.SIGTERM:
StopBoxesBeat()
close(configChannel)
stop = true
case syscall.SIGUSR1:
// `kill -USR1 pid`也会触发重新加载
config, err := parseConfig(options.config)
if err != nil {
glog.Errorf("could not parse config:%s", err)
continue
}
glog.Infof("config:\n%s", removeSensitiveInfo(config))
configChannel <- config
}

if stop {
break
}
}
}
40 changes: 40 additions & 0 deletions signalhandle_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package main

import (
"os"
"os/signal"
"syscall"

"github.com/golang/glog"
)

func listenSignal() {
c := make(chan os.Signal, 1)
var stop bool
signal.Notify(c, syscall.SIGINT, syscall.SIGTERM, syscall.SIGUSR1)

defer glog.Infof("listen signal stop, exit...")

for sig := range c {
glog.Infof("capture signal: %v", sig)
switch sig {
case syscall.SIGINT, syscall.SIGTERM:
StopBoxesBeat()
close(configChannel)
stop = true
case syscall.SIGUSR1:
// `kill -USR1 pid`也会触发重新加载
config, err := parseConfig(options.config)
if err != nil {
glog.Errorf("could not parse config:%s", err)
continue
}
glog.Infof("config:\n%s", removeSensitiveInfo(config))
configChannel <- config
}

if stop {
break
}
}
}
31 changes: 31 additions & 0 deletions signalhandle_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package main

import (
"os"
"os/signal"
"syscall"

"github.com/golang/glog"
)

func listenSignal() {
c := make(chan os.Signal, 1)
var stop bool
signal.Notify(c, syscall.SIGINT, syscall.SIGTERM)

defer glog.Infof("listen signal stop, exit...")

for sig := range c {
glog.Infof("capture signal: %v", sig)
switch sig {
case syscall.SIGINT, syscall.SIGTERM:
StopBoxesBeat()
close(configChannel)
stop = true
}

if stop {
break
}
}
}

0 comments on commit 442e09a

Please sign in to comment.