func main() { srv := syslogbot.NewBot(os.Args[1]) s := syslog.NewServer() s.AddHandler(srv.SyslogHandler()) s.Listen("0.0.0.0:514") s.Listen("0.0.0.0:1514") sc := make(chan os.Signal, 2) signal.Notify(sc, syscall.SIGTERM, syscall.SIGINT) <-sc log.Println("Shutdown the server...") s.Shutdown() log.Println("Server is down") }
// newSyslogServer start a syslog server using a unix socket to listen for connections func newSyslogServer(path string) (*syslogServer, error) { glog.Infof("Starting syslog server for haproxy using %v as socket", path) // remove the socket file if exists os.Remove(path) server := &syslogServer{syslog.NewServer()} server.AddHandler(newHandler()) err := server.Listen(path) if err != nil { return nil, err } return server, nil }
func main() { flag.Parse() s := syslog.NewServer() s.AddHandler(newHandler()) s.Listen(flag.Arg(0)) // Wait for terminating signal sc := make(chan os.Signal, 2) signal.Notify(sc, syscall.SIGTERM, syscall.SIGINT) <-sc fmt.Println("Shutdown the server...") s.Shutdown() }
func main() { address := flag.String("addr", ":514", "address") flag.Parse() server := syslog.NewServer() server.AddHandler(newHandler()) server.Listen(*address) sig := make(chan os.Signal, 2) signal.Notify(sig, syscall.SIGTERM, syscall.SIGINT) <-sig server.Shutdown() fmt.Println("Server is now down.") }
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:1514") // Wait for terminating signal sc := make(chan os.Signal, 2) signal.Notify(sc, syscall.SIGTERM, syscall.SIGINT) <-sc // Shutdown the server fmt.Println("Shutdown the server...") s.Shutdown() fmt.Println("Server is down") }
// StartSyslogServer start a syslog server listening in the specified path func StartSyslogServer(path string) error { glog.Info("Starting syslog server for haproxy") s := syslog.NewServer() s.AddHandler(newHandler()) return s.Listen(path) }