You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@karaf.apache.org by Steve <de...@gmail.com> on 2014/02/04 15:24:58 UTC

Programmatically restarting Karaf while using the service wrapper

Karaf users,


A little background:

I have a bundle that periodically needs to restart its host Karaf
container.  I accomplish this by setting the “karaf.restart”
system-property to “true” and then stopping the system-bundle.  This
worked perfectly when Karaf was invoked directly via the bat files;
however, when using the service wrapper an attempt to restart simply
resulted in Karaf shutting down:

System.setProperty("karaf.restart", "true");
bundleContext.getBundle(0).stop();

I checked the mailing list archives and determined that this was
likely due to the Java Service Wrapper’s default behavior to shutdown
(http://karaf.922171.n3.nabble.com/Ability-to-self-restart-karaf-WAS-Infamous-permgen-leak-tp3589167p3590128.html).
 The advice mentioned in the previous thread suggested changing the
Java Service Wrapper’s default behavior from “SHUTDOWN” to “RESTART”
via a wrapper configuration parameter (“wrapper.on_exit.default”).
While this works, it does prevent a normal shutdown as the wrapper
will restart the application no matter what.

After digging through the Java Service Wrapper documentation further I
discovered the filter mechanism by which the wrapper monitors the
console output of an application for “triggers” upon which it can act.
 I was able to add a “trigger” to my code, via a System.out statement,
and indeed the wrapper initiates a restart while still allowing the
application to function correctly when invoked via the normal bat
files (sans-wrapper):

System.setProperty("karaf.restart", "true");
System.out.println("wrapper_restart_requested"); //wrapper restart trigger
bundleContext.getBundle(0).stop();

Question:

Are there any negative implications to the Karaf container by allowing
the wrapper to initiate a restart rather than stopping the
system-bundle directly?  Does this introduce the possibility of
leaving the container in an inconsistent/corrupt state.  I speculate
that the answer to this is “no”; however, I was hoping others
(especially core developers) might be able to give me a yes/no in
regards to the validity of this approach (or perhaps suggest an
alternative).

Thanks,
Steve

Re: Programmatically restarting Karaf while using the service wrapper

Posted by Jean-Baptiste Onofré <jb...@nanthrax.net>.
You're welcome Steve, anytime ;)

Regards
JB

On 02/04/2014 03:49 PM, Steve wrote:
> JB,
>
> Thank  you for clarifying that for me.  Your quick reply was very much
> appreciated!
>
> -Steve
>
> On Tue, Feb 4, 2014 at 9:41 AM, Jean-Baptiste Onofré <jb...@nanthrax.net> wrote:
>> Hi Steve,
>>
>> no worries, you can do a restart via the service wrapper.
>>
>> Basically, it's what you do when you do restart on the service wrapper (on
>> Windows with service restart, or on Unix with /etc/init.d/karaf restart).
>>
>> Regards
>> JB
>>
>>
>> On 02/04/2014 03:24 PM, Steve wrote:
>>>
>>> Karaf users,
>>>
>>>
>>> A little background:
>>>
>>> I have a bundle that periodically needs to restart its host Karaf
>>> container.  I accomplish this by setting the “karaf.restart”
>>> system-property to “true” and then stopping the system-bundle.  This
>>> worked perfectly when Karaf was invoked directly via the bat files;
>>> however, when using the service wrapper an attempt to restart simply
>>> resulted in Karaf shutting down:
>>>
>>> System.setProperty("karaf.restart", "true");
>>> bundleContext.getBundle(0).stop();
>>>
>>> I checked the mailing list archives and determined that this was
>>> likely due to the Java Service Wrapper’s default behavior to shutdown
>>>
>>> (http://karaf.922171.n3.nabble.com/Ability-to-self-restart-karaf-WAS-Infamous-permgen-leak-tp3589167p3590128.html).
>>>    The advice mentioned in the previous thread suggested changing the
>>> Java Service Wrapper’s default behavior from “SHUTDOWN” to “RESTART”
>>> via a wrapper configuration parameter (“wrapper.on_exit.default”).
>>> While this works, it does prevent a normal shutdown as the wrapper
>>> will restart the application no matter what.
>>>
>>> After digging through the Java Service Wrapper documentation further I
>>> discovered the filter mechanism by which the wrapper monitors the
>>> console output of an application for “triggers” upon which it can act.
>>>    I was able to add a “trigger” to my code, via a System.out statement,
>>> and indeed the wrapper initiates a restart while still allowing the
>>> application to function correctly when invoked via the normal bat
>>> files (sans-wrapper):
>>>
>>> System.setProperty("karaf.restart", "true");
>>> System.out.println("wrapper_restart_requested"); //wrapper restart trigger
>>> bundleContext.getBundle(0).stop();
>>>
>>> Question:
>>>
>>> Are there any negative implications to the Karaf container by allowing
>>> the wrapper to initiate a restart rather than stopping the
>>> system-bundle directly?  Does this introduce the possibility of
>>> leaving the container in an inconsistent/corrupt state.  I speculate
>>> that the answer to this is “no”; however, I was hoping others
>>> (especially core developers) might be able to give me a yes/no in
>>> regards to the validity of this approach (or perhaps suggest an
>>> alternative).
>>>
>>> Thanks,
>>> Steve
>>>
>>
>> --
>> Jean-Baptiste Onofré
>> jbonofre@apache.org
>> http://blog.nanthrax.net
>> Talend - http://www.talend.com

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

Re: Programmatically restarting Karaf while using the service wrapper

Posted by Steve <de...@gmail.com>.
JB,

Thank  you for clarifying that for me.  Your quick reply was very much
appreciated!

-Steve

On Tue, Feb 4, 2014 at 9:41 AM, Jean-Baptiste Onofré <jb...@nanthrax.net> wrote:
> Hi Steve,
>
> no worries, you can do a restart via the service wrapper.
>
> Basically, it's what you do when you do restart on the service wrapper (on
> Windows with service restart, or on Unix with /etc/init.d/karaf restart).
>
> Regards
> JB
>
>
> On 02/04/2014 03:24 PM, Steve wrote:
>>
>> Karaf users,
>>
>>
>> A little background:
>>
>> I have a bundle that periodically needs to restart its host Karaf
>> container.  I accomplish this by setting the “karaf.restart”
>> system-property to “true” and then stopping the system-bundle.  This
>> worked perfectly when Karaf was invoked directly via the bat files;
>> however, when using the service wrapper an attempt to restart simply
>> resulted in Karaf shutting down:
>>
>> System.setProperty("karaf.restart", "true");
>> bundleContext.getBundle(0).stop();
>>
>> I checked the mailing list archives and determined that this was
>> likely due to the Java Service Wrapper’s default behavior to shutdown
>>
>> (http://karaf.922171.n3.nabble.com/Ability-to-self-restart-karaf-WAS-Infamous-permgen-leak-tp3589167p3590128.html).
>>   The advice mentioned in the previous thread suggested changing the
>> Java Service Wrapper’s default behavior from “SHUTDOWN” to “RESTART”
>> via a wrapper configuration parameter (“wrapper.on_exit.default”).
>> While this works, it does prevent a normal shutdown as the wrapper
>> will restart the application no matter what.
>>
>> After digging through the Java Service Wrapper documentation further I
>> discovered the filter mechanism by which the wrapper monitors the
>> console output of an application for “triggers” upon which it can act.
>>   I was able to add a “trigger” to my code, via a System.out statement,
>> and indeed the wrapper initiates a restart while still allowing the
>> application to function correctly when invoked via the normal bat
>> files (sans-wrapper):
>>
>> System.setProperty("karaf.restart", "true");
>> System.out.println("wrapper_restart_requested"); //wrapper restart trigger
>> bundleContext.getBundle(0).stop();
>>
>> Question:
>>
>> Are there any negative implications to the Karaf container by allowing
>> the wrapper to initiate a restart rather than stopping the
>> system-bundle directly?  Does this introduce the possibility of
>> leaving the container in an inconsistent/corrupt state.  I speculate
>> that the answer to this is “no”; however, I was hoping others
>> (especially core developers) might be able to give me a yes/no in
>> regards to the validity of this approach (or perhaps suggest an
>> alternative).
>>
>> Thanks,
>> Steve
>>
>
> --
> Jean-Baptiste Onofré
> jbonofre@apache.org
> http://blog.nanthrax.net
> Talend - http://www.talend.com

Re: Programmatically restarting Karaf while using the service wrapper

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

no worries, you can do a restart via the service wrapper.

Basically, it's what you do when you do restart on the service wrapper 
(on Windows with service restart, or on Unix with /etc/init.d/karaf 
restart).

Regards
JB

On 02/04/2014 03:24 PM, Steve wrote:
> Karaf users,
>
>
> A little background:
>
> I have a bundle that periodically needs to restart its host Karaf
> container.  I accomplish this by setting the “karaf.restart”
> system-property to “true” and then stopping the system-bundle.  This
> worked perfectly when Karaf was invoked directly via the bat files;
> however, when using the service wrapper an attempt to restart simply
> resulted in Karaf shutting down:
>
> System.setProperty("karaf.restart", "true");
> bundleContext.getBundle(0).stop();
>
> I checked the mailing list archives and determined that this was
> likely due to the Java Service Wrapper’s default behavior to shutdown
> (http://karaf.922171.n3.nabble.com/Ability-to-self-restart-karaf-WAS-Infamous-permgen-leak-tp3589167p3590128.html).
>   The advice mentioned in the previous thread suggested changing the
> Java Service Wrapper’s default behavior from “SHUTDOWN” to “RESTART”
> via a wrapper configuration parameter (“wrapper.on_exit.default”).
> While this works, it does prevent a normal shutdown as the wrapper
> will restart the application no matter what.
>
> After digging through the Java Service Wrapper documentation further I
> discovered the filter mechanism by which the wrapper monitors the
> console output of an application for “triggers” upon which it can act.
>   I was able to add a “trigger” to my code, via a System.out statement,
> and indeed the wrapper initiates a restart while still allowing the
> application to function correctly when invoked via the normal bat
> files (sans-wrapper):
>
> System.setProperty("karaf.restart", "true");
> System.out.println("wrapper_restart_requested"); //wrapper restart trigger
> bundleContext.getBundle(0).stop();
>
> Question:
>
> Are there any negative implications to the Karaf container by allowing
> the wrapper to initiate a restart rather than stopping the
> system-bundle directly?  Does this introduce the possibility of
> leaving the container in an inconsistent/corrupt state.  I speculate
> that the answer to this is “no”; however, I was hoping others
> (especially core developers) might be able to give me a yes/no in
> regards to the validity of this approach (or perhaps suggest an
> alternative).
>
> Thanks,
> Steve
>

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