check for pacman lock and handle sync timeout

This commit is contained in:
JerryXiao 2021-02-07 14:17:08 +08:00
parent c75cf9100e
commit 09404979b0
Signed by: Jerry
GPG key ID: 9D9CE43650FF2BAA
2 changed files with 11 additions and 1 deletions

View file

@ -8,6 +8,7 @@ DB_FILE = 'db'
PACMAN_CONFIG = '/etc/pacman.conf' PACMAN_CONFIG = '/etc/pacman.conf'
PACMAN_LOG = '/var/log/pacman.log' PACMAN_LOG = '/var/log/pacman.log'
PACMAN_PKG_DIR = '/var/cache/pacman/pkg' PACMAN_PKG_DIR = '/var/cache/pacman/pkg'
PACMAN_DB_LCK = '/var/lib/pacman/db.lck'
assert LIB_DIR.is_dir() assert LIB_DIR.is_dir()
if (cfg := (CONFIG_DIR / CONFIG_FILE)).exists(): if (cfg := (CONFIG_DIR / CONFIG_FILE)).exists():

View file

@ -15,7 +15,7 @@ from pacroller.checker import log_checker, sync_err_is_net, upgrade_err_is_net,
from pacroller.config import (CONFIG_DIR, CONFIG_FILE, LIB_DIR, DB_FILE, PACMAN_LOG, PACMAN_CONFIG, from pacroller.config import (CONFIG_DIR, CONFIG_FILE, LIB_DIR, DB_FILE, PACMAN_LOG, PACMAN_CONFIG,
TIMEOUT, UPGRADE_TIMEOUT, NETWORK_RETRY, CUSTOM_SYNC, SYNC_SH, TIMEOUT, UPGRADE_TIMEOUT, NETWORK_RETRY, CUSTOM_SYNC, SYNC_SH,
EXTRA_SAFE, SHELL, HOLD, NEEDRESTART, NEEDRESTART_CMD, SYSTEMD, EXTRA_SAFE, SHELL, HOLD, NEEDRESTART, NEEDRESTART_CMD, SYSTEMD,
PACMAN_PKG_DIR, PACMAN_SCC) PACMAN_PKG_DIR, PACMAN_SCC, PACMAN_DB_LCK)
logger = logging.getLogger() logger = logging.getLogger()
@ -55,6 +55,12 @@ def sync() -> None:
else: else:
logger.exception(f'sync failed with {e.returncode=} {e.output=}') logger.exception(f'sync failed with {e.returncode=} {e.output=}')
raise raise
except subprocess.TimeoutExpired as e:
logger.warning('database download timeout {e.timeout=} {e.output=}')
if PACMAN_DB_LCK.exists():
logger.warning(f'automatically removing {PACMAN_DB_LCK}')
Path(PACMAN_DB_LCK).unlink()
raise SyncRetry()
else: else:
logger.debug(f'sync {p.stdout=}') logger.debug(f'sync {p.stdout=}')
logger.info('sync end') logger.info('sync end')
@ -252,6 +258,9 @@ def main() -> None:
if _s := is_system_failed(): if _s := is_system_failed():
logger.error(f'systemd is in {_s} state, refused') logger.error(f'systemd is in {_s} state, refused')
exit(11) exit(11)
if Path(PACMAN_DB_LCK).exists():
logger.error(f'Database is locked at {PACMAN_DB_LCK}')
exit(2)
try: try:
report = do_system_upgrade(args.debug) report = do_system_upgrade(args.debug)
except NonFatal: except NonFatal: