Starting applications remotely


Forum: Other Help Topics
Topic: Starting applications remotely
started by: colinbes

Posted by colinbes on June 21 2004,02:59
Not sure what I am doing wrong or why I am getting this behaviour.

If I ssh into embedded pc with DSL distro installed and start an application, using "appname &", it exits when I exit the ssh session. If I keep the ssh session open the application continues to execute.

I have done this many times with Suse/Redhat etc and am at a bit of a loss. The ability to fire up the application remotely is critical and would appreciate some wise words of wisdom.

Posted by Grim on June 21 2004,03:59
If SuSE/RedHat continued to run an application after you logged out, then SuSE/RedHat is doing something wrong.  All of your user instantiated processes should terminate once you logout of the system.  This behaviour is part of what allows UNIX-like operating systems to capitalize on system resources and provide a multi-user OS.

In order to do what you want done, you need to install and learn to use < GNU screen >.

It's available via apt:
Code Sample
apt-get install screen


Once installed on the system you wish to secure shell into, SSH into the box and type screen at the prompt.  Now start whatever program you want to continue to run.  After the program has started, type `CTRL-D' to detach the screen session.  The program continues to run and everybody's happy.

If you want to log back into the system and stop the process, ssh into the remote machine, type `screen -D -R' to reattach the session and proceed like you had never severed the connection.

There's actually a lot of digestable information at < http://www.michael-prokop.at/screen/ >

Posted by colinbes on June 21 2004,12:09
Would be surprised if the Redhat/Suse side were wrong, what is more likely to be incorrect is my understanding of what I am doing. I thought one could spawn a process remotely and to be honest can't see why I can't (although my method could be wrong). With Suse/Redhat setup I am running tomcat apache and am able to fire these up remotely with no problem. For the learning curve I will look closer into what they are doing.

Thanks so much for your suggestion and will do as you suggest.

Posted by colinbes on June 28 2004,18:43
Simple solution at end of day.

I was trying to run my script as myscript & (to run in background). On exiting ssh, my script would also exit and application would shutdown (still need to understand why).

What I then did was to edit my script and initiate application to run in background.
i.e. changed java -jar myapp.jar in script to java -jar myapp.jar &

Now running my script myscript allows me to exit ssh and my app still runs

Posted by ripcrd6 on Aug. 18 2004,07:41
screen would make a good .dsl
Posted by el_supremo on Aug. 20 2004,04:37
Quote
I was trying to run my script as myscript & (to run in background). On exiting ssh, my script would also exit and application would shutdown (still need to understand why).

I don't know the specifics but I can perhaps point you in the right direction.
It's something to do with the way that ssh handles the SIGHUP signal when you logout.
When you run a script as "myscript &", a shell (ssh) is spawned in the background to execute the script commands.
When you put the & on the java command in the script, the script itself is still executed by the foreground ssh until it gets to the java command which it then puts in the background.
I think that when it puts a process like java in the background, it makes it immune to the SIGHUP signal so that when you log out it, the shell (ssh) will die but the java will keep running.
However, it would appear that when it spawns a copy of itself (to do "myscript &") it does not make that immune to SIGHUP and so the script dies when you logout.

Best Wishes
Pete

Powered by Ikonboard 3.1.2a
Ikonboard © 2001 Jarvis Entertainment Group, Inc.