Live data from Hacker News

Show HN: Restore tmux environment after a system restart

github.com

31–40 of 48 posts

Re: Show HN: Restore tmux environment after a system restart

#31
post #9
post #7

Earlier quoted context omitted.

This is the use case of Foreman. https://github.com/ddollar/foreman

or Goreman. https://github.com/mattn/goreman

Thanks for all replies. I tested this before the tmux solution, and I must say I'm impressed.

Ctrl-c worked like I was running a single app:

    16:44:33    scss | QUIT
    16:44:33 webpack | QUIT
    16:44:33   nginx | QUIT
    16:44:33      go | QUIT
This was better than expected! I suppose tmux will be preferable if one of the apps is slow to start and must be killed individually.

Re: Show HN: Restore tmux environment after a system restart

#32
post #4

BTW do people use tmux/screen to start multiple apps for development? I'm looking for a way to start nginx/sass watcher/js builder/web app in a split screen, and also stop them all with one command (which would send ctrl-c to all windows). Now I just use tabs (OSX).

yes.. http://devstack.org for openstack, does a ~20 window screen session with all the servers attached to the foreground.

Re: Show HN: Restore tmux environment after a system restart

#33
post #13
post #4

BTW do people use tmux/screen to start multiple apps for development? I'm looking for a way to start nginx/sass watcher/js builder/web app in a split screen, and also stop them all with one command (which would send ctrl-c to all windows). Now I just use tabs (OSX).

I just use a shell script based on this SO answer. https://stackoverflow.com/questions/9023164/in-bash-how-can-... The only sort of problem with it is that the output gets merged with each other. You can quite easily figure out what is what though.

See the goreman solution below: its similar but each output line has its app prefixed.

Re: Show HN: Restore tmux environment after a system restart

#34
Tangentially, anyone know how to run tmux (or screen) so that SSH sessions automatically attach?

Ie., I want every interactive connection to automatically attach to a session on the server if one exists, otherwise create one, so that when I disconnect or quit, my shell stays.

I tried to hack a solution using .zshrc a while ago, but it just didn't work properly and/or didn't handle all the edge cases, I forget exactly.

Re: Show HN: Restore tmux environment after a system restart

#35

Tangentially, anyone know how to run tmux (or screen) so that SSH sessions automatically attach? Ie., I want every interactive connection to automatically attach to a session on the server if one exists, otherwise create one, so that when I disconnect or quit, my shell stays. I tried to hack a solution using .zshrc a while ago, but it just didn't work properly and/or didn't handle all the edge cases, I forget exactly…

I have this in my .kshrc, can't recall where I found it.

  if [ "$PS1" != "" -a "${STARTED_TMUX:-x}" = x -a "${SSH_TTY:-x}" != x ]
  then
      STARTED_TMUX=1; export STARTED_TMUX
      sleep 1
      ( (tmux has-session -t remote && tmux attach-session -t remote) || (tmux new-session -s remote) ) && exit 0
      echo "tmux failed to start"
  fi

I also don't recall why the "sleep" command is in there.

Edit: to clarify, this is in the .kshrc of my work machine. When I start xterms on that machine, they just get a normal shell because $SSH_TTY is not set. When I ssh into my work machine from elsewhere, I get attached to the tmux session (if any) or one is started.

Re: Show HN: Restore tmux environment after a system restart

#36
I just installed it and played around with it for a bit - it's a really nice - but what I would kill for is something that would restore tmux server state - including the various scroll-back-buffers.

One of the few reasons I still drop out of tmux, and switch over to Terminal.app (iTerm2 might do this as well natively) - is when you have a system crash or Kernel Panic (which happens all to often with OS X -weekly basis, or daily if I'm plugging/unplugging the USB -> Serial adapters), and OS X reboots - Terminal.app restores all of my history buffers - so I don't lose any of the work in my screens.

Yes, I know script is a good way of doing this - but When you are opening a dozen or so windows, it's nice to be able to just scroll back in your history to see what you are working on.

Saving the scroll-back buffer is possible, (https://github.com/tmux-plugins/tmux-logging) - I just don't know if there is any way of restoring it.

Even if I could just do this prior to doing something dangerous (like unplugging a USB cable), that would be great.

I just noticed, that both of these plugins are by the same developer, brunosutic, - so perhaps we'll see this feature in the future. If so, super excited! :-)

Re: Show HN: Restore tmux environment after a system restart

#37
post #35

Tangentially, anyone know how to run tmux (or screen) so that SSH sessions automatically attach? Ie., I want every interactive connection to automatically attach to a session on the server if one exists, otherwise create one, so that when I disconnect or quit, my shell stays. I tried to hack a solution using .zshrc a while ago, but it just didn't work properly and/or didn't handle all the edge cases, I forget exactly…

I have this in my .kshrc, can't recall where I found it. if [ "$PS1" != "" -a "${STARTED_TMUX:-x}" = x -a "${SSH_TTY:-x}" != x ] then STARTED_TMUX=1; export STARTED_TMUX sleep 1 ( (tmux has-session -t remote && tmux attach-session -t remote) || (tmux new-session -s remote) ) && exit 0 echo "tmux failed to start" fi I also don't recall why the "sleep" command is in there. Edit: to clarify, this is in the .kshrc of my…

Thanks, I'll play around with this.
Post reply on HN