Пример #1
0
// Listen starts a new syslog server which runs until it receives a signal.
func Listen(exitChan, cleanupDone chan bool, drainChan chan string, bindAddr string) {
	fmt.Println("Starting syslog...")
	// If LogRoot doesn't exist, create it
	// equivalent to Python's `if not os.path.exists(filename)`
	if _, err := os.Stat(LogRoot); os.IsNotExist(err) {
		if err = os.MkdirAll(LogRoot, 0777); err != nil {
			log.Fatalf("unable to create LogRoot at %s: %v", LogRoot, err)
		}
	}
	// Create a server with one handler and run one listen goroutine
	s := syslog.NewServer()
	h := newHandler()
	s.AddHandler(h)
	s.Listen(bindAddr)
	fmt.Println("Syslog server started...")
	fmt.Println("deis-logger running")

	// Wait for terminating signal
	for {
		select {
		case <-exitChan:
			// Shutdown the server
			fmt.Println("Shutting down...")
			s.Shutdown()
			cleanupDone <- true
		case d := <-drainChan:
			h.drainURI = d
		}
	}
}
Пример #2
0
func main() {
	// Create a server with one handler and run one listen gorutine
	s := syslog.NewServer()
	s.AddHandler(newHandler())
	s.Listen("0.0.0.0:514")

	// Wait for terminating signal
	sc := make(chan os.Signal, 2)
	signal.Notify(sc, syscall.SIGTERM, syscall.SIGINT)
	<-sc

	// Shutdown the server
	log.Println("Shutdown the server...")
	s.Shutdown()
	log.Println("Server is down")
}
Пример #3
0
// Listen starts a new syslog server which runs until it receives a signal.
func Listen(signalChan chan os.Signal, cleanupDone chan bool) {
	fmt.Println("Starting syslog...")
	// Create a server with one handler and run one listen gorutine
	s := syslog.NewServer()
	s.AddHandler(newHandler())
	s.Listen("0.0.0.0:514")
	fmt.Println("Syslog server started...")
	fmt.Println("deis-logger running")

	// Wait for terminating signal
	for _ = range signalChan {
		// Shutdown the server
		fmt.Println("Shutting down...")
		s.Shutdown()
		cleanupDone <- true
	}
}
Пример #4
0
// Listen starts a new syslog server which runs until it receives a signal.
func Listen(signalChan chan os.Signal, cleanupDone chan bool) {
	fmt.Println("Starting syslog...")
	// If logRoot doesn't exist, create it
	// equivalent to Python's `if not os.path.exists(filename)`
	if _, err := os.Stat(logRoot); os.IsNotExist(err) {
		if err = os.MkdirAll(logRoot, 0777); err != nil {
			log.Fatalf("unable to create logRoot at %s", logRoot)
		}
	}
	// Create a server with one handler and run one listen gorutine
	s := syslog.NewServer()
	s.AddHandler(newHandler())
	s.Listen("0.0.0.0:514")
	fmt.Println("Syslog server started...")
	fmt.Println("deis-logger running")

	// Wait for terminating signal
	for _ = range signalChan {
		// Shutdown the server
		fmt.Println("Shutting down...")
		s.Shutdown()
		cleanupDone <- true
	}
}