Compare commits
21 Commits
Author | SHA1 | Date | |
---|---|---|---|
8d373f599c | |||
17ef7eee8e | |||
0f713bf476 | |||
9f08c5f687 | |||
6fd96562ae | |||
76fe384d0f | |||
3d3dd379b7 | |||
cc206f6198 | |||
29c1256ee1 | |||
4002279a20 | |||
62ff301c3c | |||
fc6f29c0e1 | |||
db865eafe9 | |||
7cce11022c | |||
cef0f8d8bc | |||
00496493cd | |||
434858174c | |||
a4a28a1fb3 | |||
ae560e96c0 | |||
9970fe3365 | |||
2491df81f6 |
2
bin/sau
2
bin/sau
@ -115,7 +115,7 @@ def main():
|
|||||||
log.error(f'Upgrade failed: {e}')
|
log.error(f'Upgrade failed: {e}')
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
if not conf.getboolean('default', 'live_system', True):
|
if not conf.getboolean('default', 'live_system', fallback=True):
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
if conf.getboolean('default', 'do_service_restart', fallback=True):
|
if conf.getboolean('default', 'do_service_restart', fallback=True):
|
||||||
|
@ -45,6 +45,11 @@ do_depclean=yes
|
|||||||
# do eix-sync on Gentoo
|
# do eix-sync on Gentoo
|
||||||
do_reposync=yes
|
do_reposync=yes
|
||||||
|
|
||||||
|
# do live-rebuild, go-rebuild, rust-rebuild, perl-cleaner etc. on Gentoo
|
||||||
|
# set to no if using binary packages that are bumped when needed.
|
||||||
|
# Leave as yes on package builders and if not using binary packages.
|
||||||
|
do_rebuilds=yes
|
||||||
|
|
||||||
# to only write to stderr when something unexpected happens or manual action is required
|
# to only write to stderr when something unexpected happens or manual action is required
|
||||||
# set stderr_loglevel to warning
|
# set stderr_loglevel to warning
|
||||||
stderr_loglevel=debug
|
stderr_loglevel=debug
|
||||||
|
@ -4,6 +4,7 @@ import re
|
|||||||
|
|
||||||
import sau
|
import sau
|
||||||
import sau.helpers
|
import sau.helpers
|
||||||
|
import sau.services
|
||||||
|
|
||||||
EIX_SYNC_PATH='/usr/bin/eix-sync'
|
EIX_SYNC_PATH='/usr/bin/eix-sync'
|
||||||
RC_SERVICE_PATH='/sbin/rc-service'
|
RC_SERVICE_PATH='/sbin/rc-service'
|
||||||
@ -22,8 +23,7 @@ slot_re = re.compile(r'^(\(~\))?([^\(]+)(\([^\)]+\))$')
|
|||||||
def identify_service_from_bin(exe):
|
def identify_service_from_bin(exe):
|
||||||
log = logging.getLogger(sau.LOGNAME)
|
log = logging.getLogger(sau.LOGNAME)
|
||||||
|
|
||||||
with open('/proc/1/comm', 'r') as f:
|
if sau.services.on_systemd():
|
||||||
if f.readline().strip() == 'systemd':
|
|
||||||
init_script_re = re.compile(r'[^/]*(.*)\.service$')
|
init_script_re = re.compile(r'[^/]*(.*)\.service$')
|
||||||
else:
|
else:
|
||||||
init_script_re = re.compile(r'/etc/init\.d/(.*)')
|
init_script_re = re.compile(r'/etc/init\.d/(.*)')
|
||||||
@ -61,8 +61,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)
|
||||||
with open('/proc/1/comm', 'r') as f:
|
if sau.services.on_systemd():
|
||||||
if f.readline().strip() == 'systemd':
|
|
||||||
cmd = [ SYSTEMCTL, 'restart', service ]
|
cmd = [ SYSTEMCTL, 'restart', service ]
|
||||||
else:
|
else:
|
||||||
cmd = [ RC_SERVICE_PATH, service, 'restart' ]
|
cmd = [ RC_SERVICE_PATH, service, 'restart' ]
|
||||||
@ -117,6 +116,10 @@ def is_system_package(atom, eclasses):
|
|||||||
# sys-boot/ category should probably always be considered
|
# sys-boot/ category should probably always be considered
|
||||||
# system-packages
|
# system-packages
|
||||||
if name.split('/')[0] == 'sys-boot':
|
if name.split('/')[0] == 'sys-boot':
|
||||||
|
log.debug(f"{name} is a sys-boot package")
|
||||||
|
return True
|
||||||
|
|
||||||
|
if eclasses is True:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# libc-packages should be considered system-packages as they generally
|
# libc-packages should be considered system-packages as they generally
|
||||||
@ -124,6 +127,7 @@ def is_system_package(atom, eclasses):
|
|||||||
# then just checking for specific packages here, but as far as I know there
|
# then just checking for specific packages here, but as far as I know there
|
||||||
# are not many of them anyway...
|
# are not many of them anyway...
|
||||||
if re.search(r'^sys-libs/(glibc|musl)', name):
|
if re.search(r'^sys-libs/(glibc|musl)', name):
|
||||||
|
log.debug(f"{name} is a libc package")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
if any([
|
if any([
|
||||||
@ -132,13 +136,14 @@ def is_system_package(atom, eclasses):
|
|||||||
'linux-mod',
|
'linux-mod',
|
||||||
'kernel-install' ]
|
'kernel-install' ]
|
||||||
]):
|
]):
|
||||||
|
log.debug(f"{name} is of system eclass (eclasses: {eclasses})")
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def get_eclasses(atom):
|
def get_eclasses(atom):
|
||||||
log = logging.getLogger(sau.LOGNAME)
|
log = logging.getLogger(sau.LOGNAME)
|
||||||
eclasses = []
|
eclasses = []
|
||||||
name=re.sub(r'^[<=>]*(.*?)(?:-\d)?(?:::\w+)?$', r'\1', atom)
|
name=re.sub(r'^[<=>]*(.*?)(?:-\d+)?(?:::\w+)?$', r'\1', atom)
|
||||||
test_re = re.compile(r'^\s*inherit\s+')
|
test_re = re.compile(r'^\s*inherit\s+')
|
||||||
cmd=[ EQUERY_PATH, 'w', name ]
|
cmd=[ EQUERY_PATH, 'w', name ]
|
||||||
ret, out, err = sau.helpers.exec_cmd(cmd)
|
ret, out, err = sau.helpers.exec_cmd(cmd)
|
||||||
@ -166,7 +171,7 @@ def get_eclasses(atom):
|
|||||||
return eclasses
|
return eclasses
|
||||||
|
|
||||||
def get_dependencies(atom):
|
def get_dependencies(atom):
|
||||||
cmd=[ EQUERY_PATH, '-q', 'd', '-F', '$cp', name ]
|
cmd=[ EQUERY_PATH, '-q', 'd', '-F', '$cp', atom ]
|
||||||
ret, out, err = sau.helpers.exec_cmd(cmd)
|
ret, out, err = sau.helpers.exec_cmd(cmd)
|
||||||
dependencies = [l.strip() for l in out.splitlines()]
|
dependencies = [l.strip() for l in out.splitlines()]
|
||||||
return dependencies
|
return dependencies
|
||||||
@ -233,7 +238,7 @@ def pkg_upgrade():
|
|||||||
if do_system_upgrade:
|
if do_system_upgrade:
|
||||||
do_grub = True
|
do_grub = True
|
||||||
else:
|
else:
|
||||||
raise sau.errors.UpgradeError(f"System package {name} has an update, but system upgrade is disabled")
|
raise sau.errors.UpgradeError(f"System package {package} has an update, but system upgrade is disabled")
|
||||||
|
|
||||||
if not do_rebuild:
|
if not do_rebuild:
|
||||||
raise sau.errors.UpgradeError('Some packages require manual attention, did not upgrade')
|
raise sau.errors.UpgradeError('Some packages require manual attention, did not upgrade')
|
||||||
@ -259,8 +264,11 @@ def pkg_upgrade():
|
|||||||
if line.startswith(' * '):
|
if line.startswith(' * '):
|
||||||
log.warning(line)
|
log.warning(line)
|
||||||
|
|
||||||
|
## rebuild as needed
|
||||||
|
do_rebuild = conf.getboolean('default', 'do_rebuilds', fallback=True)
|
||||||
|
if do_rebuild:
|
||||||
# from here on we shouldn't need to rebuild the upgraded packages again
|
# from here on we shouldn't need to rebuild the upgraded packages again
|
||||||
exclude_list = '--exclude '.join(rebuild_packages.keys()).split()
|
exclude_list = ' --exclude '.join(rebuild_packages.keys()).split()
|
||||||
|
|
||||||
# Rebuild go
|
# Rebuild go
|
||||||
go_packages = []
|
go_packages = []
|
||||||
@ -274,13 +282,13 @@ def pkg_upgrade():
|
|||||||
EMERGE_PATH,
|
EMERGE_PATH,
|
||||||
'--color', 'n',
|
'--color', 'n',
|
||||||
'-q',
|
'-q',
|
||||||
'--usepkg-exclude', '*/*',
|
'--usepkg', 'n',
|
||||||
'@golang-rebuild',
|
'@golang-rebuild',
|
||||||
'--exclude' ] + exclude_list
|
'--exclude' ] + exclude_list
|
||||||
elif go_packages:
|
elif go_packages:
|
||||||
dependencies = []
|
dependencies = []
|
||||||
for package in go_packages:
|
for package in go_packages:
|
||||||
dependencies.append(get_dependencies(package))
|
dependencies.extend(get_dependencies(package))
|
||||||
dependencies = set(dependencies)
|
dependencies = set(dependencies)
|
||||||
upgraded = set(rebuild_packages.keys())
|
upgraded = set(rebuild_packages.keys())
|
||||||
not_upgraded = dependencies-upgraded
|
not_upgraded = dependencies-upgraded
|
||||||
@ -290,7 +298,7 @@ def pkg_upgrade():
|
|||||||
EMERGE_PATH,
|
EMERGE_PATH,
|
||||||
'--color', 'n',
|
'--color', 'n',
|
||||||
'-q',
|
'-q',
|
||||||
'--usepkg-exclude', '*/*'] + not_upgraded
|
'--usepkg', 'n'] + not_upgraded
|
||||||
if cmd:
|
if cmd:
|
||||||
ret, out, err = sau.helpers.exec_cmd(cmd, timeout=72000)
|
ret, out, err = sau.helpers.exec_cmd(cmd, timeout=72000)
|
||||||
if ret != 0 or err:
|
if ret != 0 or err:
|
||||||
@ -307,13 +315,13 @@ def pkg_upgrade():
|
|||||||
log.warning(line)
|
log.warning(line)
|
||||||
|
|
||||||
# rebuild rust
|
# rebuild rust
|
||||||
if 'dev-lang/rust' in rebuild_packages:
|
if any([x in rebuild_packages for x in ('dev-lang/rust', 'dev-lang/rust-bin')]):
|
||||||
log.info("Running rust-rebuild due to update of dev-lang/rust")
|
log.info("Running rust-rebuild due to update of rust")
|
||||||
cmd = [
|
cmd = [
|
||||||
EMERGE_PATH,
|
EMERGE_PATH,
|
||||||
'--color', 'n',
|
'--color', 'n',
|
||||||
'-q',
|
'-q',
|
||||||
'--usepkg-exclude', '*/*',
|
'--usepkg', 'n',
|
||||||
'@rust-rebuild',
|
'@rust-rebuild',
|
||||||
'--exclude' ] + exclude_list
|
'--exclude' ] + exclude_list
|
||||||
ret, out, err = sau.helpers.exec_cmd(cmd, timeout=72000)
|
ret, out, err = sau.helpers.exec_cmd(cmd, timeout=72000)
|
||||||
@ -333,7 +341,7 @@ def pkg_upgrade():
|
|||||||
# run perl-cleaner
|
# run perl-cleaner
|
||||||
if 'dev-lang/perl' in rebuild_packages:
|
if 'dev-lang/perl' in rebuild_packages:
|
||||||
log.info("Running perl-cleaner due to perl upgrade")
|
log.info("Running perl-cleaner due to perl upgrade")
|
||||||
cmd = [ PCLEAN_PATH, '--all', '--', '-q', '--usepkg-exclude', '*/*']
|
cmd = [ PCLEAN_PATH, '--all', '--', '-q', '--usepkg', 'n']
|
||||||
ret, out, err = sau.helpers.exec_cmd(cmd, timeout=72000)
|
ret, out, err = sau.helpers.exec_cmd(cmd, timeout=72000)
|
||||||
if ret != 0 or err:
|
if ret != 0 or err:
|
||||||
log.error('perl-cleaner failed with code {}'.format(ret))
|
log.error('perl-cleaner failed with code {}'.format(ret))
|
||||||
@ -349,7 +357,7 @@ def pkg_upgrade():
|
|||||||
log.warning(line)
|
log.warning(line)
|
||||||
|
|
||||||
# rebuild live packages
|
# rebuild live packages
|
||||||
cmd = [ EMERGE_PATH, '--color', 'n', '-q', '--usepkg-exclude', '*/*', '@live-rebuild' ]
|
cmd = [ EMERGE_PATH, '--color', 'n', '-q', '--usepkg', 'n', '@live-rebuild' ]
|
||||||
ret, out, err = sau.helpers.exec_cmd(cmd, timeout=3600)
|
ret, out, err = sau.helpers.exec_cmd(cmd, timeout=3600)
|
||||||
if ret != 0 or err:
|
if ret != 0 or err:
|
||||||
log.error('live-rebuild returned {}'.format(ret))
|
log.error('live-rebuild returned {}'.format(ret))
|
||||||
@ -365,7 +373,7 @@ def pkg_upgrade():
|
|||||||
log.warning(line)
|
log.warning(line)
|
||||||
|
|
||||||
|
|
||||||
# Depclean
|
## Depclean
|
||||||
if conf.getboolean('default', 'do_depclean', fallback=False):
|
if conf.getboolean('default', 'do_depclean', fallback=False):
|
||||||
cmd = [ EMERGE_PATH, '--color', 'n', '-q', '--depclean' ]
|
cmd = [ EMERGE_PATH, '--color', 'n', '-q', '--depclean' ]
|
||||||
ret, out, err = sau.helpers.exec_cmd(cmd, timeout=3600)
|
ret, out, err = sau.helpers.exec_cmd(cmd, timeout=3600)
|
||||||
@ -383,8 +391,8 @@ def pkg_upgrade():
|
|||||||
log.warning(line)
|
log.warning(line)
|
||||||
|
|
||||||
|
|
||||||
# Preserved rebuild
|
## Preserved rebuild
|
||||||
cmd = [ EMERGE_PATH, '--color', 'n', '-q', '@preserved-rebuild' ]
|
cmd = [ EMERGE_PATH, '--color', 'n', '--usepkg', 'n', '-q', '@preserved-rebuild' ]
|
||||||
ret, out, err = sau.helpers.exec_cmd(cmd, timeout=72000)
|
ret, out, err = sau.helpers.exec_cmd(cmd, timeout=72000)
|
||||||
|
|
||||||
if ret != 0 or err:
|
if ret != 0 or err:
|
||||||
|
100
sau/services.py
100
sau/services.py
@ -10,7 +10,10 @@ import sau.errors
|
|||||||
import sau.helpers
|
import sau.helpers
|
||||||
import sau.platforms
|
import sau.platforms
|
||||||
|
|
||||||
proc_fd_map_re = re.compile(r'^.*(/[^\(]*) \(deleted\)$')
|
proc_fd_map_re = re.compile(r'^.*(/(?:usr|lib|opt|etc|s?bin)[^\(]*) \(deleted\)$')
|
||||||
|
|
||||||
|
valid_service_policies=('restart', 'warn', 'ignore', 'silent-restart',
|
||||||
|
'reboot', 'silent-reboot')
|
||||||
|
|
||||||
def _warn(policy, msg):
|
def _warn(policy, msg):
|
||||||
log = logging.getLogger(sau.LOGNAME)
|
log = logging.getLogger(sau.LOGNAME)
|
||||||
@ -28,7 +31,8 @@ def get_deleted_open_files(proc):
|
|||||||
for line in f:
|
for line in f:
|
||||||
match = re.match(proc_fd_map_re, line)
|
match = re.match(proc_fd_map_re, line)
|
||||||
if match:
|
if match:
|
||||||
files.add(match.group(1))
|
fname = match.group(1)
|
||||||
|
files.add(fname)
|
||||||
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
|
||||||
@ -75,6 +79,16 @@ def _get_processes():
|
|||||||
|
|
||||||
return check_procs
|
return check_procs
|
||||||
|
|
||||||
|
# Just return True if system is running on systemd
|
||||||
|
def on_systemd():
|
||||||
|
try:
|
||||||
|
init_proc = psutil.Process(pid=1)
|
||||||
|
if init_proc.name() == 'systemd':
|
||||||
|
return True
|
||||||
|
except psutil.NoSuchProcess:
|
||||||
|
pass
|
||||||
|
return False
|
||||||
|
|
||||||
def restart_services():
|
def restart_services():
|
||||||
log = logging.getLogger(sau.LOGNAME)
|
log = logging.getLogger(sau.LOGNAME)
|
||||||
platform = sau.platforms.get_platform()
|
platform = sau.platforms.get_platform()
|
||||||
@ -84,14 +98,6 @@ def restart_services():
|
|||||||
# wait before the second test
|
# wait before the second test
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
|
|
||||||
on_systemd = False
|
|
||||||
try:
|
|
||||||
init_proc = psutil.Process(pid=1)
|
|
||||||
if init_proc.name() == 'systemd':
|
|
||||||
on_systemd = True
|
|
||||||
except psutil.NoSuchProcess:
|
|
||||||
pass
|
|
||||||
|
|
||||||
# perform a second check to remove potential false positives
|
# perform a second check to remove potential false positives
|
||||||
service_procs = set()
|
service_procs = set()
|
||||||
retest_procs = set()
|
retest_procs = set()
|
||||||
@ -105,7 +111,7 @@ def restart_services():
|
|||||||
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
|
||||||
continue
|
continue
|
||||||
if on_systemd:
|
if on_systemd():
|
||||||
service_procs.add(proc)
|
service_procs.add(proc)
|
||||||
else:
|
else:
|
||||||
parent = _get_top_parent(proc)
|
parent = _get_top_parent(proc)
|
||||||
@ -114,7 +120,6 @@ def restart_services():
|
|||||||
retest_procs.add(proc)
|
retest_procs.add(proc)
|
||||||
|
|
||||||
recommend_restart = False
|
recommend_restart = False
|
||||||
processes = {}
|
|
||||||
services = {}
|
services = {}
|
||||||
for proc in service_procs:
|
for proc in service_procs:
|
||||||
if not proc:
|
if not proc:
|
||||||
@ -128,43 +133,28 @@ def restart_services():
|
|||||||
log.debug('{} died before it could be restarted'.format(proc))
|
log.debug('{} died before it could be restarted'.format(proc))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if on_systemd:
|
|
||||||
if proc.pid == 1:
|
|
||||||
log.info("Upgrade of systemd detected; doing daemon-reexec")
|
|
||||||
ret, _out, _err = sau.helpers.exec_cmd([ '/usr/bin/systemctl', 'daemon-reexec' ])
|
|
||||||
continue
|
|
||||||
ret, unit, err = sau.helpers.exec_cmd([ '/usr/bin/systemctl', 'whoami', f'{proc.pid}' ])
|
|
||||||
unit = unit.strip()
|
|
||||||
name, unit_type = unit.split('.')
|
|
||||||
if ret != 0:
|
|
||||||
log.debug(f'Non-success ({ret}) when checking unit for process: {err}')
|
|
||||||
continue
|
|
||||||
elif unit_type != 'service':
|
|
||||||
log.warning(f'not restarting non-service unit "{unit}"; owner of {proc}')
|
|
||||||
elif name.startswith('user@'):
|
|
||||||
log.warning(f'Not restarting user service {unit}; please log out and log in again')
|
|
||||||
else:
|
|
||||||
_ret, enabled, _err = sau.helpers.exec_cmd([ '/usr/bin/systemctl', 'is-enabled', unit ])
|
|
||||||
enabled = enabled.strip()
|
|
||||||
if enabled not in ('enabled', 'static'):
|
|
||||||
log.warning(f'Unit {name}.service has enable status: {enabled} - will only restart "enabled" services')
|
|
||||||
else:
|
|
||||||
service_name = name
|
|
||||||
else:
|
|
||||||
service_name = _get_service_from_proc(proc)
|
service_name = _get_service_from_proc(proc)
|
||||||
|
|
||||||
if not service_name:
|
if not service_name:
|
||||||
log.warning('no service for process {}'.format(proc))
|
log.warning('no service for process {}'.format(proc))
|
||||||
recommend_restart = True
|
recommend_restart = True
|
||||||
continue
|
continue
|
||||||
|
if service_name == 'systemd':
|
||||||
|
log.info("Upgrade of systemd detected; doing daemon-reexec")
|
||||||
|
sau.helpers.exec_cmd([ '/usr/bin/systemctl', 'daemon-reexec' ])
|
||||||
|
continue
|
||||||
|
elif service_name == '@ignore':
|
||||||
|
log.info(f"Process {proc} ignored by configuration")
|
||||||
|
retest_procs.discard(proc)
|
||||||
|
continue
|
||||||
|
|
||||||
services[proc_name] = service_name
|
services[proc_name] = service_name
|
||||||
processes[service_name] = [proc]
|
|
||||||
|
|
||||||
for service in set([x for x in services.values() if x]):
|
for service in set([x for x in services.values() if x]):
|
||||||
policy = _get_service_restart_policy(service)
|
policy = _get_service_restart_policy(service)
|
||||||
if policy == 'ignore':
|
if policy == 'ignore':
|
||||||
log.info('Service "{}" ignored by configuration'.format(service))
|
log.info('Service "{}" ignored by configuration'.format(service))
|
||||||
|
[retest_procs.discard(x) for x,y in services.items() if y == service]
|
||||||
continue
|
continue
|
||||||
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))
|
||||||
@ -195,7 +185,7 @@ def _get_service_restart_policy(service):
|
|||||||
log = logging.getLogger(sau.LOGNAME)
|
log = logging.getLogger(sau.LOGNAME)
|
||||||
conf = sau.config
|
conf = sau.config
|
||||||
policy = conf.get('services', service, fallback=None)
|
policy = conf.get('services', service, fallback=None)
|
||||||
if policy and policy.lower() in ('restart', 'warn', 'ignore', 'silent-restart', 'reboot', 'silent-reboot'):
|
if policy and policy.lower() in valid_service_policies:
|
||||||
return policy.lower()
|
return policy.lower()
|
||||||
elif policy:
|
elif policy:
|
||||||
log.warning('service policy {} for {} is invalid'.format(policy, service))
|
log.warning('service policy {} for {} is invalid'.format(policy, service))
|
||||||
@ -209,6 +199,7 @@ def _get_service_restart_policy(service):
|
|||||||
def _get_service_from_proc(proc):
|
def _get_service_from_proc(proc):
|
||||||
conf = sau.config
|
conf = sau.config
|
||||||
platform = sau.platforms.get_platform()
|
platform = sau.platforms.get_platform()
|
||||||
|
if not on_systemd():
|
||||||
proc = _get_top_parent(proc)
|
proc = _get_top_parent(proc)
|
||||||
log = logging.getLogger(sau.LOGNAME)
|
log = logging.getLogger(sau.LOGNAME)
|
||||||
try:
|
try:
|
||||||
@ -216,14 +207,45 @@ def _get_service_from_proc(proc):
|
|||||||
service_exe = proc.exe()
|
service_exe = proc.exe()
|
||||||
except (psutil.NoSuchProcess, psutil.ZombieProcess, psutil.AccessDenied):
|
except (psutil.NoSuchProcess, psutil.ZombieProcess, psutil.AccessDenied):
|
||||||
log.debug('{} died'.format(proc))
|
log.debug('{} died'.format(proc))
|
||||||
return None
|
return '@ignore'
|
||||||
|
|
||||||
service_name = conf.get('processes', proc_name, fallback=None)
|
service_name = conf.get('processes', proc_name, fallback=None)
|
||||||
|
log.debug(f'configuration of process "{proc_name}" in config: "{service_name}"')
|
||||||
if service_name == '':
|
if service_name == '':
|
||||||
log.debug('Ignoring process {}'.format(proc))
|
log.debug('Ignoring process {}'.format(proc))
|
||||||
return None
|
return '@ignore'
|
||||||
|
|
||||||
if not service_name:
|
if not service_name:
|
||||||
|
# Systemd has it's own way...
|
||||||
|
if on_systemd():
|
||||||
|
if proc.pid == 1:
|
||||||
|
return 'systemd'
|
||||||
|
ret, unit, err = sau.helpers.exec_cmd([ '/usr/bin/systemctl', 'whoami', f'{proc.pid}' ])
|
||||||
|
unit = unit.strip()
|
||||||
|
name, unit_type = unit.split('.')
|
||||||
|
if ret != 0:
|
||||||
|
log.debug(f'Non-success ({ret}) when checking unit for process: {err}')
|
||||||
|
return None
|
||||||
|
elif unit_type != 'service':
|
||||||
|
log.warning(f'not restarting non-service unit "{unit}"; owner of {proc}')
|
||||||
|
return None
|
||||||
|
elif name.startswith('user@'):
|
||||||
|
log.warning(f'Not restarting user service {unit}; please log out and log in again')
|
||||||
|
return None
|
||||||
|
else:
|
||||||
|
policy = conf.get('services', name, fallback=None)
|
||||||
|
if policy and policy.lower() in valid_service_policies:
|
||||||
|
return name
|
||||||
|
_ret, enabled, _err = sau.helpers.exec_cmd([ '/usr/bin/systemctl', 'is-enabled', unit ])
|
||||||
|
enabled = enabled.strip()
|
||||||
|
if enabled not in ('enabled', 'static'):
|
||||||
|
log.warning(f'Unit {name}.service has enable status: {enabled} - will only restart "enabled" services')
|
||||||
|
return None
|
||||||
|
else:
|
||||||
|
return name
|
||||||
|
log.error(f'This should be an unreachable path when checking process {proc}')
|
||||||
|
return None
|
||||||
|
|
||||||
# if the exe file has been deleted since started, service_exe will be empty
|
# if the exe file has been deleted since started, service_exe will be empty
|
||||||
# and we'll have to guess
|
# and we'll have to guess
|
||||||
if not service_exe:
|
if not service_exe:
|
||||||
|
4
setup.py
4
setup.py
@ -1,11 +1,11 @@
|
|||||||
#!/usr/bin/env python3.7
|
#!/usr/bin/env python3
|
||||||
from os import environ
|
from os import environ
|
||||||
|
|
||||||
from setuptools import setup, find_packages
|
from setuptools import setup, find_packages
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='sau',
|
name='sau',
|
||||||
version='1.3.1',
|
version='1.4.5',
|
||||||
description='Tool for auto-updating OS and packages',
|
description='Tool for auto-updating OS and packages',
|
||||||
author='Feffe',
|
author='Feffe',
|
||||||
author_email='feffe@fulh.ax',
|
author_email='feffe@fulh.ax',
|
||||||
|
Loading…
Reference in New Issue
Block a user