One thing I am confused about though is, when you run the application (./8.out), the terminal will sit there and listen on port 8080 until somebody accesses a page.
In Linux, every process has a parent. When you run a command in a terminal, such as ./8.out
, or find
, a new process is spawned that is the child of the shells process. When it is run without the ampersand at the end of the line (./8.out &
), the shell waits for the process to complete before it lets you input further text. If it is run with the ampersand, it lets you continue to work with the shell while the process runs in the background. However, when you close the shell, you will notice that the server process also shuts down. This is because when you terminate a parent, all of its children are also terminated.
Does the terminal need to stay up all of the time to run the web application?
If you want the process to run without a terminal, and you probably don't want this, but if you really did:
jobs
disown %jobid
The first command gives you a list of the child processes of the shell, the second command changes the parent process of %jobid to init. Init is the process that is the parent of all processes.
Does the application act like apache?
Both apache and this application listen to a port provided by the operating system, but beyond that they are dissimilar.
Does apache need to be run next to this app?
No, this application works entirely separate from Apache. Apache is in no way magical (?), on a basic level it is just listening on a port, just like this app does.
Setting this up on a server environment seems very confusing to me right now because I dont understand what the best way to do this is.
It should seem confusing. Writing web servers/services is very hard, and this is by no means an example that is meant to be deployed beyond localhost
.
Thanks for the replies. So if the Go app essentially acts like apache, is there a premade ?Go server app that has the verboseness of apache?
There are no production quality servers written in Go that I am aware of, at this point, Go is a very new language.