This post is basically for myself :) , and will be useful for you as well. Intent of this post is to list down frequently used and most useful OSGi commands with examples. For the sake of completeness I will give a small description before stepping into OSGi commands.
Here I will show how to debug WSO2 Carbon products via OSGi console. First you have to start Carbon server with -DosgiConsole property.
./wso2server.sh -DosgiConsole
Once the server is started properly, you can start trying commands in OSGi console. Here are some mostly used OSGi commands.
1) ss
Lists down the bundles with the life-cycle state of them.
ss <bundle_name>
Searches for given bundle name and lists matching bundles.
eg. osgi> ss data
osgi> ss data
"Framework is launched."
id State Bundle
36 ACTIVE gdata-core_1.47.0.wso2v1
37 ACTIVE gdata-spreadsheet_3.0.0.wso2v1
40 ACTIVE h2-database-engine_1.2.140.wso2v3
110 ACTIVE org.eclipse.equinox.p2.metadata_2.1.0.v20110510
... ... ... ... ...
2) b <bundle_Id>
Shows the details for the specified bundle. Here bundle_id can be figured out using above ss command.
osgi> b 36
gdata-core_1.47.0.wso2v1 [36]
Id=36, Status=ACTIVE Data Root=/data/products/dss/wso2dss-3.1.1/repository/components/default/configuration/org.eclipse.osgi/bundles/36/data
"No registered services."
No services in use.
Exported packages
com.google.gdata.model.atom; version="1.47.0.wso2v1"[exported]
com.google.gdata.client.uploader; version="1.47.0.wso2v1"[exported]
com.google.gdata.model.gd; version="1.47.0.wso2v1"[exported]
Imported packages
com.google.common.collect; version="13.0.1"<com.google.guava_13.0.1 [21]>
com.sun.mirror.type; version="0.0.0"<unwired><optional>
com.sun.mirror.util; version="0.0.0"<unwired><optional>
No fragment bundles
Named class space
gdata-core; bundle-version="1.47.0.wso2v1"[provided]
No required bundles
3) p <package_name>
Shows the bundles that export and import the specified package.
eg. osgi> p org.apache.log4j
osgi> p org.apache.log4j
org.apache.log4j; version="4.2.0"<org.wso2.carbon.logging_4.2.0 [198]>
arq_1.0.0.wso2v1 [10] imports
commons-httpclient_3.1.0.wso2v2 [29] imports
spring.framework_3.1.0.wso2v1 [347] imports
webharvest-core_2.0.0.wso2v1 [353] imports
... ... ... ... ...
4) diag <bundle_id>
Shows any unsatisfied constraints of the bundle. This can be used to find out why a bundle is not going to its next life cycle state.
eg. osgi> diag 36
osgi> diag 36
reference:file:../plugins/gdata-core_1.47.0.wso2v1.jar [36]
Direct constraints which are unresolved:
Missing optionally imported package com.google.api.client.auth.oauth2_0.0.0.
Missing optionally imported package com.sun.mirror.apt_0.0.0.
Missing optionally imported package com.sun.mirror.declaration_0.0.0.
... ... ... ... ...
5) ls or list
ls -c
Lists down details of all OSGI components.
Lists down details all components of the specified bundle, or details specified OSGI components.
eg. osgi> ls -c 154 or osgi> comp 26
osgi> ls -c 154
Components in bundle org.wso2.carbon.dataservices.core:
ID Component details
26 Component[
name = dataservices.component
factory = null
autoenable = true
immediate = true
... ... ... ... ...
osgi> comp 26
Components in bundle org.wso2.carbon.dataservices.core:
ID Component details
26 Component[
name = dataservices.component
factory = null
autoenable = true
immediate = true
... ... ... ... ...
6) services
Displays registered service details.
services <service_name>
Displays specified service details.
eg. services org.eclipse.osgi.framework.log.FrameworkLog
osgi> services org.eclipse.osgi.framework.log.FrameworkLog
{org.eclipse.osgi.framework.log.FrameworkLog}={service.ranking=2147483647, service.pid=0.org.eclipse.core.runtime.internal.adaptor.EclipseLogFactory, service.vendor=Eclipse.org - Equinox, service.id=8}
"Registered by bundle:" org.eclipse.osgi_3.8.1.v20120830-144521 [0]
"Bundles using service"
org.eclipse.equinox.ds_1.4.0.v20120522-1841 [92]
org.eclipse.core.runtime_3.8.0.v20120521-2346 [82]
org.eclipse.equinox.app_1.3.100.v20120522-1841 [88]
{org.eclipse.osgi.framework.log.FrameworkLog}={service.ranking=-2147483648, performance=true, service.pid=46org.eclipse.core.runtime.internal.adaptor.EclipseLogFactory$1, service.vendor=Eclipse.org - Equinox, service.id=9}
"Registered by bundle:" org.eclipse.osgi_3.8.1.v20120830-144521 [0]
"Bundles using service"
org.eclipse.core.runtime_3.8.0.v20120521-2346 [82]
org.eclipse.equinox.app_1.3.100.v20120522-1841 [88]
... ... ... ... ...
Very helpful. Thanks a lot.
ReplyDeleteThanks for the great post.
ReplyDeleteThanks. This is very useful
ReplyDeleteA great post. Thanks.
ReplyDeleteNice one
ReplyDeleteVery useful post. Thanks.
ReplyDeleteI've always wondered how to do this. Thanks!!!
ReplyDelete