Felix Gogo shell command examples & cheat sheet

A short overview of frequently used Felix Gogo OSGi commands with examples.

    • List all installed bundles on the system (nb. lb is short for list-bundles)
      g! lb
      START LEVEL 1
      ID|State |Level|Name
      0|Active | 0|System Bundle (4.2.1)
      1|Active | 1|Apache Felix Bundle Repository (1.6.6)
      ...
      
    • Get the current framework startlevel and then sets it. When setting a new level, all levels in between the current and the new level are activated in between.
      g! frameworklevel
      Level is 1
      g! frameworklevel 2
      g! frameworklevel
      Level is 2
      
    • For bundles which will be newly installed, set which bundle start level they will have assigned (here level 3) after install
      g! bundlelevel -i 3
    • For bundles already installed, set the bundle start level, here to level 5 for bundles 94 and 172
      g! bundlelevel -s 5 94 172
    • Set bundle 23 to be started, when the frameworklevel gets equal or above the bundle’s start level (resp stop)
      g! start 23
      g! stop 23
    • Install a bundle from a local file or a remote location. (note using a repository instead of direct links is described below)
      g! install file:///path/to/bundle.jar
      Bundle ID: 173
      g! install http://www.example.com/path/to/bundle.jar
      Bundle ID: 174
    • Update a bundle from it’s default location (here bundle 174)
      g! update 174
    • Uninstall a bundle
      g! uninstall 174
    • Get detailed infos on a bundles headers (basically the manifest content)
      g! headers 3
      Apache Felix EventAdmin (3)
      ---------------------------
      Bnd-LastModified = 1349073346464
      ...
      Bundle-SymbolicName = org.apache.felix.eventadmin
      ...
      Bundle-Version = 1.3.2
      ...
      Export-Package = org.osgi.service.event;uses:="org.osgi.framework";version="1.3"
      ...

 

  • Get list of services offered by a bundle (here bundle 2)
    g! inspect capability service 2
    org.apache.felix.configadmin [2] provides:
    ------------------------------------------
    service; org.apache.felix.cm.PersistenceManager with properties:
    service.description = Platform Filesystem Persistence Manager
    service.id = 5
    service.pid = org.apache.felix.cm.file.FilePersistenceManager
    service.ranking = -2147483648
    service.vendor = Apache Software Foundation
    Used by:
    org.apache.felix.configadmin [2]
    ...
  • Refresh bundles, so that they let go of old packages and surely use the new ones you just updated. If neceessary this will restart the bundles
    g! refresh
  • Print the System properties
    g! system:getproperties
    java.vm.version 24.51-b03
    sun.jnu.encoding ANSI_X3.4-1968
    ...

 

Interaction with an OBR, a remote OSGi bundle repository

  • List all and add remote repositories
    g! repos list
    No repository URLs are set.
    g! repos add http://updates.example.com/repository/repository.xml
    g! repos list
    http://updates.example.com/repository/repository.xml
    
  • Refresh the list of provided bundle of a repository
    repos refresh http://updates.example.com/repository/repository.xml
  • List content of remote repositories
    g! list
    My First Bundle (0.0.1.SNAPSHOT)
    My Second Bundle (0.0.3.SNAPSHOT, ...)
    
  • Install from remote repository
    g! deploy "My First Bundle"
    Target resource(s):
    -------------------
    My First Bundle (0.0.1.SNAPSHOT)
    Deploying...
    done.

Built-in commands

  • Use grep to filter output.
    g! lb | grep Felix
      1|Active     |    1|Apache Felix Configuration Admin Service (1.8.0)
     37|Active     |    1|Apache Felix Dependency Manager (3.2.0)
     ...
    

Using registered services

  • Get a service and call methods on it
    _sref = $.context getServiceReference "com.example.MyServiceInterface"
    _srv = $.context getService $_sref
    $_srv getFooBar
    ...
    $.context ungetService $_sref
    

    or with a filter

    _srefs = $.context getServiceReferences "com.example.MyServiceInterface" "(filterKey=filterValue)";
    _srv = $.context getService ($_srefs 0)
    $_srv getFooBar
    ...
    _srv = $.context ungetService ($_srefs 0)
    

Posted

in

,

by

Tags: