func main() { flag.Parse() // Create unix socket addr, err := net.ResolveUnixAddr("unix", *socketPath) if err != nil { log.Fatal(err) } l, err := net.ListenUnix("unix", addr) if err != nil { log.Fatal(err) } // Create server that listens on the socket s := agent.NewServer(l, &accpeter{}) // Setup signal handler to stop Server on various signals s.StopOnSignals(os.Interrupt, syscall.SIGTERM) log.Println("Server listening on", addr.String()) err = s.Serve() if err != nil { log.Fatal(err) } log.Println("Server stopped") }
func main() { // Parse flags flag.Parse() // Setup logging log.SetOutput(wlog.NewWriter(os.Stderr)) if err := wlog.SetLevelFromName(*logLevel); err != nil { log.Fatal("E! ", err) } if *socket == "" { a := agent.New(os.Stdin, os.Stdout) h := newHandler(a) a.Handler = h log.Println("I! Starting agent using STDIN/STDOUT") a.Start() err := a.Wait() if err != nil { log.Fatal("E! ", err) } log.Println("I! Agent finished") } else { // Create unix socket addr, err := net.ResolveUnixAddr("unix", *socket) if err != nil { log.Fatal("E! ", err) } l, err := net.ListenUnix("unix", addr) if err != nil { log.Fatal("E! ", err) } // Create server that listens on the socket s := agent.NewServer(l, &accepter{}) // Setup signal handler to stop Server on various signals s.StopOnSignals(os.Interrupt, syscall.SIGTERM) log.Println("I! Socket server listening on", addr.String()) err = s.Serve() if err != nil { log.Fatal("E! ", err) } log.Println("I! Socket server stopped") } }