我正在开发一个使用 apache karaf 的 opendaylight 项目。在程序开始时,我需要 karaf 安装一些功能。目前(这有效)我手动将其输入到 shell 中并安装了功能:
$ bin/karaf
Apache Karaf starting up. Press Enter to open the shell now...
100% [========================================================================]
Karaf started in 9s. Bundle stats: 409 active, 410 total
________ ________ .__ .__ .__ __
\_____ \ ______ ____ ____ \______ \ _____ ___.__.| | |__| ____ | |___/ |_
/ | \\____ \_/ __ \ / \ | | \\__ \< | || | | |/ ___\| | \ __\
/ | \ |_> > ___/| | \| ` \/ __ \\___ || |_| / /_/ > Y \ |
\_______ / __/ \___ >___| /_______ (____ / ____||____/__\___ /|___| /__|
\/|__| \/ \/ \/ \/\/ /_____/ \/
Hit '<tab>' for a list of available commands
and '[cmd] --help' for help on a specific command.
Hit '<ctrl-d>' or type 'system:shutdown' or 'logout' to shutdown OpenDaylight.
opendaylight-user@root>feature:install odl-restconf odl-mdsal-apidocs odl-openflowplugin-flow-services-rest odl-openflowplugin-app-table-miss-enforcer odl-openflowplugin-nxm-extensions odl-restconf-all odl-openflowplugin-flow-services
opendaylight-user@root>
这一切都有效。但是,我需要的是在开始时自动安装此功能。我知道有一个shell.init.script
文件,我试图将此行添加到它的底部:
feature:install odl-restconf odl-mdsal-apidocs odl-openflowplugin-flow-services-rest odl-openflowplugin-app-table-miss-enforcer odl-openflowplugin-nxm-extensions odl-restconf-all odl-openflowplugin-flow-services
但是当我这样做时,我收到以下错误:
/opt/opendaylight-0.11.0/etc/shell.init.script: Command not found: feature:install
我也知道添加 featuresBoot 元素org.apache.karaf.features.cfg
featuresBoot = odl-restconf
(为了便于测试,我将其缩短为仅一项功能)
我得到这个错误:
org.apache.felix.resolver.reason.ReasonException: Unable to resolve root: missing requirement [root] osgi.identity; osgi.identity=odl-restconf; type=karaf.feature; version="[1.10.0,1.10.0]"; filter:="(&(osgi.identity=odl-restconf)(type=karaf.feature)(version>=1.10.0)(version<=1.10.0))" [caused by: Unable to resolve odl-restconf/1.10.0: missing requirement [odl-restconf/1.10.0] osgi.identity; osgi.identity=odl-restconf-nb-rfc8040; type=karaf.feature; version="[1.10.0,1.10.0]" [caused by: Unable to resolve odl-restconf-nb-rfc8040/1.10.0: missing requirement [odl-restconf-nb-rfc8040/1.10.0] osgi.identity; osgi.identity=odl-restconf-common; type=karaf.feature; version="[1.10.0,1.10.0]" [caused by: Unable to resolve odl-restconf-common/1.10.0: missing requirement [odl-restconf-common/1.10.0] osgi.identity; osgi.identity=odl-mdsal-broker; type=karaf.feature; version="[1.10.0,1.10.0]" [caused by: Unable to resolve odl-mdsal-broker/1.10.0: missing requirement [odl-mdsal-broker/1.10.0] osgi.identity; osgi.identity=org.opendaylight.controller.sal-binding-broker-impl; type=osgi.bundle; version="[1.10.0,1.10.0]"; resolution:=mandatory [caused by: Unable to resolve org.opendaylight.controller.sal-binding-broker-impl/1.10.0: missing requirement [org.opendaylight.controller.sal-binding-broker-impl/1.10.0] osgi.wiring.package; filter:="(&(osgi.wiring.package=org.osgi.service.blueprint)(version>=1.0.0)(!(version>=2.0.0)))"]]]]]
所以,我可以说 karaf 至少承认 shell.init.script 和 org.apache.karaf.features.cfg,但是我显然使用了错误的语法。我已经用尽了谷歌搜索来找到正确的语法或找到这方面的例子。事实上,当我为这个问题做谷歌时,我得到了“使用 shell.init.script”文件的建议,没有示例或如何使用它的文档链接。
例如,这是一个类似的问题脚本,用于在 apache karaf 开始时运行命令,但答案实际上并不完整或不完整。我不知道在哪里放置建议的命令等。
无论如何,我希望这里有人可以告诉我在 shell.init.script 或 org.apache.karaf.features.cfg 中使用什么特定命令来实现这一目标。(目标是等效的初始化命令来完成我可以手动成功完成的操作,如顶部所述)
更新:我也尝试过这种类型的命令:
echo "feature:install odl-restconf odl-mdsal-apidocs odl-openflowplugin-flow-services-rest odl-openflowplugin-app-table-miss-enforcer odl-openflowplugin-nxm-extensions odl-restconf-all odl-openflowplugin-flow-services" | /opt/opendaylight-0.11.0/bin/karaf
这也没有奏效。我没有收到任何错误消息,我只知道我的 restconf 不起作用。有趣的是,我确实看到所有功能都通过管道传输到 karaf shell 中,并且 shell 似乎确实冻结了(似乎它正在处理命令),但是在光标返回给我之后就不行了。
感谢@jamo,因为他的回答让我找到了答案。我只需要将它添加到 etc/org.apache.karaf.features.cfg:
featuresBoot = odl-restconf,odl-mdsal-apidocs,odl-openflowplugin-flow-services-rest,odl-openflowplugin-app-table-miss-enforcer,odl-openflowplugin-nxm-extensions,odl-restconf-all,odl-openflowplugin-flow-services, 25921329-8d07-420b-af13-94948bf1a78d
我相信诀窍25921329-8d07-420b-af13-94948bf1a78d
是在默认的 cfg 文件中设置最终的一些十六进制值,我确保它保留在那里。