Last active
August 29, 2015 13:56
-
-
Save chetanmeh/8949877 to your computer and use it in GitHub Desktop.
Groovy script to remove bundle via JMX
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Licensed to the Apache Software Foundation (ASF) under one | |
* or more contributor license agreements. See the NOTICE file | |
* distributed with this work for additional information | |
* regarding copyright ownership. The ASF licenses this file | |
* to you under the Apache License, Version 2.0 (the | |
* "License"); you may not use this file except in compliance | |
* with the License. You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, | |
* software distributed under the License is distributed on an | |
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
* KIND, either express or implied. See the License for the | |
* specific language governing permissions and limitations | |
* under the License. | |
*/ | |
import javax.management.remote.JMXConnectorFactory as JmxFactory | |
import javax.management.remote.JMXServiceURL as JmxUrl | |
/** | |
* In a Sling based application at times it might happen that Repository | |
* becomes unresponsive and that might disable access to the OSGi web console. | |
* | |
* To enable access to the Web Console we would need to uninstall the | |
* webconsolesecurityprovider bundle. | |
* | |
* Following script would connect to the server and find and uninstall the | |
* Sling webconsolesecurityprovider bundle. | |
* | |
* The JVM should be configured for remote JMX access. To enable that pass following | |
* system properties | |
* | |
* com.sun.management.jmxremote | |
* com.sun.management.jmxremote.port=40321 | |
* com.sun.management.jmxremote.authenticate=false | |
* com.sun.management.jmxremote.ssl=false | |
* | |
* If you need to access it from remote system then bind JVM to non local loopback | |
* address | |
* | |
* java.rmi.server.hostname=YOUR_IP | |
*/ | |
def serverUrl = 'service:jmx:rmi:///jndi/rmi://localhost:40321/jmxrmi' | |
def server = JmxFactory.connect(new JmxUrl(serverUrl)).MBeanServerConnection | |
def fwkBean = new GroovyMBean(server, 'osgi.core:type=framework,version=1.5') | |
def bundleState = new GroovyMBean(server, 'osgi.core:type=bundleState,version=1.5') | |
def secProvider = bundleState.listBundles().findResult {id, e -> | |
if(e.get('SymbolicName') == 'org.apache.sling.extensions.webconsolesecurityprovider'){ | |
return e | |
} | |
} | |
assert secProvider | |
def id = secProvider.get('Identifier') | |
fwkBean.uninstallBundle(id) | |
println "Uninstalled bundle ${secProvider.get('SymbolicName')}" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment