15.8. 콘솔 사용

15.8.1. 사용 가능한 명령

콘솔에서 사용 가능한 명령 목록을 보려면 도움말 을 사용할 수 있습니다.

karaf@root()> help
bundle                            Enter the subshell
bundle:capabilities               Displays OSGi capabilities of a given bundles.
bundle:classes                    Displays a list of classes/resources contained in the bundle
bundle:diag                       Displays diagnostic information why a bundle is not Active
bundle:dynamic-import             Enables/disables dynamic-import for a given bundle.
bundle:find-class                 Locates a specified class in any deployed bundle
bundle:headers                    Displays OSGi headers of a given bundles.
bundle:id                         Gets the bundle ID.
...

간단한 설명과 함께 모든 명령 목록이 있습니다.

tab 키를 사용하여 모든 명령의 빠른 목록을 가져올 수 있습니다.

karaf@root()> Display all 294 possibilities? (y or n)
...

15.8.2. 하위 쉘 및 완료 모드

명령에는 범위와 이름이 있습니다. 예를 들어, 명령 feature:list 에는 범위가 있으며 list as name이 있습니다.

카프는 범위별로 명령을 "그룹"으로 합니다. 각 범위는 하위 쉘을 형성합니다.

정규화된 이름(scope:name)을 사용하여 명령을 직접 실행할 수 있습니다.

karaf@root()> feature:list
...

또는 하위 쉘을 입력하고 명령 컨텍스트를 하위 쉘로 입력합니다.

karaf@root()> feature
karaf@root(feature)> list

하위 쉘 이름(여기 기능)을 입력하여 직접 하위 쉘을 입력할 수 있습니다. 하위 쉘에서 다른 쉘로 직접 "switch"할 수 있습니다.

karaf@root()> feature
karaf@root(feature)> bundle
karaf@root(bundle)>

프롬프트에 () 사이의 현재 하위 쉘이 표시됩니다.

exit 명령은 상위 하위 쉘로 이동합니다.

karaf@root()> feature
karaf@root(feature)> exit
karaf@root()>

완료 모드는 tab 키의 동작과 help 명령을 정의합니다.

다음 세 가지 모드를 사용할 수 있습니다.

  • GLOBAL
  • FIRST
  • SUBSHELL

etc/org.apache.karaf.shell.cfg 파일의 completionMode 속성을 사용하여 기본 완료 모드를 정의할 수 있습니다. 기본적으로 다음을 수행할 수 있습니다.

completionMode = GLOBAL

shell:completion 명령을 사용하여 "오전기 중에"(카운트 쉘 콘솔을 사용하는 동안) 완료 모드를 변경할 수도 있습니다.

karaf@root()> shell:completion
GLOBAL
karaf@root()> shell:completion FIRST
karaf@root()> shell:completion
FIRST

shell:completion 은 사용된 현재 완료 모드에 대해 알려줍니다. 원하는 새 완료 모드를 제공할 수도 있습니다.

GLOBAL 완료 모드는 Karaf 4.0.0 (대부분의 전환 목적으로)의 기본 완료 모드입니다.

GLOBAL 모드는 실제로 하위 쉘을 사용하지 않습니다. 이전 Karaf 버전과 동일한 동작입니다.

tab 키를 입력하면 하위 쉘이 무엇이든 완료 시 모든 명령 및 모든 별칭이 표시됩니다.

karaf@root()> <TAB>
karaf@root()> Display all 273 possibilities? (y or n)
...
karaf@root()> feature
karaf@root(feature)> <TAB>
karaf@root(feature)> Display all 273 possibilities? (y or n)

첫 번째 완료 모드는 GLOBAL 완료 모드의 대안입니다.

루트 수준 하위 쉘에 tab 키를 입력하면 완료 시 모든 하위 쉘의 명령과 별칭(GLOBAL 모드)이 표시됩니다. 그러나 하위 쉘에 있는 경우 tab 키를 입력하면 완료에 현재 하위 쉘의 명령만 표시됩니다.

karaf@root()> shell:completion FIRST
karaf@root()> <TAB>
karaf@root()> Display all 273 possibilities? (y or n)
...
karaf@root()> feature
karaf@root(feature)> <TAB>
karaf@root(feature)>
info install list repo-add repo-list repo-remove uninstall version-list
karaf@root(feature)> exit
karaf@root()> log
karaf@root(log)> <TAB>
karaf@root(log)>
clear display exception-display get log set tail

SUBSHELL 완료 모드는 실제 하위 쉘 모드입니다.

루트 수준에서 Tab 키를 입력하면 완료에 하위 쉘 명령(하위 쉘로 이동)과 글로벌 별칭이 표시됩니다. 하위 쉘에 있으면 TAB 키를 입력하면 완료에 현재 하위 쉘의 명령이 표시됩니다.

karaf@root()> shell:completion SUBSHELL
karaf@root()> <TAB>
karaf@root()>
* bundle cl config dev feature help instance jaas kar la ld lde log log:list man package region service shell ssh system
karaf@root()> bundle
karaf@root(bundle)> <TAB>
karaf@root(bundle)>
capabilities classes diag dynamic-import find-class headers info install list refresh requirements resolve restart services start start-level stop
uninstall update watch
karaf@root(bundle)> exit
karaf@root()> camel
karaf@root(camel)> <TAB>
karaf@root(camel)>
backlog-tracer-dump backlog-tracer-info backlog-tracer-start backlog-tracer-stop context-info context-list context-start context-stop endpoint-list route-info route-list route-profile route-reset-stats
route-resume route-show route-start route-stop route-suspend

15.8.3. UNIX와 같은 환경

Karaf 콘솔은 환경과 같은 전체 Unix를 제공합니다.

15.8.3.1. 도움말 또는 사람

이미 사용 가능한 모든 명령을 표시하는 help 명령의 사용법을 살펴보았습니다.

그러나 help 명령을 사용하여 명령 또는 help 명령의 별칭인 man 명령에 대한 세부 정보를 가져올 수도 있습니다. 명령에 --help 옵션을 사용하여 다른 양식을 사용하여 명령 도움말을 가져올 수도 있습니다.

따라서 이러한 명령

karaf@root()> help feature:list
karaf@root()> man feature:list
karaf@root()> feature:list --help

모두 동일한 도움말 출력을 생성합니다.

DESCRIPTION
        feature:list

        Lists all existing features available from the defined repositories.

SYNTAX
        feature:list [options]

OPTIONS
        --help
                Display this help message
        -o, --ordered
                Display a list using alphabetical order
        -i, --installed
                Display a list of all installed features only
        --no-format
                Disable table rendered output

15.8.3.2. 완료

Tab 키를 입력하면 Karaf가 완료하려고 합니다.

  • 하위 쉘
  • 명령
  • 별칭
  • 명령 인수
  • 명령 옵션

15.8.3.3. 별칭

별칭은 지정된 명령과 연결된 다른 이름입니다.

shell:alias 명령은 새 별칭을 생성합니다. 예를 들어 실제 feature:list -i 명령에 대한 list- installed-features 별칭을 생성하려면 다음을 수행할 수 있습니다.

karaf@root()> alias "list-features-installed = { feature:list -i }"
karaf@root()> list-features-installed
Name       | Version | Required | State   | Repository     | Description
------------------------------------------------------------------------------------------------------------------------------
feature    | 4.0.0   | x        | Started | standard-4.0.0 | Features Support
shell      | 4.0.0   | x        | Started | standard-4.0.0 | Karaf Shell
deployer   | 4.0.0   | x        | Started | standard-4.0.0 | Karaf Deployer
bundle     | 4.0.0   | x        | Started | standard-4.0.0 | Provide Bundle support
config     | 4.0.0   | x        | Started | standard-4.0.0 | Provide OSGi ConfigAdmin support
diagnostic | 4.0.0   | x        | Started | standard-4.0.0 | Provide Diagnostic support
instance   | 4.0.0   | x        | Started | standard-4.0.0 | Provide Instance support
jaas       | 4.0.0   | x        | Started | standard-4.0.0 | Provide JAAS support
log        | 4.0.0   | x        | Started | standard-4.0.0 | Provide Log support
package    | 4.0.0   | x        | Started | standard-4.0.0 | Package commands and mbeans
service    | 4.0.0   | x        | Started | standard-4.0.0 | Provide Service support
system     | 4.0.0   | x        | Started | standard-4.0.0 | Provide System support
kar        | 4.0.0   | x        | Started | standard-4.0.0 | Provide KAR (KARaf archive) support
ssh        | 4.0.0   | x        | Started | standard-4.0.0 | Provide a SSHd server on Karaf
management | 4.0.0   | x        | Started | standard-4.0.0 | Provide a JMX MBeanServer and a set of MBeans in

로그인 시 Apache Karaf 콘솔은 별칭을 생성할 수 있는 etc/shell.init.script 파일을 읽습니다. Unix의 bashrc 또는 프로필 파일과 유사합니다.

ld = { log:display $args } ;
lde = { log:exception-display $args } ;
la = { bundle:list -t 0 $args } ;
ls = { service:list $args } ;
cl = { config:list "(service.pid=$args)" } ;
halt = { system:shutdown -h -f $args } ;
help = { *:help $args | more } ;
man = { help $args } ;
log:list = { log:get ALL } ;

여기에서는 기본적으로 사용 가능한 별칭을 확인할 수 있습니다.

  • LD는 로그를 표시하는 짧은 양식입니다( log:display 명령).
  • LDE 는 예외를 표시하는 짧은 양식입니다( log:exception-display 명령).
  • La 는 모든 번들을 나열하는 짧은 양식입니다( bundle:list -t 0 명령)
  • LS 는 모든 서비스를 나열하는 짧은 양식입니다( service:list 명령).
  • CL 은 모든 구성을 나열하는 짧은 양식입니다( config:list 명령).
  • halt 는 Apache Karaf를 종료하는 간단한 양식입니다( system:shutdown -h -f 명령).
  • 도움말은 도움말을 표시하는 간단한 양식입니다( *: help 명령까지)
  • man 은 도움말과 동일합니다( help command)
  • log:list 는 모든 로거 및 수준 ( log:get ALL 명령)을 표시합니다.

etc/shell.init.script 파일에서 고유한 별칭을 생성할 수 있습니다.

15.8.3.4. 키 바인딩

대부분의 Unix 환경에서와 마찬가지로 Karaf 콘솔은 몇 가지 주요 바인딩을 지원합니다.

  • 명령 기록에서 탐색할 화살표 키
  • CTRL-D to logout/shutdown Karaf
  • CTRL-R: 이전에 실행된 명령을 검색
  • CTRL-U를 사용하여 현재 행을 제거합니다.

15.8.3.5. Pipe

한 명령의 출력을 입력으로 다른 명령에 파이프할 수 있습니다. | 문자를 사용하는 파이프입니다.

karaf@root()> feature:list |grep -i war
pax-war                       | 4.1.4                            |          | Uninstalled | org.ops4j.pax.web-4.1.4  | Provide support of a full WebContainer
pax-war-tomcat                | 4.1.4                            |          | Uninstalled | org.ops4j.pax.web-4.1.4  |
war                           | 4.0.0                            |          | Uninstalled | standard-4.0.0           | Turn Karaf as a full WebContainer
blueprint-web                 | 4.0.0                            |          | Uninstalled | standard-4.0.0           | Provides an OSGI-aware Servlet ContextListener fo

15.8.3.6. grep, more, find, …​

Karaf 콘솔은 Unix 환경과 유사한 몇 가지 핵심 명령을 제공합니다.

  • shell:alias 는 기존 명령에 대한 별칭을 생성
  • shell:cat 은 파일 또는 URL의 내용을 표시합니다.
  • shell:clear 현재 콘솔 디스플레이를 지웁니다.
  • shell:completion 이 표시되거나 현재 완료 모드를 변경합니다.
  • shell:date 는 현재 날짜를 표시합니다 (선택적으로 형식을 사용)
  • shell:each 는 인수 목록에서 호출을 실행합니다.
  • shell:echo echoes 및 print arguments to stdout
  • shell:edit 는 현재 파일 또는 URL에서 텍스트 편집기를 호출합니다.
  • shell:env 가 쉘 세션 변수 값을 표시하거나 설정합니다.
  • shell:exec 가 시스템 명령을 실행합니다.
  • shell:grep 은 지정된 패턴과 일치하는 행을 출력합니다.
  • shell:head 는 입력의 첫 번째 행을 표시합니다.
  • shell:history 는 명령 기록을 출력합니다.
  • shell:if 를 사용하여 스크립트에서 조건(if, then, else blocks)을 사용할 수 있습니다.
  • shell:info 는 현재 Karaf 인스턴스에 대한 다양한 정보를 출력합니다.
  • shell:java 는 Java 애플리케이션을 실행합니다.
  • shell:less file pager
  • shell:logout 의 현재 세션과 쉘의 연결을 끊습니다.
  • shell:more 는 파일 페이지입니다.
  • shell:new 에서 새 Java 오브젝트 생성
  • shell: arguments 형식 및 출력
  • shell:sleep s for a bit then wakes up
  • shell:sort 쓰기는 모든 파일의 연결을 stdout에 정렬
  • shell:source 는 스크립트에 포함된 명령을 실행합니다.
  • shell:stack-traces-print 는 명령 실행 시 예외가 발생할 때 콘솔의 전체 스택 추적을 출력합니다.
  • shell:tac 은 STDIN을 캡처하고 문자열로 반환합니다.
  • shell:tail 이 입력의 마지막 행을 표시합니다.
  • shell:threads 현재 스레드를 출력합니다.
  • shell:watch 는 주기적으로 명령을 실행하고 출력을 새로 고칩니다.
  • shell:wc 는 각 파일에 대한 줄 바꿈, 단어 및 바이트 수를 출력합니다.
  • shell: condition이 True인 동안 loop

