You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@karaf.apache.org by Ioannis Canellos <io...@gmail.com> on 2012/06/17 18:17:21 UTC

When executing commands using karaf's bin/shell there is a huge delay before the command exits.

Last week I tried to run some Karaf based commands outside OSGi using
Karaf's bin/shell.

I noticed something strange. The commands run normally but in many cases
the shell didn't return after the command execution and it even took like a
minute or so for the commands to return.
I think that the main reason this happens is that we don't have a
System.exit(0) after the command execution and that keeps the jvm alive for
a while.

Do you see any reason why we shouldn't have an explicit System.exit(0) ?

-- 
*Ioannis Canellos*
*
FuseSource <http://fusesource.com>

**
Blog: http://iocanel.blogspot.com
**
Twitter: iocanel
*

Re: When executing commands using karaf's bin/shell there is a huge delay before the command exits.

Posted by Ioannis Canellos <io...@gmail.com>.
> I don´t know of anything that has to be cleaned up so probably we can do
> System.exit.


Most probably commands that do things asynchronously need to wait. That's
the only case that I can think of. So far neither the core distro nor an
project providing karaf commands has such commands.

Any ideas on how to balance those needs?

-- 
*Ioannis Canellos*
*
FuseSource <http://fusesource.com>

**
Blog: http://iocanel.blogspot.com
**
Twitter: iocanel
*

Re: When executing commands using karaf's bin/shell there is a huge delay before the command exits.

Posted by Christian Schneider <ch...@die-schneider.net>.
Am 18.06.2012 14:13, schrieb Ioannis Canellos:
> Commands that are tightly couple to OSGi cannot run using bin/shell. This
> is applicable only to commands that are capable of creating anything they
> need.
>
Ok .. for these kinds of commands your proposal is fine.

Christian

-- 
Christian Schneider
http://www.liquid-reality.de

Open Source Architect
Talend Application Integration Division http://www.talend.com


Re: When executing commands using karaf's bin/shell there is a huge delay before the command exits.

Posted by Ioannis Canellos <io...@gmail.com>.
Commands that are tightly couple to OSGi cannot run using bin/shell. This
is applicable only to commands that are capable of creating anything they
need.

-- 
*Ioannis Canellos*
*
FuseSource <http://fusesource.com>

**
Blog: http://iocanel.blogspot.com
**
Twitter: iocanel
*

Re: When executing commands using karaf's bin/shell there is a huge delay before the command exits.

Posted by Christian Schneider <ch...@die-schneider.net>.
I am not sure if this is possible. Many commands need a service to work 
(at least in trunk). This service is created on bundle startup and 
destroyed on bundle stop.
It is very well possible that such a service holds some kind of context 
and only closes it on shudown.

Christian

Am 18.06.2012 13:37, schrieb Ioannis Canellos:
> I guess that the easiest way is to make sure that when a command creates a
> context, it does destroy it once its done.


-- 
Christian Schneider
http://www.liquid-reality.de

Open Source Architect
Talend Application Integration Division http://www.talend.com


Re: When executing commands using karaf's bin/shell there is a huge delay before the command exits.

Posted by Ioannis Canellos <io...@gmail.com>.
I guess that the easiest way is to make sure that when a command creates a
context, it does destroy it once its done.
-- 
*Ioannis Canellos*
*
FuseSource <http://fusesource.com>

**
Blog: http://iocanel.blogspot.com
**
Twitter: iocanel
*

Re: When executing commands using karaf's bin/shell there is a huge delay before the command exits.

Posted by Christian Schneider <ch...@die-schneider.net>.
Wrong project .. I meant we could use Pojo sr or similar:
http://code.google.com/p/pojosr/

Christian

Am 18.06.2012 13:26, schrieb Christian Schneider:
> You wrote about a context you keep open. I guess you will have to find 
> a way to close this context on exit. Probably it keeps threads running.
> I wonder if it would make sense to use iPojo for the shell to make 
> sure our OSGi based cleanup will be used outside of OSGi.
>
> Christian
>
> Am 18.06.2012 12:08, schrieb Ioannis Canellos:
>>> I don't have any problem with adding a System.exit() call, but if
>>> commands spawn threads, they should stop them cleanly anyway, so
>>> that's kinda indicating a bug somewhere to me.
>>
>> Ok, I think that the safest bet, is to keep things as is now, till I 
>> have a
>> more clear view of what is keeping the jvm alive.
>>
>
>


-- 
Christian Schneider
http://www.liquid-reality.de

Open Source Architect
Talend Application Integration Division http://www.talend.com


Re: When executing commands using karaf's bin/shell there is a huge delay before the command exits.

Posted by Christian Schneider <ch...@die-schneider.net>.
You wrote about a context you keep open. I guess you will have to find a 
way to close this context on exit. Probably it keeps threads running.
I wonder if it would make sense to use iPojo for the shell to make sure 
our OSGi based cleanup will be used outside of OSGi.

