I am in the process of creating a service that, amongst other things, allows users start/stop a Golang web server at will. To get a Nodejs server running under similar circumstances I simply issue a nodejs /path/to/index.js &disown
from within a batch file that I run when the container starts up. The essential bits
ADD gorun.sh /usr/local/bin/gorun.sh
RUN chmod +x /usr/local/bin/gorun.sh
...
ENTRYPOINT ["/bin/bash"]
CMD ["/usr/local/bin/gorun.sh"]
This works perfectly, every time. In gorun.sh
I have the nodejs /path/to/index.js & disown
line.
Now that I am trying to get a Golang web server running under similar conditions I thought I would try the same approach. I modified the gorun.sh script to read
#! /bin/bash
go run /path/to/index.go & disown;
ps aux | grep go
Now here is the odd thing. I have tried to get the Go server started in two ways
- Purely as an experiment I started the Docker container with a terminal attached at called
gorun
from the terminal. The Golang server fired up right away and everything was hunkry-dory. - To better emulate the way things work in the real world - I placed a file, startgo.txt at a pre-determined location which then gets picked up by a CRON job that calls gorun. This time round, no joy - the server does not start up.
Why not just call go run /path/to/index.go & disown
from the Docker container startup script? Tried that too -same result: the server does not start up.
It is not clear to me what is happening here. Why does the Nodejs server fire up whilst the golang server refuses point blank? Why does it fire up if I run the same script from within a terminal? I'd much appreciate any help with these issues.