Skip to main content

Resetting OSM Data (reboot)

A "reboot" involves resetting the reference data based on a new OpenStreetMap extract and restarting the validation and integration process from that point onward.

This is useful after an application update, especially if the update fixes bugs in the Python scripts that load and integrate OSM differences into the database, to ensure that no errors are carried over.

Suspension of Services​

sudo systemctl list-units --type=timer --state=active --plain --no-legend 'lbt-*.timer' | awk '{print $1}' | sudo tee "/tmp/active-timers.txt" >/dev/null
while IFS= read -r lbt_timer; do
sudo systemctl stop "$lbt_timer"
done < <(sudo cat "/tmp/active-timers.txt")
while true; do
lbt_running_jobs=$(sudo systemctl list-units --type=service --state=active,activating,deactivating,reloading --plain --no-legend lbt-pipeline.service lbt-integration.service lbt-segmentation.service lbt-cleaning.service lbt-email-digests.service)
if [ -z "$lbt_running_jobs" ]; then
break
fi
printf '%s\n' "$lbt_running_jobs"
sleep 5
done
sudo systemctl stop lbt-web.service

Data Cleaning and Resetting Load Settings​

We clear the osm2pgrouting and osm2pgsql tables, which will be reloaded from the new PBF file; then we move the objects that still need to be validated to the history and clear the validation tables. Finally, certain application settings are reset.

Connect to the application database (for example, "lebontag_production"), then:

BEGIN;
SET LOCAL lock_timeout='5s';

DO $$ BEGIN
IF to_regclass('lebontag.lbt_integration_batch') IS NOT NULL THEN
IF EXISTS(SELECT 1 FROM lebontag.lbt_integration_batch WHERE state IN ('prepared','running','needs_review')) THEN
RAISE EXCEPTION 'Lot actif : terminer sa résolution ou annulation avant tout rechargement de référence.';
END IF;
END IF;
IF to_regclass('lebontag.lbt_email_digest') IS NOT NULL THEN
IF EXISTS(SELECT 1 FROM lebontag.lbt_email_digest WHERE state IN ('preparing','sending','uncertain')) THEN
RAISE EXCEPTION 'Email en cours/incertain : résoudre avant réinitialisation.';
END IF;
END IF;
END $$;

DO $$ BEGIN
IF to_regclass('lebontag.lbt_relation_context') IS NOT NULL THEN TRUNCATE lebontag.lbt_relation_context; END IF;
IF to_regclass('lebontag.lbt_repl_queue') IS NOT NULL THEN TRUNCATE lebontag.lbt_repl_queue; END IF;
IF to_regclass('lebontag.lbt_repl_state') IS NOT NULL THEN
UPDATE lebontag.lbt_repl_state SET last_done_seq=0,updated_at=now() WHERE id=1;
END IF;
IF to_regclass('lebontag.lbt_notification_state') IS NOT NULL THEN DELETE FROM lebontag.lbt_notification_state; END IF;
IF to_regclass('lebontag.lbt_email_digest') IS NOT NULL THEN UPDATE lebontag.lbt_email_digest SET baseline=NULL,prepared_baseline=NULL; END IF;
END $$;

TRUNCATE TABLE osm2pgsql.osm2pgsql_properties;
TRUNCATE TABLE osm2pgsql.osm_users;
TRUNCATE TABLE osm2pgsql.osm_line CASCADE;
TRUNCATE TABLE osm2pgsql.osm_nodes CASCADE;
TRUNCATE TABLE osm2pgsql.osm_point CASCADE;
TRUNCATE TABLE osm2pgsql.osm_polygon CASCADE;
TRUNCATE TABLE osm2pgsql.osm_rels CASCADE;
TRUNCATE TABLE osm2pgsql.osm_roads CASCADE;
TRUNCATE TABLE osm2pgsql.osm_ways CASCADE;
TRUNCATE TABLE osm2pgrouting.pgr_ways_vertices CASCADE;
TRUNCATE TABLE osm2pgrouting.pgr_ways CASCADE;
INSERT INTO lebontag.lbt_osmdiff_history (SELECT * FROM lebontag.lbt_osmdiff) ON CONFLICT (od_id,od_element,od_new_version) DO NOTHING;
TRUNCATE lebontag.lbt_validation,lebontag.lbt_osmdiff_footprint, lebontag.lbt_osmdiff,lebontag.lbt_quality_processed_items;
UPDATE lebontag.lbt_setting SET s_value = '' WHERE s_name = 'osm_diff_nodes_date';
UPDATE lebontag.lbt_setting SET s_value = '' WHERE s_name = 'osm_diff_ways_date';
UPDATE lebontag.lbt_setting SET s_value = '' WHERE s_name = 'osm_diff_relations_date';
UPDATE lebontag.lbt_setting SET s_value = '0' WHERE s_name = 'osm_diff_nodes_attempts';
UPDATE lebontag.lbt_setting SET s_value = '0' WHERE s_name = 'osm_diff_ways_attempts';
UPDATE lebontag.lbt_setting SET s_value = '0' WHERE s_name = 'osm_diff_relations_attempts';

COMMIT;

File Cleanup​

sudo rm -R /opt/le-bon-tag/log/* && \
sudo rm -R /opt/le-bon-tag/osm/changeset/* && \
sudo rm -R /opt/le-bon-tag/osm/integration/* && \
sudo rm -R /opt/le-bon-tag/osm/osc_update/* && \
sudo rm -R /opt/le-bon-tag/osm/prepare/* && \
sudo rm /opt/le-bon-tag/osm/replication/* && \
sudo rm -R /opt/le-bon-tag/osm/source/*

Loading the New PBF Export File​

Follow the "OSM Reference Data" procedures in the installation document.

Restarting the Application​

sudo systemctl daemon-reload
sudo systemctl start lbt-web.service
while IFS= read -r lbt_timer; do
sudo systemctl start "$lbt_timer"
done < <(sudo cat "/tmp/active-timers.txt")
sudo rm /tmp/active-timers.txt