How to start an app within a SSH session and have it continue to run if I leave?

Red Squirrel

No Lifer
May 24, 2003
67,198
12,025
126
www.anyf.ca
If I do something like:

./appname &

It runs in the background. yet, if I close the SSH console I ran that from, the app or script terminates. How do I make it so it does not terminate?

I had the impression it already worked that way, but it just so happened that the console I've been doing this stuff from always stayed open on my server. I accidentally closed it, and all hell broke loose. I can't seem to get everything started again without having to keep a SSH session active somewhere or restarting the whole server (all that stuff is in the rc.local file). Is there a way to do this?
 

Jodell88

Diamond Member
Jan 29, 2007
9,491
42
91
I would go with tmux over screen, but the same principle is behind the software.
 

Ken g6

Programming Moderator, Elite Member
Moderator
Dec 11, 1999
16,219
3,798
75
I think you guys might be over-thinking it. It sounds like he just needs "nohup".
 

Red Squirrel

No Lifer
May 24, 2003
67,198
12,025
126
www.anyf.ca
Interesting, I will give nohup that a try, thanks! Also forgot about the at command, that would work too.

Also through further experimenting I noticed if I do it with & and exit the console gracefully by typing exit, I'm ok. It's if I just X out of it.
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
I think you guys might be over-thinking it. It sounds like he just needs "nohup".

With that you lose control of the process, with screen or tmux you can resume the session and still interact with it if necessary.
 

_Rick_

Diamond Member
Apr 20, 2012
3,932
68
91
If you're an admin, you can also use the service/daemon frame work of your distribution.
 

TheRyuu

Diamond Member
Dec 3, 2005
5,479
14
81
I like tmux. Switched from screen, you can do a little more than screen but the main thing is the configuration is likely going to be far easier.

Code:
[SIZE="1"]set-option -g prefix C-a
bind-key C-a last-window
bind-key a send-prefix

set -g default-terminal "screen-256color"

set -g status-bg black
set -g status-fg white
set -g status-left-length 25
set -g status-right-length 50
set -g status-left '#[fg=green,dim][ #[fg=green,bold,nodim]#(whoami)#[fg=green,dim,nobold]@#[fg=green,bold,nodim]#H #[fg=green,dim,nobold]] #[default]'
set -g status-right '#[fg=green,dim][ #[fg=green,bold,nodim]#(cut -d " " -f 1-3 /proc/loadavg) #[fg=green,dim,nobold]] [ #[fg=green,bold,nodim]%Y-%m-%d %I:%M %p #[fg=green,dim,nobold]]'
set -g base-index 1

set-window-option -g utf8 on
set-window-option -g window-status-current-fg white
set-window-option -g window-status-current-format '#[fg=red,bold](#[fg=white,bold]#I:#W#F#[fg=red,bold])'
set-window-option -g window-status-fg green
set-window-option -g window-status-format '#I:#W#F'[/SIZE]
Code:
tmux -u new
Gets you a new tmux session.
Ctrl-A + D detaches you, then you can leave the ssh session.
Code:
tmux attach
Should be self explanatory :p
 
Last edited: