I've read about tmux-resurrect
, but it's still not clear to me if I can do the following:
- start
tmux
session ssh
to remote server- launch long-running code on remote host
- kill tmux server (e.g. local machine reboot)
- restore & reattach tmux session (e.g. using
tmux-resurrect
) - continue monitoring the code I launched on the remote server
Do I need to use nohup
in step 3? or can tmux-resurrect
(or some other tool) take care of it?
Best Answer
No local-side tool can do this, because of what the server "sees":
ClientAlive*
options, TCP keepalive concept – see this answer for some details).Even if you intended to use
tmux-resurrect
or another tool on the local side, the server doesn't know, doesn't care. It will terminate your long-running code unless you usednohup
or better…If you can, use
tmux
(orscreen
) on the server:tmux
session on the client.ssh
to the server.tmux
session on the server.tmux
.ssh
again.tmux
session is still there (unless something bad happened to the server in the meantime); reattach withtmux a
.I use
tmux
this way on daily basis and I think this is the right way. On my laptoptmux
sessions last for few hours at most, I shut it down every night; but I have access to a couple of servers where mytmux
sessions run for months. When I'm writing this, on one of them there'swatch df -h
process running literally for a week in atmux
session started like two months ago.