Stopping/starting renderd during map import. Moving tile cache clearing to import script.

This commit is contained in:
Roland 2023-08-17 11:47:34 -06:00
parent 6376e6539b
commit 6791e88baf
No known key found for this signature in database
GPG key ID: 9D6DBD3ACF11AB93
8 changed files with 26 additions and 49 deletions

View file

@ -151,15 +151,6 @@ export class Settings extends React.Component {
/>
</div>
<div style={{margin: '0.5em'}}>
<Toggle
label='WiFi Hotspot on Startup'
disabled={disabled || hotspot_on_startup === null}
checked={hotspot_on_startup === true}
onChange={checked => this.handleInputChange(null, 'hotspot_on_startup', checked)}
/>
</div>
<div style={{margin: '0.5em'}}>
<Toggle
label='CPU Power-save on Startup'

View file

@ -8,12 +8,12 @@ from sqlalchemy.orm import Session
from modules.map.models import MapFile
from wrolpi import flags
from wrolpi.cmd import BASH_BIN
from wrolpi.common import get_media_directory, walk, logger, wrol_mode_check
from wrolpi.cmd import SUDO_BIN
from wrolpi.common import get_media_directory, walk, logger
from wrolpi.dates import now, timedelta_to_timestamp, seconds_to_timestamp
from wrolpi.db import optional_session, get_db_session
from wrolpi.events import Events
from wrolpi.vars import PYTEST, PROJECT_DIR
from wrolpi.vars import PROJECT_DIR
logger = logger.getChild(__name__)
@ -156,8 +156,6 @@ async def import_files(paths: List[str]):
map_file.imported = True
finally:
if any_success:
# A map was imported, remove the tile cache files.
await clear_mod_tile()
Events.send_map_import_complete(f'Map import completed; took {seconds_to_timestamp(total_elapsed)}')
else:
Events.send_map_import_failed(f'Map import failed! See server logs.')
@ -193,7 +191,8 @@ async def run_import_command(*paths: Path) -> 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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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.

View file

@ -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.