D
D
danforth2016-11-20 19:20:03
linux
danforth, 2016-11-20 19:20:03

How to run compiled Golang binaries under Ubuntu?

Wrote a small Go program using the net/http package. The whole task comes down to listening to port 80 and responding to requests (a la hello, world). I use the log package to handle web server startup errors. The rights to the binary: 777, the owner is the one from whom I launch.

2016/11/20 11:11:27 Cannot start and listen:  listen tcp :80: bind: permission denied

Here is a list of questions:
  1. How to run this binary correctly if it requires root rights (sudo)?
  2. How do I keep my Go program stable? I want my program to automatically start when the server starts, and also when it crashes (for example, in case of high load), so that it automatically restarts
  3. What is the best way to run websites written in Go?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
bnytiki, 2016-11-20
@danforth

It has nothing to do with Go.
Under Linux, only an application with root rights can listen on port 80 (or rather, all ports less than 1024).
For example, you can throw it through nginx. Moreover, nginx will be very good for static and for protection against slow clients.
There are tons of options. The ultimate goal is to somehow launch the application, incl. when you restart your computer.
For example, you can turn it into a daemon (carefully, a Go program does not turn into a daemon so easily https://habrahabr.ru/post/187668/ so it will be easier to use third-party ready-made packages to daemonize a program on go)
Fashionable youth method - through Docker/ rkt - also written in Go.
An even more fashionable youth method is through a scheduler designed for clusters, for example Hashicorp Nomad (which, by the way, is also written in Go).
Here it is written how to run Nomad itself https://github.com/hashicorp/nomad/tree/master/dist
If you do without Docker and Nomad - the same recipe can be used for your application.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question