func signalHandler()

in scripts/testpop/testpop.go [133:166]


func signalHandler(rp *ringpop.Ringpop, interactive bool) {
	sigchan := make(chan os.Signal, 1)

	var s os.Signal
	if interactive {
		s = syscall.SIGINT
	} else {
		s = syscall.SIGTERM
	}

	signal.Notify(sigchan, s)

	// wait on a signal
	receivedSignal := <-sigchan
	log.Printf("received signal %q, initiating self eviction\n", receivedSignal)

	if interactive {
		log.Error("triggered graceful shutdown. Press Ctrl+C again to force exit.")
		go func() {
			// exit on second signal
			<-sigchan
			log.Error("Force exiting...")
			os.Exit(2)
		}()
	}

	err := rp.SelfEvict()
	if err != nil {
		log.Errorf("Error during self-eviction: %v\n", err)
		os.Exit(1)
	}

	os.Exit(0)
}