def delete(self, service): """ Delete a new service object """ from agent.lib.agent_thread.service_delete import ServiceDelete try: LOG.info('Got a delete request for service ' + service) path = ServiceController.servicePath(service) if (not os.path.exists(path) and not os.path.isdir(path)): return errorResult(request, response, Errors.SERVICE_NOT_FOUND, "No service(%s) found" % service, controller=self) # see if active manifest exist for the service if manifestutil.hasActiveManifest(service): return errorResult( request, response, Errors.MANIFEST_DELETING_ACTIVE_MANIFEST, 'Active manifest exists for service %s, deactivate the manifest first before deleting service' % (service), controller=self) # start the delete thread appGlobal = config['pylons.app_globals'] deleteThread = ServiceDelete(appGlobal.threadMgr, service, path) self.injectJobCtx(deleteThread) deleteThread.start() deleteThread.threadMgrEvent.wait() return statusResult(request, response, deleteThread, controller=self) except Exception as excep: return errorResult( request, response, error=Errors.UNKNOWN_ERROR, errorMsg='Unknown error when deleting service(%s) %s - %s' % (service, str(excep), traceback.format_exc(2)), controller=self)
def cleanRogueService(): """ delete rogue services """ try: services = manifestutil.getServices() for service in services: path = manifestutil.servicePath(service) for idx in range(3): if os.path.exists(os.path.join(path, 'manifests')): break time.sleep(2) if idx == 2: appGlobal = pylons.config['pylons.app_globals'] LOG.info( 'service %s does not have manifests folder, cleanup the rogue service' % service) deleteThread = ServiceDelete(appGlobal.threadMgr, service, path) deleteThread.run() LOG.info('service %s cleaned up' % service) break except Exception: LOG.error('failed to check and cleanup rogue service' + traceback.format_exc(5))