diff --git a/app/src/components/admin/Settings.js b/app/src/components/admin/Settings.js index 7bde34c2..184d13da 100644 --- a/app/src/components/admin/Settings.js +++ b/app/src/components/admin/Settings.js @@ -151,15 +151,6 @@ export class Settings extends React.Component { /> -
- this.handleInputChange(null, 'hotspot_on_startup', checked)} - /> -
-
int: raise ValueError('Invalid PBF file') paths = ' '.join(str(i) for i in paths) - cmd = f'{BASH_BIN} {PROJECT_DIR}/scripts/import_map.sh {paths}' + # Run with sudo so renderd can be restarted. + cmd = f'{SUDO_BIN} {PROJECT_DIR}/scripts/import_map.sh {paths}' import_logger.warning(f'Running map import command: {cmd}') start = now() proc = await asyncio.create_subprocess_shell(cmd, stderr=asyncio.subprocess.PIPE, stdout=asyncio.subprocess.PIPE) @@ -225,19 +224,6 @@ def get_import_status(session: Session = None) -> List[MapFile]: return map_paths -@wrol_mode_check -async def clear_mod_tile(): - """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') - - await asyncio.create_subprocess_shell(f'sudo /opt/wrolpi/scripts/clear_map_cache.sh') - - # Bps calculated using many tests on a well-cooled RPi4. RPI4_PBF_BYTES_PER_SECOND = 61879 diff --git a/modules/map/test/test_models.py b/modules/map/test/test_models.py index 46d7a5d5..be1e34f7 100644 --- a/modules/map/test/test_models.py +++ b/modules/map/test/test_models.py @@ -9,11 +9,11 @@ from modules.map import models @pytest.mark.parametrize('size,expected', [ (0, 0), (-1, 0), - (17737381, 252), - (63434267, 904), - (87745484, 1251), - (136372996, 1944), - (116318111, 1658), + (17737381, 286), + (63434267, 1025), + (87745484, 1418), + (136372996, 2203), + (116318111, 1879), ]) def test_seconds_to_import_rpi4(size, expected): assert modules.map.lib.seconds_to_import(size) == expected diff --git a/pi-gen/stage2/04-wrolpi/03-run-chroot.sh b/pi-gen/stage2/04-wrolpi/03-run-chroot.sh index 3963c72c..362dfb19 100755 --- a/pi-gen/stage2/04-wrolpi/03-run-chroot.sh +++ b/pi-gen/stage2/04-wrolpi/03-run-chroot.sh @@ -66,7 +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 +%wrolpi ALL= NOPASSWD:/opt/wrolpi/scripts/import_map.sh EOF chmod 660 /etc/sudoers.d/90-wrolpi diff --git a/scripts/clear_map_cache.sh b/scripts/clear_map_cache.sh deleted file mode 100755 index 62b0b2b5..00000000 --- a/scripts/clear_map_cache.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/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/import_map.sh b/scripts/import_map.sh index 5e352d9a..bbeee3a2 100755 --- a/scripts/import_map.sh +++ b/scripts/import_map.sh @@ -24,15 +24,24 @@ if [ ${HAS_ICE_SHEET} = false ]; then exit 4 fi +# Re-execute this script if it wasn't called with sudo. +if [ $EUID != 0 ]; then + sudo "$0" "$@" + exit $? +fi + function cleanup() { if [ -f ${MERGED_TMP_FILE} ]; then rm ${MERGED_TMP_FILE} fi + systemctl restart renderd } trap cleanup EXIT cleanup +systemctl stop renderd + if [[ ${1} == *.osm.pbf ]]; then # Import PBF files. for i in "$@"; do @@ -93,3 +102,7 @@ else echo "WROLPi: Cannot import unknown map file" exit 8 fi + +# Clear map tile cache only after successful import. +[ -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 diff --git a/scripts/install_debian_11.sh b/scripts/install_debian_11.sh index e6c54392..d7ed63b1 100755 --- a/scripts/install_debian_11.sh +++ b/scripts/install_debian_11.sh @@ -88,7 +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 +%wrolpi ALL= NOPASSWD:/opt/wrolpi/scripts/import_map.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 78be6c69..13dec20a 100755 --- a/scripts/install_raspberrypios.sh +++ b/scripts/install_raspberrypios.sh @@ -98,7 +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 +%wrolpi ALL= NOPASSWD:/opt/wrolpi/scripts/import_map.sh EOF chmod 660 /etc/sudoers.d/90-wrolpi # Verify this new file is valid.