mirror of
https://github.com/isjerryxiao/pacroller.git
synced 2024-11-26 01:30:42 +08:00
run needrestart on fail-reset
This commit is contained in:
parent
aa23067b07
commit
401ffcfcd3
1 changed files with 23 additions and 17 deletions
|
@ -184,7 +184,7 @@ def is_system_failed() -> str:
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
def locale_set():
|
def locale_set() -> None:
|
||||||
p = subprocess.run(['localectl', 'list-locales', '--no-pager'],
|
p = subprocess.run(['localectl', 'list-locales', '--no-pager'],
|
||||||
stdin=subprocess.DEVNULL,
|
stdin=subprocess.DEVNULL,
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
|
@ -203,6 +203,25 @@ def main() -> None:
|
||||||
else:
|
else:
|
||||||
logger.debug('using fallback locale C')
|
logger.debug('using fallback locale C')
|
||||||
environ['LANG'] = 'C'
|
environ['LANG'] = 'C'
|
||||||
|
def run_needrestart(ignore_error=False) -> None:
|
||||||
|
logger.debug('running needrestart')
|
||||||
|
try:
|
||||||
|
p = subprocess.run(
|
||||||
|
NEEDRESTART_CMD,
|
||||||
|
stdin=subprocess.DEVNULL,
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
stderr=subprocess.STDOUT,
|
||||||
|
encoding='utf-8',
|
||||||
|
timeout=TIMEOUT,
|
||||||
|
check=True
|
||||||
|
)
|
||||||
|
except subprocess.CalledProcessError as e:
|
||||||
|
logger.error(f'needrestart failed with {e.returncode=} {e.output=}')
|
||||||
|
if not ignore_error:
|
||||||
|
write_db(None, NeedrestartFailed(f'{e.returncode=}'))
|
||||||
|
exit(2)
|
||||||
|
else:
|
||||||
|
logger.debug(f'needrestart {p.stdout=}')
|
||||||
import argparse
|
import argparse
|
||||||
parser = argparse.ArgumentParser(description='Pacman Automatic Rolling Helper')
|
parser = argparse.ArgumentParser(description='Pacman Automatic Rolling Helper')
|
||||||
parser.add_argument('action', choices=['run', 'status', 'fail-reset'])
|
parser.add_argument('action', choices=['run', 'status', 'fail-reset'])
|
||||||
|
@ -240,22 +259,7 @@ def main() -> None:
|
||||||
if exc:
|
if exc:
|
||||||
exit(2)
|
exit(2)
|
||||||
if NEEDRESTART:
|
if NEEDRESTART:
|
||||||
try:
|
run_needrestart()
|
||||||
p = subprocess.run(
|
|
||||||
NEEDRESTART_CMD,
|
|
||||||
stdin=subprocess.DEVNULL,
|
|
||||||
stdout=subprocess.PIPE,
|
|
||||||
stderr=subprocess.STDOUT,
|
|
||||||
encoding='utf-8',
|
|
||||||
timeout=TIMEOUT,
|
|
||||||
check=True
|
|
||||||
)
|
|
||||||
except subprocess.CalledProcessError as e:
|
|
||||||
logger.error(f'needrestart failed with {e.returncode=} {e.output=}')
|
|
||||||
write_db(None, NeedrestartFailed(f'{e.returncode=}'))
|
|
||||||
exit(2)
|
|
||||||
else:
|
|
||||||
logger.debug(f'needrestart {p.stdout=}')
|
|
||||||
|
|
||||||
elif args.action == 'status':
|
elif args.action == 'status':
|
||||||
count = 0
|
count = 0
|
||||||
|
@ -301,6 +305,8 @@ def main() -> None:
|
||||||
if prev_err := has_previous_error():
|
if prev_err := has_previous_error():
|
||||||
write_db(None)
|
write_db(None)
|
||||||
logger.info(f'reset previous error {prev_err}')
|
logger.info(f'reset previous error {prev_err}')
|
||||||
|
if NEEDRESTART:
|
||||||
|
run_needrestart(True)
|
||||||
else:
|
else:
|
||||||
logger.warning('nothing to do')
|
logger.warning('nothing to do')
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue