fixed detection of deleted files on linux
This commit is contained in:
parent
6f19bf71ca
commit
d08fa867d4
11
bin/sau
11
bin/sau
@ -5,6 +5,7 @@ import logging.handlers
|
|||||||
import os
|
import os
|
||||||
import platform
|
import platform
|
||||||
import sys
|
import sys
|
||||||
|
import time
|
||||||
|
|
||||||
import sau
|
import sau
|
||||||
import sau.services
|
import sau.services
|
||||||
@ -14,14 +15,20 @@ import sau.platforms
|
|||||||
def main():
|
def main():
|
||||||
conf = sau.config
|
conf = sau.config
|
||||||
log = logging.getLogger(sau.LOGNAME)
|
log = logging.getLogger(sau.LOGNAME)
|
||||||
reboot_required = False
|
|
||||||
platform = sau.platforms.get_platform()
|
platform = sau.platforms.get_platform()
|
||||||
#reboot_required = platform.system_upgrade()
|
reboot_required = platform.system_upgrade()
|
||||||
platform.pkg_upgrade()
|
platform.pkg_upgrade()
|
||||||
|
|
||||||
reboot_recommended = sau.services.restart_services()
|
reboot_recommended = sau.services.restart_services()
|
||||||
if conf.getboolean('default', 'do_reboot', fallback=False):
|
if conf.getboolean('default', 'do_reboot', fallback=False):
|
||||||
|
if reboot_required:
|
||||||
|
log.warning('Rebooting because of a system upgrade')
|
||||||
|
elif reboot_recommended:
|
||||||
|
log.warning('Rebooting because service restarts did not close all deleted files')
|
||||||
if reboot_required or reboot_recommended:
|
if reboot_required or reboot_recommended:
|
||||||
|
# sleep a little to make sure the above log-messages has reached
|
||||||
|
# syslog before we reboot
|
||||||
|
time.sleep(1)
|
||||||
os.system('/sbin/reboot')
|
os.system('/sbin/reboot')
|
||||||
|
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@ def identify_service_from_bin(exe):
|
|||||||
|
|
||||||
def restart_service(service):
|
def restart_service(service):
|
||||||
log = logging.getLogger(sau.LOGNAME)
|
log = logging.getLogger(sau.LOGNAME)
|
||||||
cmd = [ SERVICE_PATH, service, 'restart' ]
|
cmd = [ RC_SERVICE_PATH, service, 'restart' ]
|
||||||
log.debug('Executing "{}"'.format(' '.join(cmd)))
|
log.debug('Executing "{}"'.format(' '.join(cmd)))
|
||||||
proc = subprocess.Popen(
|
proc = subprocess.Popen(
|
||||||
cmd,
|
cmd,
|
||||||
@ -92,6 +92,7 @@ def restart_service(service):
|
|||||||
log.info("restarted service {}".format(service))
|
log.info("restarted service {}".format(service))
|
||||||
|
|
||||||
def system_upgrade():
|
def system_upgrade():
|
||||||
|
log = logging.getLogger(sau.LOGNAME)
|
||||||
log.debug('Gentoo has no concept of system upgrade, ignoring...')
|
log.debug('Gentoo has no concept of system upgrade, ignoring...')
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -179,18 +180,11 @@ def _get_upgradable_packages_eix():
|
|||||||
|
|
||||||
return upgradable
|
return upgradable
|
||||||
|
|
||||||
def _get_upgradable_packages():
|
|
||||||
log = loggin.getLogger(sau.LOGNAME)
|
|
||||||
conf = sau.config
|
|
||||||
|
|
||||||
pretend_re = re.compile(r'^\[ebuild ([^\]]*)\] ([^ ]+)( \[([^\])]\])?')
|
|
||||||
|
|
||||||
def pkg_upgrade():
|
def pkg_upgrade():
|
||||||
log = logging.getLogger(sau.LOGNAME)
|
log = logging.getLogger(sau.LOGNAME)
|
||||||
conf = sau.config
|
conf = sau.config
|
||||||
|
|
||||||
_sync_portage()
|
_sync_portage()
|
||||||
#packages = _get_upgradable_packages()
|
|
||||||
|
|
||||||
# [ebuild U ] media-plugins/alsa-plugins-1.1.8 [1.1.6]
|
# [ebuild U ] media-plugins/alsa-plugins-1.1.8 [1.1.6]
|
||||||
pretend_re = re.compile(r'^\[ebuild ([^\]]*)\] ([^ ]+)( \[[^\]]+\])?')
|
pretend_re = re.compile(r'^\[ebuild ([^\]]*)\] ([^ ]+)( \[[^\]]+\])?')
|
||||||
@ -240,7 +234,7 @@ def pkg_upgrade():
|
|||||||
min_diff = conf.getint('packages', name, fallback=default_version_diff)
|
min_diff = conf.getint('packages', name, fallback=default_version_diff)
|
||||||
diff = sau.helpers.version_diff(version, old)
|
diff = sau.helpers.version_diff(version, old)
|
||||||
if min_diff >= diff:
|
if min_diff >= diff:
|
||||||
log.debug('{}-{} -> {} configured level {} >= pkg level {}'.format(name, old, version, min_diff, diff))
|
log.info('{}-{} -> {} configured level {} >= pkg level {}'.format(name, old, version, min_diff, diff))
|
||||||
else:
|
else:
|
||||||
log.warning('{}-{} -> {} configured level {} < pkg level {}'.format(name, old, version, min_diff, diff))
|
log.warning('{}-{} -> {} configured level {} < pkg level {}'.format(name, old, version, min_diff, diff))
|
||||||
do_rebuild = False
|
do_rebuild = False
|
||||||
@ -259,8 +253,8 @@ def pkg_upgrade():
|
|||||||
out = out.decode('utf-8')
|
out = out.decode('utf-8')
|
||||||
err = err.decode('utf-8')
|
err = err.decode('utf-8')
|
||||||
|
|
||||||
if not proc.returncode == 0 or err:
|
if proc.returncode != 0 or err:
|
||||||
log.error('emerge pretend returned {}'.format(proc.returncode))
|
log.error('emerge returned {}'.format(proc.returncode))
|
||||||
for line in out.splitlines():
|
for line in out.splitlines():
|
||||||
log.error('stdout: {}'.format(line))
|
log.error('stdout: {}'.format(line))
|
||||||
for line in err.splitlines():
|
for line in err.splitlines():
|
||||||
@ -268,5 +262,27 @@ def pkg_upgrade():
|
|||||||
else:
|
else:
|
||||||
log.info('upgrade complete')
|
log.info('upgrade complete')
|
||||||
for line in out.splitlines():
|
for line in out.splitlines():
|
||||||
log.warning('stdout: {}'.format(line))
|
if line.startswith(' * '):
|
||||||
|
log.warning(line)
|
||||||
|
|
||||||
|
cmd = [ EMERGE_PATH, '--color', 'n', '-q', '@preserved-rebuild' ]
|
||||||
|
log.debug('Executing "{}"'.format(' '.join(cmd)))
|
||||||
|
proc = subprocess.Popen(
|
||||||
|
cmd,
|
||||||
|
stdout = subprocess.PIPE,
|
||||||
|
stderr = subprocess.PIPE)
|
||||||
|
out, err = proc.communicate()
|
||||||
|
out = out.decode('utf-8')
|
||||||
|
err = err.decode('utf-8')
|
||||||
|
|
||||||
|
if proc.returncode != 0 or err:
|
||||||
|
log.error('preserved-rebuild returned {}'.format(proc.returncode))
|
||||||
|
for line in out.splitlines():
|
||||||
|
log.error('stdout: {}'.format(line))
|
||||||
|
for line in err.splitlines():
|
||||||
|
log.error('stderr: {}'.format(line))
|
||||||
|
else:
|
||||||
|
log.info('preserved-rebuild complete')
|
||||||
|
for line in out.splitlines():
|
||||||
|
if line.startswith(' * '):
|
||||||
|
log.warning(line)
|
||||||
|
@ -11,11 +11,28 @@ import sau
|
|||||||
import sau.errors
|
import sau.errors
|
||||||
import sau.platforms
|
import sau.platforms
|
||||||
|
|
||||||
|
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)
|
||||||
files = set()
|
files = set()
|
||||||
|
|
||||||
|
# try the linux-way first
|
||||||
|
maps_file = '/proc/{}/maps'.format(proc.pid)
|
||||||
|
if os.path.isfile(maps_file):
|
||||||
|
with open(maps_file, 'r') as f:
|
||||||
|
for line in f:
|
||||||
|
match = re.match(proc_fd_map_re, line)
|
||||||
|
if match:
|
||||||
|
files.add(match.group(1))
|
||||||
|
return files
|
||||||
|
|
||||||
|
# on FreeBSD psutils open_files() helpfully returns a null path if a file
|
||||||
|
# has been deleted.
|
||||||
try:
|
try:
|
||||||
for f in proc.open_files():
|
for f in proc.open_files():
|
||||||
|
if 'lvmetad' in f.path:
|
||||||
|
log.debug(f)
|
||||||
if f.path and os.path.exists(f.path):
|
if f.path and os.path.exists(f.path):
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
@ -108,9 +125,11 @@ def restart_services():
|
|||||||
log.warning('Could not find service for process {}'.format(proc))
|
log.warning('Could not find service for process {}'.format(proc))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
services.add(service_name)
|
if service_name:
|
||||||
|
services.add(service_name)
|
||||||
|
|
||||||
for service in services:
|
for service in services:
|
||||||
|
log.info('Restarting service {}'.format(service))
|
||||||
platform.restart_service(service)
|
platform.restart_service(service)
|
||||||
|
|
||||||
recommend_restart = False
|
recommend_restart = False
|
||||||
|
Loading…
Reference in New Issue
Block a user