diff --git a/modules/map/lib.py b/modules/map/lib.py index a765fd77..2e023100 100644 --- a/modules/map/lib.py +++ b/modules/map/lib.py @@ -216,19 +216,14 @@ def get_import_status(session: Session = None) -> List[MapFile]: return map_paths -MOD_TILE_CACHE_DIR1 = Path('/var/lib/mod_tile/ajt') -MOD_TILE_CACHE_DIR2 = Path('/var/cache/renderd/tiles/ajt') - - @wrol_mode_check async def clear_mod_tile(): - """Remove all cached map tile files""" + """Remove all cached map tile files. + + @warning: Uses sudo to clear the files and restart the renderd service.""" if PYTEST: return logger.warning('Clearing map tile cache files') - if MOD_TILE_CACHE_DIR1.is_dir(): - await asyncio.create_subprocess_shell(f'rm -r {MOD_TILE_CACHE_DIR1}') - if MOD_TILE_CACHE_DIR2.is_dir(): - await asyncio.create_subprocess_shell(f'rm -r {MOD_TILE_CACHE_DIR2}') + await asyncio.create_subprocess_shell(f'sudo /opt/wrolpi/scripts/clear_map_cache.sh') diff --git a/pi-gen/stage2/04-wrolpi/03-run-chroot.sh b/pi-gen/stage2/04-wrolpi/03-run-chroot.sh index f909e511..3963c72c 100755 --- a/pi-gen/stage2/04-wrolpi/03-run-chroot.sh +++ b/pi-gen/stage2/04-wrolpi/03-run-chroot.sh @@ -66,6 +66,7 @@ cat >/etc/sudoers.d/90-wrolpi <<'EOF' %wrolpi ALL= NOPASSWD:/usr/bin/systemctl restart wrolpi-app.service %wrolpi ALL= NOPASSWD:/usr/bin/systemctl stop wrolpi-app.service %wrolpi ALL= NOPASSWD:/usr/bin/systemctl start wrolpi-app.service +%wrolpi ALL= NOPASSWD:/opt/wrolpi/scripts/clear_map_cache.sh EOF chmod 660 /etc/sudoers.d/90-wrolpi diff --git a/scripts/clear_map_cache.sh b/scripts/clear_map_cache.sh new file mode 100755 index 00000000..62b0b2b5 --- /dev/null +++ b/scripts/clear_map_cache.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash +# Simple script which removes the Renderd map tile cache files. + +# Re-execute this script if it wasn't called with sudo. +if [ $EUID != 0 ]; then + sudo "$0" "$@" + exit $? +fi + +[ -d /var/lib/mod_tile/ajt ] && rm -rf /var/lib/mod_tile/ajt +[ -d /var/cache/renderd/tiles/ajt ] && rm -rf /var/cache/renderd/tiles/ajt + +systemctl restart renderd diff --git a/scripts/install_debian_11.sh b/scripts/install_debian_11.sh index db3abba4..e6c54392 100755 --- a/scripts/install_debian_11.sh +++ b/scripts/install_debian_11.sh @@ -88,6 +88,7 @@ cat >/etc/sudoers.d/90-wrolpi <<'EOF' %wrolpi ALL= NOPASSWD:/usr/bin/systemctl restart wrolpi-app.service %wrolpi ALL= NOPASSWD:/usr/bin/systemctl stop wrolpi-app.service %wrolpi ALL= NOPASSWD:/usr/bin/systemctl start wrolpi-app.service +%wrolpi ALL= NOPASSWD:/opt/wrolpi/scripts/clear_map_cache.sh EOF chmod 660 /etc/sudoers.d/90-wrolpi # Verify this new file is valid. diff --git a/scripts/install_raspberrypios.sh b/scripts/install_raspberrypios.sh index 07e2df7a..78be6c69 100755 --- a/scripts/install_raspberrypios.sh +++ b/scripts/install_raspberrypios.sh @@ -98,6 +98,7 @@ cat >/etc/sudoers.d/90-wrolpi <<'EOF' %wrolpi ALL= NOPASSWD:/usr/bin/systemctl restart wrolpi-app.service %wrolpi ALL= NOPASSWD:/usr/bin/systemctl stop wrolpi-app.service %wrolpi ALL= NOPASSWD:/usr/bin/systemctl start wrolpi-app.service +%wrolpi ALL= NOPASSWD:/opt/wrolpi/scripts/clear_map_cache.sh EOF chmod 660 /etc/sudoers.d/90-wrolpi # Verify this new file is valid.