Christian

Am 18.06.2012 12:08, schrieb Ioannis Canellos:
>> I don't have any problem with adding a System.exit() call, but if
>> commands spawn threads, they should stop them cleanly anyway, so
>> that's kinda indicating a bug somewhere to me.
>
> Ok, I think that the safest bet, is to keep things as is now, till I have a
> more clear view of what is keeping the jvm alive.
>


-- 
Christian Schneider
http://www.liquid-reality.de

Open Source Architect
Talend Application Integration Division http://www.talend.com


Re: When executing commands using karaf's bin/shell there is a huge delay before the command exits.

Posted by Ioannis Canellos <io...@gmail.com>.
>
> I don't have any problem with adding a System.exit() call, but if
> commands spawn threads, they should stop them cleanly anyway, so
> that's kinda indicating a bug somewhere to me.


Ok, I think that the safest bet, is to keep things as is now, till I have a
more clear view of what is keeping the jvm alive.

-- 
*Ioannis Canellos*
*
FuseSource <http://fusesource.com>

**
Blog: http://iocanel.blogspot.com
**
Twitter: iocanel
*

Re: When executing commands using karaf's bin/shell there is a huge delay before the command exits.

Posted by Guillaume Nodet <gn...@gmail.com>.
I don't have any problem with adding a System.exit() call, but if
commands spawn threads, they should stop them cleanly anyway, so
that's kinda indicating a bug somewhere to me.

On Mon, Jun 18, 2012 at 10:31 AM, Ioannis Canellos <io...@gmail.com> wrote:
> By the way if you want to take a closer look, I was working on this:
> https://github.com/jclouds/jclouds-cli which is a jclouds interactive shell
> based on karaf and I was trying to also add support for non interactive
> mode.
>
> In the current master of the project, I use a modified version of the Main
> class that uses a System.exit as a workaround.
> --
> *Ioannis Canellos*
> *
> FuseSource <http://fusesource.com>
>
> **
> Blog: http://iocanel.blogspot.com
> **
> Twitter: iocanel
> *



-- 
------------------------
Guillaume Nodet
------------------------
Blog: http://gnodet.blogspot.com/
------------------------
FuseSource, Integration everywhere
http://fusesource.com

Re: When executing commands using karaf's bin/shell there is a huge delay before the command exits.

Posted by Ioannis Canellos <io...@gmail.com>.
By the way if you want to take a closer look, I was working on this:
https://github.com/jclouds/jclouds-cli which is a jclouds interactive shell
based on karaf and I was trying to also add support for non interactive
mode.

In the current master of the project, I use a modified version of the Main
class that uses a System.exit as a workaround.
-- 
*Ioannis Canellos*
*
FuseSource <http://fusesource.com>

**
Blog: http://iocanel.blogspot.com
**
Twitter: iocanel
*

Re: When executing commands using karaf's bin/shell there is a huge delay before the command exits.

Posted by Ioannis Canellos <io...@gmail.com>.
Yes, if I just use the shell:* commands, then they do return immediately.

I was trying to use the latest jclouds karaf commands:
https://github.com/jclouds/jclouds-karaf which were supposed to also work
outside OSGi.

They take a good one minute "after" the command execution to return.

Maybe, if those commands did a cleanup they would return immediately too
(e.g. destroy the contexts etc, but I am trying to avoid that).

-- 
*Ioannis Canellos*
*
FuseSource <http://fusesource.com>

**
Blog: http://iocanel.blogspot.com
**
Twitter: iocanel
*

Re: When executing commands using karaf's bin/shell there is a huge delay before the command exits.

Posted by Guillaume Nodet <gn...@gmail.com>.
How do you reproduce this issue ? I've tried running a simple command
multiple times, and the process exits immediately after the execution
?

On Sun, Jun 17, 2012 at 10:06 PM, Jean-Baptiste Onofré <jb...@nanthrax.net> wrote:
> Hi guys,
>
> bin/shell currently run org.apache.karaf.shell.console.Main. It's just the
> JLine implementation without the "core features". It's a tiny container to
> execute command.
>
> So IMHO, as the shell doesn't install a lot of commands (provided by
> feature), but only the "core" commands (shell:*), we can perform a
> System.exit without problem.
>
> Regards
> JB
>
>
> On 06/17/2012 09:59 PM, Christian Schneider wrote:
>>
>> I don´t know of anything that has to be cleaned up so probably we can do
>> System.exit.
>>
>> Christian
>>
>> Am 17.06.2012 21:57, schrieb Ioannis Canellos:
>>>>
>>>> System.exit is of course a way to make sure you get a fast exit. The
>>>> problem is that if something is to be cleaned up in the background it
>>>> will
>>>> simply be cut off.
>>>>
>>>> So the cleaner way is to not use System.exit and make sure our
>>>> background
>>>> threads terminate fast. This can be a bit tricky though :-)
>>>>
>>> Totally agree, the question is do we care if the threads are cleaned up
>>> properlly when using bin/shell. From what I understand the purpose is to
>>> execute commands outside OSGi, so that they can be used in scripts
>>> etc. In
>>> such case exiting fast seems really important.
>>>
>>
>>
>
> --
> Jean-Baptiste Onofré
> jbonofre@apache.org
> http://blog.nanthrax.net
> Talend - http://www.talend.com



-- 
------------------------
Guillaume Nodet
------------------------
Blog: http://gnodet.blogspot.com/
------------------------
FuseSource, Integration everywhere
http://fusesource.com

Re: When executing commands using karaf's bin/shell there is a huge delay before the command exits.

Posted by Jean-Baptiste Onofré <jb...@nanthrax.net>.
Hi guys,

bin/shell currently run org.apache.karaf.shell.console.Main. It's just 
the JLine implementation without the "core features". It's a tiny 
container to execute command.

So IMHO, as the shell doesn't install a lot of commands (provided by 
feature), but only the "core" commands (shell:*), we can perform a 
System.exit without problem.

Regards
JB

On 06/17/2012 09:59 PM, Christian Schneider wrote:
> I don´t know of anything that has to be cleaned up so probably we can do
> System.exit.
>
> Christian
>
> Am 17.06.2012 21:57, schrieb Ioannis Canellos:
>>> System.exit is of course a way to make sure you get a fast exit. The
>>> problem is that if something is to be cleaned up in the background it
>>> will
>>> simply be cut off.
>>>
>>> So the cleaner way is to not use System.exit and make sure our
>>> background
>>> threads terminate fast. This can be a bit tricky though :-)
>>>
>> Totally agree, the question is do we care if the threads are cleaned up
>> properlly when using bin/shell. From what I understand the purpose is to
>> execute commands outside OSGi, so that they can be used in scripts
>> etc. In
>> such case exiting fast seems really important.
>>
>
>

-- 
Jean-Baptiste Onofré
jbonofre@apache.org
http://blog.nanthrax.net
Talend - http://www.talend.com

Re: When executing commands using karaf's bin/shell there is a huge delay before the command exits.

Posted by Christian Schneider <ch...@die-schneider.net>.
I don´t know of anything that has to be cleaned up so probably we can do 
System.exit.

Christian

Am 17.06.2012 21:57, schrieb Ioannis Canellos:
>> System.exit is of course a way to make sure you get a fast exit. The
>> problem is that if something is to be cleaned up in the background it will
>> simply be cut off.
>>
>> So the cleaner way is to not use System.exit and make sure our background
>> threads terminate fast. This can be a bit tricky though :-)
>>
> Totally agree, the question is do we care if the threads are cleaned up
> properlly when using bin/shell. From what I understand the purpose is to
> execute commands outside OSGi, so that they can be used in scripts etc. In
> such case exiting fast seems really important.
>


-- 

Christian Schneider
http://www.liquid-reality.de

Open Source Architect
Talend Application Integration Division http://www.talend.com


Re: When executing commands using karaf's bin/shell there is a huge delay before the command exits.

Posted by Ioannis Canellos <io...@gmail.com>.
>
> System.exit is of course a way to make sure you get a fast exit. The
> problem is that if something is to be cleaned up in the background it will
> simply be cut off.
>
> So the cleaner way is to not use System.exit and make sure our background
> threads terminate fast. This can be a bit tricky though :-)
>

Totally agree, the question is do we care if the threads are cleaned up
properlly when using bin/shell. From what I understand the purpose is to
execute commands outside OSGi, so that they can be used in scripts etc. In
such case exiting fast seems really important.

-- 
*Ioannis Canellos*
*
FuseSource <http://fusesource.com>

**
Blog: http://iocanel.blogspot.com
**
Twitter: iocanel
*

Re: When executing commands using karaf's bin/shell there is a huge delay before the command exits.

Posted by Christian Schneider <ch...@die-schneider.net>.
System.exit is of course a way to make sure you get a fast exit. The 
problem is that if something is to be cleaned up in the background it 
will simply be cut off.

So the cleaner way is to not use System.exit and make sure our 
background threads terminate fast. This can be a bit tricky though :-)

Christian

Am 17.06.2012 18:17, schrieb Ioannis Canellos:
> Last week I tried to run some Karaf based commands outside OSGi using
> Karaf's bin/shell.
>
> I noticed something strange. The commands run normally but in many cases
> the shell didn't return after the command execution and it even took like a
> minute or so for the commands to return.
> I think that the main reason this happens is that we don't have a
> System.exit(0) after the command execution and that keeps the jvm alive for
> a while.
>
> Do you see any reason why we shouldn't have an explicit System.exit(0) ?
>


-- 

Christian Schneider
http://www.liquid-reality.de

Open Source Architect
Talend Application Integration Division http://www.talend.com