Run Go HTTP Server in Command Line (Remote SSH)

499 views
Skip to first unread message

dc0d

unread,
May 17, 2016, 9:25:56 PM5/17/16
to golang-nuts
Not directly a Go thing, but surely all of you have deployed Go Web apps on your servers; but this really frustrated me (nix noob too - but this should not be this hard).

Why after running tmux on a remote server via ssh, program works; but after detaching sessions, it returns 404? 


In other words the behavior of the app changes by disconnecting from ssh terminal.


This is a Go(golang) program, a http server listening on a port, behind a nginx reverse proxy.

First data: everything works fine like this:


1 - I connect to the server using ssh user@server-ip,


2 - run tmux,


3 - run this script inside tmux session, by . my-script.sh:

#!/bin/sh

go build -v

exec 3>&1 4>&2
trap 'exec 2>&4 1>&3' 0 1 2 3
exec 1>/tmp/myapi.log 2>&1

export API_COUCHDB_ADMIN='admin'
export API_COUCHDB_PASSWORD='************'
export API_COUCHDB_URL='http://172.17.0.2:5984/'
# [some other env variables ...]
./myapi


4 - detach the tmux session by Ctrl-b and then d.

So far so good! Everything works fine inside a browser on address http://www.myapi-consumer.com and the ssh terminal is still open; but


5 - when I detach the ssh session (by Ctrl+a and d), the program no longer works correctly and returns 404 (it's the one sending 404).


6 - Now when I reconnect to the remote server using ssh user@server-ip then again it works as expected and I am testing the "working" part on another connection - on my cell phone with another internet connection.


What is happening?

Jakob Borg

unread,
May 18, 2016, 5:33:33 AM5/18/16
to dc0d, golang-nuts
2016-05-18 10:25 GMT+09:00 dc0d <kaveh.sh...@gmail.com>:
> What is happening?

Impossible to say for sure with the data given, but my best guess
based on similar error reports is that you have home directory
encryption and your home directory gets unmounted when you log out. If
your server is serving files from in there, those are then gone.

//jb

dc0d

unread,
May 18, 2016, 10:41:10 AM5/18/16
to golang-nuts, kaveh.sh...@gmail.com
You are right, absolutely. That was it. Thanks a lot;
Reply all
Reply to author
Forward
0 new messages