當前位置: 首頁>>代碼示例>>Golang>>正文


Golang os.Signal類代碼示例

本文整理匯總了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)
	}
}
開發者ID:shaunstanislaus,項目名稱:overseer,代碼行數:29,代碼來源:proc_master.go

示例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
		}
	}
}
開發者ID:Terry-Mao,項目名稱:bfs,代碼行數:26,代碼來源:signal.go

示例3: OnSignaled

func OnSignaled(sig os.Signal) bool {
	gLock.Lock()
	// prevent others entering
	Secretary.Log("mainpkg::Terminated", "Receive signal "+sig.String())

	return false
}
開發者ID:levythu,項目名稱:swiftlayerC-Go,代碼行數:7,代碼來源:terminating.go

示例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)
}
開發者ID:mdelagrange,項目名稱:envconsul,代碼行數:11,代碼來源:runner.go

示例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
}
開發者ID:handsomefaces,項目名稱:buildbox-agent,代碼行數:11,代碼來源:script.go

示例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
}
開發者ID:nikyoudale,項目名稱:agent,代碼行數:15,代碼來源:process.go

示例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
}
開發者ID:nklizhe,項目名稱:ovpnutil,代碼行數:15,代碼來源:management.go

示例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)
	}
}
開發者ID:zofuthan,項目名稱:containerbuddy,代碼行數:18,代碼來源:signals_test.go

示例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
}
開發者ID:detailyang,項目名稱:zoneproxy,代碼行數:20,代碼來源:main.go

示例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())
	}
}
開發者ID:tarent,項目名稱:lib-compose,代碼行數:22,代碼來源:logger.go

示例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
		}
	}
}
開發者ID:huangered,項目名稱:beaver,代碼行數:24,代碼來源:signal.go

示例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)
}
開發者ID:yuanfeng0905,項目名稱:consul-template,代碼行數:8,代碼來源:child.go


注:本文中的os.Signal類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。