本文整理汇总了Golang中os.Signal类的典型用法代码示例。如果您正苦于以下问题:Golang Signal类的具体用法?Golang Signal怎么用?Golang Signal使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Signal类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: handleSignal
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)
}
}
示例2: StartSignal
// 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
}
}
}
示例3: OnSignaled
func OnSignaled(sig os.Signal) bool {
gLock.Lock()
// prevent others entering
Secretary.Log("mainpkg::Terminated", "Receive signal "+sig.String())
return false
}
示例4: Signal
// 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)
}
示例5: signal
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
}
示例6: signal
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
}
示例7: Signal
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
}
示例8: sendAndWaitForSignal
// 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)
}
}
示例9: singalhandler
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
}
示例10: LifecycleStop
// 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())
}
}
示例11: StartSignal
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
}
}
}
示例12: Signal
// 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)
}