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

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:


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='************'
# [some other env variables ...]

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?

  • 1
    This might be the problem (and a solution) – Ron May 15 '16 at 6:27
  • This is such a pain. There's a plethora of different solutions for this problem & yet it's simple: closing the damn terminal without touching anything by OS. Apparently it's not just the sockets but also stdin/out/err thing too. screen, tmux, nohub and no-luck! BTW Thanks for the link - though I do not get it. – Kaveh Shahbazian May 15 '16 at 21:35

The problem is that the app is serving files that reside inside home directory, which gets unmounted when disconnecting.

I've got the answer from golang-nuts group here.


This is how I am understanding.

You saying you are exiting the session or closing current terminal session. A program running and you just closed your terminal , it will no longer run.

But you are using tmux and thats all tmux for, to run the programs in background.

Try running the program by placing it from background. I mean

nohup myscript.sh &

nohup to run your script even you sign off , &[and] to push your script into background.

Hope it will help you.

  • Raja, OP is running the program in a tmux session, not the regular shell session.. – heemayl May 15 '16 at 6:24
  • @heemayl I have updated already , please reload. – rɑːdʒɑ May 15 '16 at 6:24
  • 2
    If OP is already using tmux session, then why would he need nohup and backgrounding? – heemayl May 15 '16 at 6:25
  • @heemayl I am asking him to try and I am not saying this is damn sure straight answer – rɑːdʒɑ May 15 '16 at 6:26
  • Thanks! The program works as expected after reconnecting just to the ssh. So it's already running back in tmux. Please see updates. – Kaveh Shahbazian May 15 '16 at 6:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.