You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@karaf.apache.org by Max Spring <m2...@springdot.org> on 2019/01/12 01:13:18 UTC
custom Karaf commands and OSGi container termination
Is it possible to write a Karaf command which
(a) initiates the termination of the OSGi container and
(b) defines the exit code of the JVM process (like System.exit(exitCode) would do)?
Context: For my own development I quite often run Karaf in a shell loop so I don't have to manually restart:
$ while true; do karaf clean; sleep 2; done
I like to write my own Karaf console command so I can exit this loop based on Karaf's exit code.
Thanks!
-Max
Re: custom Karaf commands and OSGi container termination
Posted by Max Spring <m2...@springdot.org>.
Hi JB,
thanks for the pointer.
I just found the Shutdown command source [1] as a good example for how to use the SystemService.
Instead of using an exit code, I can use a temporary file as a marker created by my own "shutdown" command to have the outer loop continue or exit.
Regards,
-Max
[1] https://github.com/apache/karaf/blob/master/system/src/main/java/org/apache/karaf/system/commands/Shutdown.java
On 1/11/19 10:23 PM, Jean-Baptiste Onofré wrote:
> Hi,
>
> You can use the Karaf System service to perform a halt/shutdown:
>
> https://github.com/apache/karaf/blob/master/system/src/main/java/org/apache/karaf/system/SystemService.java
>
> However, you can't define the exit code (it's controlled internally).
>
> I think it makes more sense to exit the loop based on the concrete exit
> condition: you can have a custom "control" service that your command is
> tracking and then exit the loop (if I understood your use case).
>
> Regards
> JB
>
> On 12/01/2019 02:13, Max Spring wrote:
>> Is it possible to write a Karaf command which
>> (a) initiates the termination of the OSGi container and
>> (b) defines the exit code of the JVM process (like System.exit(exitCode)
>> would do)?
>>
>> Context: For my own development I quite often run Karaf in a shell loop
>> so I don't have to manually restart:
>>
>> $ while true; do karaf clean; sleep 2; done
>>
>> I like to write my own Karaf console command so I can exit this loop
>> based on Karaf's exit code.
>>
>> Thanks!
>> -Max
>
Re: custom Karaf commands and OSGi container termination
Posted by Jean-Baptiste Onofré <jb...@nanthrax.net>.
Hi,
You can use the Karaf System service to perform a halt/shutdown:
https://github.com/apache/karaf/blob/master/system/src/main/java/org/apache/karaf/system/SystemService.java
However, you can't define the exit code (it's controlled internally).
I think it makes more sense to exit the loop based on the concrete exit
condition: you can have a custom "control" service that your command is
tracking and then exit the loop (if I understood your use case).
Regards
JB
On 12/01/2019 02:13, Max Spring wrote:
> Is it possible to write a Karaf command which
> (a) initiates the termination of the OSGi container and
> (b) defines the exit code of the JVM process (like System.exit(exitCode)
> would do)?
>
> Context: For my own development I quite often run Karaf in a shell loop
> so I don't have to manually restart:
>
> $ while true; do karaf clean; sleep 2; done
>
> I like to write my own Karaf console command so I can exit this loop
> based on Karaf's exit code.
>
> Thanks!
> -Max
--
Jean-Baptiste Onofré
jbonofre@apache.org
http://blog.nanthrax.net
Talend - http://www.talend.com