Skip to content

Instantly share code, notes, and snippets.

Created September 12, 2018 15:05
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
// Hostile Health Check
// !!! Be careful, this creates a long-running health check blocking one
// thread of the HC thread pool. Unregister the hostile health check by
// creating a file "hc-unregister" in the current working dir (usually the
// dir next to crx-quickstart folder) and running the HC one more time
File currentWorkingDir = new File(System.getProperty('user.dir'))
dynamicHealthCheck = new HealthCheck() {
def serviceRegistration
def repository
Result execute() {
FormattingResultLog log = new FormattingResultLog()"Groovy Health Check")
for(int i=1; i<10;i++) {
def hcSession = null
try {
hcSession = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));
hcSession.getNode("/").recurse { node ->
log.debug("node: "+node.getPath())
} finally {
if(hcSession!=null) {
def markerFile = new File(currentWorkingDir, "hc-unregister")
if(markerFile.exists()) {
markerFile.renameTo(new File(currentWorkingDir, "hc-unregister-done"))
return new Result(log)
resourceChangeListenerReg = bundleContext.registerService(
new Hashtable([(HealthCheck.NAME): "Hostile Health Check", (HealthCheck.TAGS): ["groovy","dashboard"]]))
dynamicHealthCheck.serviceRegistration = resourceChangeListenerReg
dynamicHealthCheck.repository = session.getRepository()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment