Keeping a Java app running when SSH is closed on Google Cloud

Solution 1:

You state this:

I would like this app (which is a server) to persist after I terminate SSH, and, at any point, I would like to be able to reconnect to the console and issue commands on the server.

Slightly vague in goals, but I will take a stab at it!

To run any command as a background process on a Linux server, you should prepend the command with nohup and append & to the end.

So the final command would be:

nohup [your command] &

The nohup means the command should ignore “hang ups” and the ampersand & appended to it is a shell command that tells the system to run the command as background process. More information on it’s usage can be found here.

When you run a command like this, the process will run, you will be sent back to the command prompt and you can exit the terminal session or even go and do something else unrelated to that command during that terminal session.

Solution 2:

There are at least three ways to do this: nohup ('no hang up'), screen/tmux, or disown. It's a little unclear from you question as to your need to connect to the server and interact with the daemon after you disconnect.

If this is the case, nohup and disown won't be good matches as you release the process (though it keeps running). tmux (and also screen) will keep a term running even when you.

For more info you can see the respective pages:

man nohup
man tux

Bash disown (assuming you are running Bash, though many other shell include something similar)

Solution 3:

To detach an application from its running shell, making it persist after the shell exits, use the nohup command.

You simply prefix your normal command with nohup and it should work.

Solution 4:

Also if nohub isn't working, you can use screen:

 ssh into your remote box. 

type screen Then start the process you want.

Press Ctrl-A then Ctrl-D. 

This will detach your screen session but leave your processes running. You can now log out of the remote box.

If you want to come back later, log on again and type screen -r This will resume your screen session, and you can see the output

of

your process.