정규화된 명령 이름을 사용할 필요는 없으며 고유 한 명령 이름을 직접 사용할 수 있습니다. 따라서 'shell:head' 대신 'head'를 사용할 수 있습니다.

또한 help 명령 또는 -- help 옵션을 사용하여 이러한 명령의 세부 정보와 모든 옵션을 찾을 수 있습니다.

15.8.3.7. 스크립팅

Apache Karaf Console은 Unix의 bash 또는 csh와 유사한 전체 스크립팅 언어를 지원합니다.

(shell:each) 명령은 목록에서 반복할 수 있습니다.

karaf@root()> list = [1 2 3]; each ($list) { echo $it }
1
2
3
참고

쉘을 사용하여 동일한 루프를 작성할 수 있습니다. while 명령:

karaf@root()> a = 0 ; while { %((a+=1) <= 3) } { echo $a }
1
2
3

이전 예에서와 같이 목록을 직접 만들거나 일부 명령도 목록을 반환할 수 있습니다.

콘솔에서 $list 를 사용하여 액세스할 수 있는 이름 목록을 사용하여 "세션" 변수를 생성했습니다.

$it 변수는 현재 오브젝트(list에서 현재 반복된 값)에 해당하는 암시적 변수입니다.

[] 로 목록을 생성하면 Apache Karaf 콘솔에서 Java Cryostat를 생성합니다. 즉, Cryostat 개체(예: get 또는 size for instance)에서 사용할 수 있는 방법을 사용할 수 있습니다.

karaf@root()> list = ["Hello" world]; echo ($list get 0) ($list get 1)
Hello world

여기에서는 개체의 메서드를 직접 호출하면 (오브젝트 메서드 인수) 를 사용할 수 있습니다. 여기에서 ($list get 0)$list.get(0) 을 의미합니다. 여기서 $list 는 Cryostat입니다.

클래스 표기법은 오브젝트에 대한 세부 정보를 표시합니다.

karaf@root()> $list class
...
ProtectionDomain     ProtectionDomain  null
 null
 <no principals>
 java.security.Permissions@6521c24e (
 ("java.security.AllPermission" "<all permissions>" "<all actions>")
)


Signers              null
SimpleName           ArrayList
TypeParameters       [E]

변수를 지정된 유형으로 "캐스팅"할 수 있습니다.

karaf@root()> ("hello world" toCharArray)
[h, e, l, l, o,  , w, o, r, l, d]

실패하면 캐스팅 예외가 표시됩니다.

karaf@root()> ("hello world" toCharArray)[0]
Error executing command: [C cannot be cast to [Ljava.lang.Object;

shell:source 명령을 사용하여 스크립트를 "콜"할 수 있습니다.

karaf@root> shell:source script.txt
True!

여기서 script.txt 에는 다음이 포함됩니다.

foo = "foo"
if { $foo equals "foo" } {
  echo "True!"
}
참고

스크립트를 작성할 때 공백이 중요합니다. 예를 들어 다음 스크립트는 올바르지 않습니다.

if{ $foo equals "foo" } ...

다음과 같이 실패합니다.

karaf@root> shell:source script.txt
Error executing command: Cannot coerce echo "true!"() to any of []

if 문 뒤에 공백이 누락되어 있기 때문입니다.

별칭에 대해 etc/shell.init.script 파일에서 init 스크립트를 생성할 수 있습니다. 별칭을 사용하여 스크립트 이름을 지정할 수도 있습니다. 사실 별칭은 스크립트일 뿐입니다.

자세한 내용은 개발자 가이드의 스크립팅 섹션을 참조하십시오.

15.8.4. 보안

Apache Karaf 콘솔은 RBAC(역할 기반 액세스 제어) 보안 메커니즘을 지원합니다. 즉, 콘솔에 연결된 사용자에 따라 사용자의 그룹 및 역할에 따라 일부 명령을 실행하거나 인수에 허용되는 값을 제한할 수 있습니다.

콘솔 보안은 이 사용자 가이드의 보안 섹션에 자세히 설명되어 있습니다.