Skip to content
This repository has been archived by the owner on Oct 5, 2024. It is now read-only.

Commit

Permalink
+ Systemd service, config files moved to /etc
Browse files Browse the repository at this point in the history
  • Loading branch information
emi420 committed Feb 20, 2024
1 parent 797d4ac commit 50fb312
Show file tree
Hide file tree
Showing 13 changed files with 57 additions and 32 deletions.
7 changes: 0 additions & 7 deletions .underpass

This file was deleted.

13 changes: 7 additions & 6 deletions Makefile.am
Original file line number Diff line number Diff line change
@@ -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.
#
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions config/default.yaml
Original file line number Diff line number Diff line change
@@ -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/

10 changes: 10 additions & 0 deletions setup/service/restart.sh
Original file line number Diff line number Diff line change
@@ -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"
3 changes: 3 additions & 0 deletions setup/service/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

underpass -t $(date +%Y-%m-%dT%H:%M:%S -d "3 days ago")
16 changes: 16 additions & 0 deletions setup/service/underpass.service
Original file line number Diff line number Diff line change
@@ -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
5 changes: 2 additions & 3 deletions src/replicator/planetreplicator.cc
Original file line number Diff line number Diff line change
@@ -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.
//
Expand Down Expand Up @@ -102,8 +102,7 @@ PlanetReplicator::PlanetReplicator(void) {};
std::shared_ptr<RemoteURL> 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<int, ptime> hashes;

Expand Down
5 changes: 2 additions & 3 deletions src/stats/statsconfig.cc
Original file line number Diff line number Diff line change
@@ -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.
//
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/testsuite/libunderpass.all/geo-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
3 changes: 1 addition & 2 deletions src/underpass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
7 changes: 3 additions & 4 deletions src/underpassconfig.hh
Original file line number Diff line number Diff line change
@@ -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.
//
Expand Down Expand Up @@ -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");
Expand Down
3 changes: 1 addition & 2 deletions src/validate/validate.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
6 changes: 2 additions & 4 deletions utils/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit 50fb312

Please sign in to comment.