diff --git a/.underpass b/.underpass deleted file mode 100644 index fdcfa76d..00000000 --- a/.underpass +++ /dev/null @@ -1,7 +0,0 @@ -# Underpass config -# Edit and copy this file to $HOME -config: - - planet_servers: - - planet.openstreetmap.org - - underpass_db_url: - - underpass@postgis/underpass diff --git a/Makefile.am b/Makefile.am index d55919be..407fe8d3 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,5 +1,5 @@ # -# Copyright (c) 2020, 2021, 2022, 2023 Humanitarian OpenStreetMap Team +# Copyright (c) 2020, 2021, 2022, 2023, 2024 Humanitarian OpenStreetMap Team # # This file is part of Underpass. # @@ -152,13 +152,14 @@ endif install-data-hook: $(MKDIR_P) $(DESTDIR)/$(pkglibdir) - $(MKDIR_P) $(DESTDIR)/$(pkglibdir)/config - cp -rvp $(srcdir)/config/priority.geojson $(DESTDIR)/$(pkglibdir)/config - $(MKDIR_P) $(DESTDIR)/$(pkglibdir)/config/replicator - cp -vp $(srcdir)/config/replicator/planetreplicator.yaml $(DESTDIR)/$(pkglibdir)/config/replicator - cp -rvp $(srcdir)/config/stats $(DESTDIR)/$(pkglibdir)/config + $(MKDIR_P) /etc/underpass + cp -rvp $(srcdir)/config/priority.geojson /etc/underpass/ + cp -rvp $(srcdir)/config/replicator /etc/underpass/ + cp -rvp $(srcdir)/config/stats /etc/underpass/ + cp -rvp $(srcdir)/config/default.yaml /etc/underpass/ $(MKDIR_P) $(DESTDIR)/$(docdir) cp -rvp $(srcdir)/docs/*.md $(DESTDIR)/$(docdir) + cp -rvp $(srcdir)/setup/service $(DESTDIR)/$(pkglibdir) dist-hook: apidoc $(MKDIR_P) $(DESTDIR)/$(docdir) diff --git a/config/default.yaml b/config/default.yaml new file mode 100644 index 00000000..b960e224 --- /dev/null +++ b/config/default.yaml @@ -0,0 +1,9 @@ +# Underpass config file +config: + - underpass_db_url: + - underpass:underpass@localhost:5432/underpass + - planet_servers: + - planet.openstreetmap.org + - destdir_base: + - /usr/local/lib/underpass/data/ + diff --git a/setup/service/restart.sh b/setup/service/restart.sh new file mode 100644 index 00000000..2a5afe54 --- /dev/null +++ b/setup/service/restart.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +# Read destdir_base from Underpass YAML configuration file +destdir_base=$(grep -A 1 destdir_base /etc/underpass/default.yaml | tail -n 1 | sed 's/^[[:space:]]*- //') + +# Get latest downloaded Changeset and OsmChange +changeseturl=$(find ${destdir_base:+$destdir_base}replication/changesets/ -type f -printf '%T@ %p\n' | sort -n | tail -n 1 | cut -d ' ' -f 2- | grep -oE '[0-9]{3}\/[0-9]{3}/[0-9]{3}') +minuteurl=$(find ${destdir_base:+$destdir_base}replication/minute/ -type f -printf '%T@ %p\n' | sort -n | tail -n 1 | cut -d ' ' -f 2- | grep -oE '[0-9]{3}\/[0-9]{3}/[0-9]{3}') + +underpass -u "$minuteurl" --changeseturl "$changeseturl" \ No newline at end of file diff --git a/setup/service/start.sh b/setup/service/start.sh new file mode 100644 index 00000000..1e900b7a --- /dev/null +++ b/setup/service/start.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +underpass -t $(date +%Y-%m-%dT%H:%M:%S -d "3 days ago") \ No newline at end of file diff --git a/setup/service/underpass.service b/setup/service/underpass.service new file mode 100644 index 00000000..7763948e --- /dev/null +++ b/setup/service/underpass.service @@ -0,0 +1,16 @@ +[Unit] +Description=Underpass replication service +After=syslog.target + +[Service] +ExecStart=/usr/local/lib/underpass/service/start.sh +ExecRestart=/usr/local/lib/underpass/service/restart.sh +WorkingDirectory=/usr/local/lib/underpass/ +Restart=always +KillSignal=SIGQUIT +Type=simple +StandardError=syslog +NotifyAccess=all + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/src/replicator/planetreplicator.cc b/src/replicator/planetreplicator.cc index 94731950..15ac3fe6 100644 --- a/src/replicator/planetreplicator.cc +++ b/src/replicator/planetreplicator.cc @@ -1,5 +1,5 @@ // -// Copyright (c) 2020, 2021, 2022, 2023 Humanitarian OpenStreetMap Team +// Copyright (c) 2020, 2021, 2022, 2023, 2024 Humanitarian OpenStreetMap Team // // This file is part of Underpass. // @@ -102,8 +102,7 @@ PlanetReplicator::PlanetReplicator(void) {}; std::shared_ptr PlanetReplicator::findRemotePath(const underpassconfig::UnderpassConfig &config, ptime time) { yaml::Yaml yaml; - std::string rep_file = PKGLIBDIR; - rep_file += "/config/replicator/planetreplicator.yaml"; + std::string rep_file = "/etc/underpass/replicator/planetreplicator.yaml"; yaml.read(rep_file); std::map hashes; diff --git a/src/stats/statsconfig.cc b/src/stats/statsconfig.cc index a2c6df21..5acc6094 100644 --- a/src/stats/statsconfig.cc +++ b/src/stats/statsconfig.cc @@ -1,5 +1,5 @@ // -// Copyright (c) 2020, 2021, 2022, 2023 Humanitarian OpenStreetMap Team +// Copyright (c) 2020, 2021, 2022, 2023, 2024 Humanitarian OpenStreetMap Team // // This file is part of Underpass. // @@ -51,8 +51,7 @@ namespace statsconfig { StatsConfig::StatsConfig() { if (path.empty()) { - path = PKGLIBDIR; - path += "/config/stats/statistics.yaml"; + path = "/etc/underpass/stats/statistics.yaml"; if (!boost::filesystem::exists(path)) { throw std::runtime_error("Statistics file not found: " + path); } diff --git a/src/testsuite/libunderpass.all/geo-test.cc b/src/testsuite/libunderpass.all/geo-test.cc index 5b88fc34..fc63ccc9 100644 --- a/src/testsuite/libunderpass.all/geo-test.cc +++ b/src/testsuite/libunderpass.all/geo-test.cc @@ -61,7 +61,7 @@ main(int argc, char* argv[]) return 1; } - if (tgu.readFile("/usr/local/lib/underpass/config/priority.geojson")) { + if (tgu.readFile("/etc/underpass/priority.geojson")) { runtest.pass("Read file with absolute path"); } else { runtest.fail("Read file with absolute path"); diff --git a/src/underpass.cc b/src/underpass.cc index 843193e3..e4028ae8 100644 --- a/src/underpass.cc +++ b/src/underpass.cc @@ -88,8 +88,7 @@ main(int argc, char *argv[]) std::string starting_url_path; std::string datadir = "replication/"; - std::string boundary = PKGLIBDIR; - boundary += "/config/priority.geojson"; + std::string boundary = "/etc/underpass/priority.geojson"; UnderpassConfig config; diff --git a/src/underpassconfig.hh b/src/underpassconfig.hh index acb288eb..45446e14 100644 --- a/src/underpassconfig.hh +++ b/src/underpassconfig.hh @@ -1,5 +1,5 @@ // -// Copyright (c) 2020, 2021, 2022, 2023 Humanitarian OpenStreetMap Team +// Copyright (c) 2020, 2021, 2022, 2023, 2024 Humanitarian OpenStreetMap Team // // This file is part of Underpass. // @@ -103,10 +103,9 @@ struct UnderpassConfig { UnderpassConfig() { - std::string homedir = getenv("HOME"); - if (std::filesystem::exists(homedir + "/.underpass")) { + if (std::filesystem::exists("/etc/underpass/default.yaml")) { yaml::Yaml yaml; - yaml.read(homedir + "/.underpass"); + yaml.read("/etc/underpass/default.yaml"); auto yamlConfig = yaml.get("config"); if (yaml.contains_key("underpass_db_url")) { underpass_db_url = yamlConfig.get_value("underpass_db_url"); diff --git a/src/validate/validate.hh b/src/validate/validate.hh index a03439e0..e8d51e0e 100644 --- a/src/validate/validate.hh +++ b/src/validate/validate.hh @@ -171,8 +171,7 @@ class ValidateStatus { class BOOST_SYMBOL_VISIBLE Validate { public: Validate(void) { - std::string path = PKGLIBDIR; - path += "/config/validate"; + std::string path = "/etc/underpass/validate"; loadConfig(path); } diff --git a/utils/bootstrap.sh b/utils/bootstrap.sh index 4881ec99..45874f6c 100644 --- a/utils/bootstrap.sh +++ b/utils/bootstrap.sh @@ -110,11 +110,9 @@ then python3 poly2geojson.py $COUNTRY.poly if "$use_docker"; then - docker cp $COUNTRY.geojson underpass:/usr/local/lib/underpass/config/priority.geojson - docker cp $COUNTRY.geojson underpass:/code/config/priority.geojson + docker cp $COUNTRY.geojson underpass:/etc/underpass/priority.geojson else - cp $COUNTRY.geojson /usr/local/lib/underpass/config/priority.geojson - cp $COUNTRY.geojson ../config/priority.geojson + cp $COUNTRY.geojson /etc/underpass/priority.geojson fi echo "Bootstrapping database ..." if "$use_docker";