1
0
mirror of https://github.com/peterbourgon/runsvinit.git synced 2024-12-16 14:57:04 +00:00

Fix some signal handling

This commit is contained in:
Peter Bourgon 2015-09-25 16:14:09 +02:00
parent f90dea03d7
commit 692c29d543
2 changed files with 8 additions and 7 deletions

View File

@ -6,5 +6,5 @@ runsvinit: runsvinit-linux-amd64.tgz
tar zxf $<
runsvinit-linux-amd64.tgz:
wget --quiet https://github.com/peterbourgon/runsvinit/releases/download/v1.0.0/runsvinit-linux-amd64.tgz
wget --quiet https://github.com/peterbourgon/runsvinit/releases/download/v2.0.0/runsvinit-linux-amd64.tgz

13
main.go
View File

@ -44,7 +44,7 @@ func main() {
log.Printf("%s started", runsvdir)
go gracefulShutdown(sv, supervisor.Process)
go shutdown(sv, supervisor.Process)
if err := supervisor.Wait(); err != nil {
log.Printf("%s exited with error: %v", runsvdir, err)
@ -84,10 +84,11 @@ type signaler interface {
Signal(os.Signal) error
}
func gracefulShutdown(sv string, s signaler) {
func shutdown(sv string, s signaler) {
c := make(chan os.Signal)
signal.Notify(c, syscall.SIGTERM, syscall.SIGINT)
log.Printf("received %s", <-c)
sig := <-c
log.Printf("received %s", sig)
matches, err := filepath.Glob(filepath.Join(etcService, "*"))
if err != nil {
@ -116,11 +117,11 @@ func gracefulShutdown(sv string, s signaler) {
}
log.Printf("stopped %d: %s", len(stopped), strings.Join(stopped, ", "))
log.Printf("stopping supervisor...")
if err := s.Signal(syscall.SIGTERM); err != nil {
log.Printf("stopping supervisor with signal %s...", sig)
if err := s.Signal(sig); err != nil {
log.Print(err)
}
log.Printf("graceful SIGTERM handler exiting")
log.Printf("shutdown handler exiting")
}
func cmd(path string, args ...string) *exec.Cmd {