func (mp *master) handleSignal(s os.Signal) { if s == mp.RestartSignal { //user initiated manual restart mp.triggerRestart() } else if s.String() == "child exited" { // will occur on every restart, ignore it } else //**during a restart** a SIGUSR1 signals //to the master process that, the file //descriptors have been released if mp.awaitingUSR1 && s == SIGUSR1 { mp.debugf("signaled, sockets ready") mp.awaitingUSR1 = false mp.descriptorsReleased <- true } else //while the slave process is running, proxy //all signals through if mp.slaveCmd != nil && mp.slaveCmd.Process != nil { mp.debugf("proxy signal (%s)", s) mp.sendSignal(s) } else //otherwise if not running, kill on CTRL+c if s == os.Interrupt { mp.debugf("interupt with no slave") os.Exit(1) } else { mp.debugf("signal discarded (%s), no slave process", s) } }
// StartSignal register signals handler. func StartSignal(store *Store, server *Server) { var ( c chan os.Signal s os.Signal ) c = make(chan os.Signal, 1) signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT, syscall.SIGSTOP) // Block until a signal is received. for { s = <-c log.Infof("get a signal %s", s.String()) switch s { case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGSTOP, syscall.SIGINT: server.Close() store.Close() return case syscall.SIGHUP: // TODO reload //return default: return } } }
func OnSignaled(sig os.Signal) bool { gLock.Lock() // prevent others entering Secretary.Log("mainpkg::Terminated", "Receive signal "+sig.String()) return false }
// Signal sends a signal to the child process, if it exists. Any errors that // occur are returned. func (r *Runner) Signal(sig os.Signal) error { if r.cmd == nil || r.cmd.Process == nil { log.Printf("[WARN] (runner) attempted to send %s to subprocess, "+ "but it does not exist ", sig.String()) return nil } return r.cmd.Process.Signal(sig) }
func (p *Process) signal(sig os.Signal) error { Logger.Debugf("Sending signal: %s to PID: %d", sig.String(), p.Pid) err := p.command.Process.Signal(syscall.SIGTERM) if err != nil { Logger.Errorf("Failed to send signal: %s to PID: %d (%T: %v)", sig.String(), p.Pid, err, err) return err } return nil }
func (p *Process) signal(sig os.Signal) error { if p.command != nil && p.command.Process != nil { logger.Debug("[Process] Sending signal: %s to PID: %d", sig.String(), p.Pid) err := p.command.Process.Signal(syscall.SIGTERM) if err != nil { logger.Error("[Process] Failed to send signal: %s to PID: %d (%T: %v)", sig.String(), p.Pid, err, err) return err } } else { logger.Debug("[Process] No process to signal yet") } return nil }
func (c *defaultController) Signal(sig os.Signal) error { if c.conn == nil { return ErrNotConnected } c.mutex.Lock() defer c.mutex.Unlock() // send command cmd := fmt.Sprintf("signal %s\n", sig.String()) if _, err := c.conn.Write([]byte(cmd)); err != nil { return err } return nil }
// Helper to ensure the signal that we send has been received so that // we don't muddy subsequent tests of the signal handler. func sendAndWaitForSignal(t *testing.T, s os.Signal) { sig := make(chan os.Signal, 1) signal.Notify(sig, s) me, _ := os.FindProcess(os.Getpid()) if err := me.Signal(s); err != nil { t.Fatalf("Got error on %s: %v\n", s.String(), err) } select { case recv := <-sig: if recv != s { t.Fatalf("Expected %v but got %v\n", s, recv) } case <-time.After(1 * time.Second): t.Fatalf("timeout waiting for %v\n", s) } }
func singalhandler(sig os.Signal, v *viper.Viper) error { switch sig { case syscall.SIGHUP: log.Println("got hup signal, now reloading conf") err := v.ReadInConfig() if err != nil { glog.Infoln("Fatal error config file ", err) return utils.ErrReadConfig } case syscall.SIGTERM: log.Println("receive SIGTERM, exit") //maybe graceful stop is better:) os.Exit(0) default: log.Println(sig) glog.Infoln("not ready to process ", sig.String()) } return nil }
// LifecycleStop logs the stop of an application func LifecycleStop(appName string, signal os.Signal, err error) { fields := logrus.Fields{ "type": "lifecycle", "event": "stop", } if signal != nil { fields["signal"] = signal.String() } if os.Getenv("BUILD_NUMBER") != "" { fields["build_number"] = os.Getenv("BUILD_NUMBER") } if err != nil { Logger.WithFields(fields). WithError(err). Errorf("stopping application: %v (%v)", appName, err) } else { Logger.WithFields(fields).Infof("stopping application: %v (%v)", appName, signal.String()) } }
func singalhandler(sig os.Signal, v *viper.Viper, dp *dialer.DialerPool) error { switch sig { case syscall.SIGHUP: log.Println("HUP") glog.Infof("got hup signal, now reloading conf\n", sig.String()) err := v.ReadInConfig() if err != nil { glog.Infoln("Fatal error config file ", err) return utils.ErrReadConfig } zones := v.GetStringMap("zones") dp.AddByZones(zones) case syscall.SIGTERM: glog.Infoln("receive SIGTERM, exit") //maybe graceful stop is better:) os.Exit(0) default: log.Println(sig) glog.Infoln("not ready to process ", sig.String()) } return nil }
func StartSignal() { var ( c chan os.Signal s os.Signal ) c = make(chan os.Signal, 1) signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT, syscall.SIGSTOP) // block until a signal is received. for { s = <-c log.Printf("Get a signal %s", s.String()) switch s { case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGSTOP, syscall.SIGINT: return case syscall.SIGHUP: // TODO reload //return default: return } } }
// Signal sends the signal to the child process, returning any errors that // occur. func (c *Child) Signal(s os.Signal) error { log.Printf("[INFO] (child) signaling %s", s.String()) c.RLock() defer c.RUnlock() return c.signal(s) }