finally fixed!
This commit is contained in:
		| @ -15,7 +15,7 @@ proc_fd_map_re = re.compile(r'^.*(/[^\(]*) \(deleted\)$') | |||||||
| def _get_deleted_open_files(proc): | def _get_deleted_open_files(proc): | ||||||
|     log = logging.getLogger(sau.LOGNAME) |     log = logging.getLogger(sau.LOGNAME) | ||||||
|     files = set() |     files = set() | ||||||
|      |  | ||||||
|     # try the linux-way first |     # try the linux-way first | ||||||
|     maps_file = '/proc/{}/maps'.format(proc.pid) |     maps_file = '/proc/{}/maps'.format(proc.pid) | ||||||
|     if os.path.isfile(maps_file): |     if os.path.isfile(maps_file): | ||||||
| @ -25,7 +25,7 @@ def _get_deleted_open_files(proc): | |||||||
|                 if match: |                 if match: | ||||||
|                     files.add(match.group(1)) |                     files.add(match.group(1)) | ||||||
|         return files |         return files | ||||||
|      |  | ||||||
|     # on FreeBSD psutils open_files() helpfully returns a null path if a file |     # on FreeBSD psutils open_files() helpfully returns a null path if a file | ||||||
|     # has been deleted. |     # has been deleted. | ||||||
|     try: |     try: | ||||||
| @ -86,7 +86,7 @@ def restart_services(): | |||||||
|             # either of the above exceptions means the process has quit |             # either of the above exceptions means the process has quit | ||||||
|             continue |             continue | ||||||
|         parent = _get_top_parent(proc) |         parent = _get_top_parent(proc) | ||||||
|          |  | ||||||
|         service_procs.add(parent) |         service_procs.add(parent) | ||||||
|         retest_procs.add(proc) |         retest_procs.add(proc) | ||||||
|  |  | ||||||
| @ -95,6 +95,7 @@ def restart_services(): | |||||||
|     for proc in service_procs: |     for proc in service_procs: | ||||||
|         try: |         try: | ||||||
|             service_exe = proc.exe() |             service_exe = proc.exe() | ||||||
|  |             proc_name = proc.name() | ||||||
|         except (psutil.NoSuchProcess, psutil.ZombieProcess, psutil.AccessDenied): |         except (psutil.NoSuchProcess, psutil.ZombieProcess, psutil.AccessDenied): | ||||||
|             log.debug('{} died before it could be restarted'.format(proc)) |             log.debug('{} died before it could be restarted'.format(proc)) | ||||||
|             continue |             continue | ||||||
| @ -115,7 +116,6 @@ def restart_services(): | |||||||
|         elif policy == 'warn': |         elif policy == 'warn': | ||||||
|             log.warning('Service "{}" has open deleted files and should be restarted'.format(service)) |             log.warning('Service "{}" has open deleted files and should be restarted'.format(service)) | ||||||
|             continue |             continue | ||||||
|  |  | ||||||
|         if not policy.startswith('silent'): |         if not policy.startswith('silent'): | ||||||
|             log.warning('Restarting service {}'.format(service)) |             log.warning('Restarting service {}'.format(service)) | ||||||
|         platform.restart_service(service) |         platform.restart_service(service) | ||||||
| @ -123,15 +123,13 @@ def restart_services(): | |||||||
|     recommend_restart = False |     recommend_restart = False | ||||||
|     tested_parents = set() |     tested_parents = set() | ||||||
|     for proc in retest_procs: |     for proc in retest_procs: | ||||||
|         try: |  | ||||||
|             name = proc.name() |  | ||||||
|         except (psutil.NoSuchProcess, psutil.ZombieProcess, psutil.AccessDenied): |  | ||||||
|             log.debug('{} was successfully killed'.format(proc)) |  | ||||||
|             continue |  | ||||||
|         parent = _get_top_parent(proc) |         parent = _get_top_parent(proc) | ||||||
|  |         parent_name = parent.name() | ||||||
|         if parent in tested_parents: |         if parent in tested_parents: | ||||||
|             log.debug('{} belongs to already tested parent {}'.format(proc, parent)) |             log.debug('{} belongs to already tested parent {}'.format(proc, parent)) | ||||||
|             continue |             continue | ||||||
|  |         if not parent: | ||||||
|  |             continue | ||||||
|  |  | ||||||
|         if _get_deleted_open_files(proc): |         if _get_deleted_open_files(proc): | ||||||
|             tested_parents.add(parent) |             tested_parents.add(parent) | ||||||
| @ -141,12 +139,14 @@ def restart_services(): | |||||||
|                 recommend_restart = True |                 recommend_restart = True | ||||||
|                 continue |                 continue | ||||||
|  |  | ||||||
|             if service in services and not services[service]: |             log.debug('{} is in service {}'.format(proc, service)) | ||||||
|  |             if parent_name in services and not services[parent_name]: | ||||||
|                 log.warning('{} (parent {}) does not belong to a service and could not be restarted'.format(proc, parent)) |                 log.warning('{} (parent {}) does not belong to a service and could not be restarted'.format(proc, parent)) | ||||||
|                 recommend_restart = True |                 recommend_restart = True | ||||||
|                 continue |                 continue | ||||||
|             elif service in services: |             elif parent_name in services: | ||||||
|                 policy = _get_service_restart_policy(service) |                 policy = _get_service_restart_policy(service) | ||||||
|  |                 log.debug('service {} has policy {}'.format(service, policy)) | ||||||
|                 if policy in ('ignore', 'warn'): |                 if policy in ('ignore', 'warn'): | ||||||
|                     continue |                     continue | ||||||
|             log.warning('{} (parent {}) still has deleted files open'.format(proc, parent)) |             log.warning('{} (parent {}) still has deleted files open'.format(proc, parent)) | ||||||
| @ -195,7 +195,7 @@ def _get_service_from_proc(proc): | |||||||
|             log.error('Failed to find executable for process {}'.format(proc)) |             log.error('Failed to find executable for process {}'.format(proc)) | ||||||
|             return None |             return None | ||||||
|  |  | ||||||
|         try:  |         try: | ||||||
|             service_name = platform.identify_service_from_bin(service_exe) |             service_name = platform.identify_service_from_bin(service_exe) | ||||||
|         except sau.errors.UnknownServiceError: |         except sau.errors.UnknownServiceError: | ||||||
|             log.warning('Could not find service for process {}'.format(proc)) |             log.warning('Could not find service for process {}'.format(proc)) | ||||||
| @ -209,12 +209,12 @@ def _get_top_parent(proc): | |||||||
|     except (psutil.NoSuchProcess, psutil.ZombieProcess, psutil.AccessDenied): |     except (psutil.NoSuchProcess, psutil.ZombieProcess, psutil.AccessDenied): | ||||||
|         # either of the above exceptions means the process has quit |         # either of the above exceptions means the process has quit | ||||||
|         return None |         return None | ||||||
|      |  | ||||||
|     if len(parents) < 2: |     if len(parents) < 2: | ||||||
|         log.debug('{} is its own top parent'.format(proc)) |         log.debug('{} is its own top parent'.format(proc)) | ||||||
|         parent = proc |         parent = proc | ||||||
|     else: |     else: | ||||||
|         log.debug('{} has top parent {}'.format(proc, parents[-2])) |         log.debug('{} has top parent {}'.format(proc, parents[-2])) | ||||||
|         parent = parents[-2] |         parent = parents[-2] | ||||||
|      |  | ||||||
|     return parent |     return parent | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user