// Install a service that starts the bundles
builder = serviceTarget.addService(Services.AUTOINSTALL_PROVIDER_COMPLETE, new AbstractService<Void>() {
public void start(StartContext context) throws StartException {
for (ServiceName serviceName : pendingServices.keySet()) {
OSGiModule moduleMetaData = pendingServices.get(serviceName);
if (moduleMetaData.getStartLevel() != null) {
@SuppressWarnings("unchecked")
ServiceController<Bundle> controller = (ServiceController<Bundle>) serviceContainer.getRequiredService(serviceName);
Bundle bundle = controller.getValue();
StartLevel startLevel = injectedStartLevel.getValue();
startLevel.setBundleStartLevel(bundle, moduleMetaData.getStartLevel());
try {
bundle.start();
} catch (BundleException ex) {
log.errorf(ex, "Cannot start bundle: %s", bundle);
}