From ikrabbe.ask at gmail.com Fri Dec 29 08:45:26 2017 From: ikrabbe.ask at gmail.com (Ingo Krabbe) Date: Fri, 29 Dec 2017 09:45:26 +0100 Subject: go: Integrating a more custom server with unit Message-ID: <94674f9b-7f8b-a507-a939-680d59321f86@gmail.com> Good Morning group, I would like to try a little go web application with the unitd. The problem is, that I a) use custom TCP input (not http) b) and therefore I have unified the approach to open the http port(s) too. Actually I wrote a bit of code, that might also help you with your unit code, but what I want to know from you is, how I can add the port to unit, without using unit.ListenAndServe. http.ListenAndServe I use l := net.Listen and then http.Serve(l): ===CODE START func (srv *Server) start() { for i := range httpaddr { f := srv.runhttpserver(uint(i)) go f() } for i := range netaddr { f := srv.runnetserver(uint(i)) go f() } } func (srv *Server) runhttpserver(i uint) func() { srv.wg.Add(1) return func() { l, err := net.Listen("tcp", httpaddr[i]) if err != nil { srv.s[i] = nil srv.errchan <- err } else { srv.wg.Add(1) srv.s[i] = &http.Server{} srv.log.Printf("HTTP %d Listen %s", i, httpaddr[i]) srv.errchan <- srv.s[i].Serve(l) srv.log.Printf("finished HTTP Listen %s", httpaddr[i]) srv.wg.Done() } srv.wg.Done() } } func (srv *Server) runnetserver(i uint) func() { srv.wg.Add(1) return func() { l, err := net.Listen("tcp", netaddr[i]) if err != nil { srv.l[i] = nil srv.errchan <- err } else { srv.wg.Add(1) srv.log.Printf("NET %d Listen %s", i, netaddr[i]) srv.l[i] = l /* blocking code goes here */ srv.errchan <- l.Close() srv.log.Printf("finished NET Listen %s", netaddr[i]) srv.wg.Done() } srv.wg.Done() } } ===CODE END So having port sets httpaddr[] and netaddr[] I add all connections to a wait group and drop the application when all waitgroups are done. It should be quite simple to add the unit connection here too, but on first sight I don't understand your code. Maybe you have a hint. Best Regards, Ingo From vbart at nginx.com Fri Dec 29 12:11:08 2017 From: vbart at nginx.com (Valentin V. Bartenev) Date: Fri, 29 Dec 2017 15:11:08 +0300 Subject: go: Integrating a more custom server with unit In-Reply-To: <94674f9b-7f8b-a507-a939-680d59321f86@gmail.com> References: <94674f9b-7f8b-a507-a939-680d59321f86@gmail.com> Message-ID: <4456639.3UVyOGfQfb@vbart-laptop> On Friday, 29 December 2017 11:45:26 MSK Ingo Krabbe wrote: > Good Morning group, > > I would like to try a little go web application with the unitd. The problem is, that I > > a) use custom TCP input (not http) > b) and therefore I have unified the approach to open the http port(s) too. > > Actually I wrote a bit of code, that might also help you with your unit code, > but what I want to know from you is, how I can add the port to unit, without using unit.ListenAndServe. > > http.ListenAndServe I use l := net.Listen and then http.Serve(l): > [..] Unit interacts with the Go application using shared memory segments and a unix socket pair for synchronization, it doesn't use TCP at all. The arguments of function unit.ListenAndServe("port", nil) are ignored when the application is run by the Unit daemon. They only needed when application is run standalone (in this case it fallbacks to standard http.ListenAndServe()). The idea is that all the networking should be configured, controlled, and handled by Unit, while the application is only responsible for processing data. Current version of Unit can only handle HTTP and only for ingoing connections. In future, we plan to add support for ongoing connection and protocols like WebSockets, generic TCP streams, and UDP. Probably, something else. HTTP support is also planned to be improved, including TLS, HTTP/2, and QUIC. So, knowing that your Go application doesn't open any TCP ports to interract with Unit, are you able to integrate unit.ListenAndServe() in your code, or you need something else? Does it make sense to you? wbr, Valentin V. Bartenev From vbart at nginx.com Fri Dec 29 17:19:44 2017 From: vbart at nginx.com (Valentin V. Bartenev) Date: Fri, 29 Dec 2017 20:19:44 +0300 Subject: unit-0.3 Message-ID: <8323884.ffDVrYeQXS@vbart-laptop> Hello, I'm glad to announce that a new beta version of NGINX Unit has been released. Changes with Unit 0.3 28 Dec 2017 *) Change: the Go package name changed to "nginx/unit". *) Change: in the "limits.timeout" application option: application start time and time in queue now are not accounted. *) Feature: the "limits.requests" application option. *) Feature: application request processing latency optimization. *) Feature: HTTP keep-alive connections support. *) Feature: the "home" Python virtual environment configuration option. *) Feature: Python atexit hook support. *) Feature: various Go package improvements. *) Bugfix: various crashes fixed. With this release we have started to build more Linux packages: - https://unit.nginx.org/installation/#precompiled-packages Also, here is a new blog post about some of our plans for the near future: - https://www.nginx.com/blog/nginx-unit-progress-and-next-steps/ Happy New Year and best wishes from all of the Unit team. Stay tuned. wbr, Valentin V. Bartenev