0

I have an Ubuntu 14.04 server and I am trying to start Apache Karaf from a ssh, exit the ssh and expect Karaf to remain execting. What I actually find is that as soon as the last ssh is closed/logged out, the Karaf process is terminated.

I start Karaf with the bin/start command as described here (background mode) and the docs state that this should put Karaf into the background mode, however my experience has shown this does not happen. As soon as I logout of ssh, the process dies.

I have tried using 'nohup' but again the karaf process is always killed once the last ssh is closed. I don't believe this is a problem with Karaf but some configuration of Ubuntu. I also see the same behaviour on Linux Mint.

However, Karaf DOES run as a backgorund process if I run it on a RaspberryPi, which is running Raspbian.

Is there a configuration of sshd that forces all processes started in a ssh to terminated once ALL ssh connections are ended? Whatever I try I cannot make a background process remain once I have logged out.

UPDATE Looking at the start script it uses exec :

exec "$KARAF_HOME"/bin/karaf server "$@" >> "$KARAF_REDIRECT" 2>&1 &

and thus another process is created. If I just do a bin/start file descriptors 0,1 and 2 are all directed toward `/dev/null'.

If I do nohup ./start 0<&- &>/dev/null & followed by a disown, then fd 0,1,2 of the resultant process all go to /dev/null. I noted on the RaspberryPi that fd 0,1 and 2 all state /dev/pts/0 (deleted)

  • does 'disown' have any effect? – Martin Mar 4 '15 at 22:34
  • No tried that. I've also tried using the ampersand after bin/start – Kerubu Mar 4 '15 at 22:40
0

The process might be running under the session leader, in this case the shell, once you exit the shell, all the processes under it are killed. Here are the steps you might need to follow to disown the process -

The first two steps are just for confirmation -

  1. Run jobs to see the process. If it has actually been backgrounded, it should be listed here.
  2. fg bring it to foreground - you might need to supply the job id if there are multiple jobs in backgrouund.
  3. ctrl+Z - stop process.
  4. bg - background it
  5. disown -h [id] - replace id with the job id.

Second option - daemonize the process

nohup ./scriptname 0<&- &>/dev/null &

|improve this answer|||||
  • Tried that, still doesn't work. I noticed that the process still has a controlling terminal after I do the disown. Something to do with ssh perhaps? – Kerubu Mar 4 '15 at 23:09
  • Where are STDIN and STDOUT pointing after you disown it? post output of ls -al /proc/PID/fd - replace PID with its process id. – Daniel t. Mar 4 '15 at 23:27
  • Info added to post Daniel – Kerubu Mar 5 '15 at 3:28
0

Try running this inside of a screen session and see if that does the trick.

|improve this answer|||||
  • I'm sure it will but to be honest I'm trying to avoid doing that. I'd rather know why the 'problem' exists especially as the developers of Karaf don't get the same result, although they have tried it on pure Debian. – Kerubu Mar 5 '15 at 8:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.