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/02/08 23:36:17 UTC

Karaf console session: Determine foreground vs. ssh?

In a Karaf console command is it possible to determine whether the console session is
(a) in Karaf in the foreground (where a Ctrl-D shuts down Karaf), or
(b) an ssh session attached to a Karaf process (where a Ctrl-D merely exits the ssh session)?

Context: I'm having my own quit command. It should only do "shutdown" when running in mode (a).

Thanks!
-Max

Re: Karaf console session: Determine foreground vs. ssh?

Posted by Max Spring <m2...@springdot.org>.
To answer my own question...
One crude way of determining "console is in ssh" is to look at the stacktrace from within a command's exec() method:

     private boolean isSshSession(){
         for (StackTraceElement ste : new Exception().getStackTrace()){
             if (ste.getClassName().contains(".ssh.")) return true;
         }
         return false;
     }

-Max


On 2/8/19 3:36 PM, Max Spring wrote:
> In a Karaf console command is it possible to determine whether the console session is
> (a) in Karaf in the foreground (where a Ctrl-D shuts down Karaf), or
> (b) an ssh session attached to a Karaf process (where a Ctrl-D merely exits the ssh session)?
> 
> Context: I'm having my own quit command. It should only do "shutdown" when running in mode (a).
> 
> Thanks!
> -Max
>