feat: automate Overpass API setup and monitoring

Introduce a complete setup for the Overpass API on Debian. Add necessary scripts and configuration files to automate the installation and configuration process, including setting up Apache and creating systemd services for automatic startup.

- Add an example Apache configuration file.
- Implement a Debian installation script for the Overpass API.
- Create a systemd service and timer for monitoring Overpass OSC and restart if no output is detected.
- Set up additional systemd services for Overpass processes to ensure continuous operations.

This setup simplifies deployment and enhances reliability by monitoring services and ensuring they restart automatically if needed.
This commit is contained in:
Kumi 2024-10-26 09:10:49 +02:00
commit e3f5293ebc
Signed by: kumi
GPG key ID: ECBCC9082395383F
9 changed files with 150 additions and 0 deletions

24
apache/example.conf Normal file
View file

@ -0,0 +1,24 @@
<VirtualHost [::]:80>
ServerAdmin webmaster@localhost
DocumentRoot /opt/osm/html/
ServerName your.hostname.here
Header set Overpass-Worker "worker-name-here"
ScriptAlias /api/ /opt/osm/cgi-bin/
TimeOut 86400
<Directory "/opt/osm/html/">
Require all granted
</Directory>
<Directory "/opt/osm/cgi-bin/">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Require all granted
</Directory>
ErrorLog /var/log/apache2/error.log
LogLevel warn
</VirtualHost>

53
install-debian.sh Normal file
View file

@ -0,0 +1,53 @@
#!/bin/bash
# Install Overpass API
# Step 1: Install required software packages
echo "Installing required packages..."
apt install wget g++ make expat libexpat1-dev zlib1g-dev liblz4-dev -y
# Step 2: Download the latest release of Overpass API
cd /opt
echo "Downloading Overpass API..."
wget https://dev.overpass-api.de/releases/osm-3s_latest.tar.gz
# Extract the package
echo "Extracting package..."
tar -xzf osm-3s_latest.tar.gz
# Navigate into the extracted directory
EXTRACTED_DIR=$(tar -tf osm-3s_latest.tar.gz | head -1 | cut -f1 -d"/")
ln -s "$EXTRACTED_DIR" osm
cd "$EXTRACTED_DIR"
# Compile the software
echo "Compiling Overpass API..."
./configure --enable-lz4
make
chmod 755 bin/*.sh cgi-bin/*
# Step 3: Load Data
DB_DIR="db"
echo "Cloning the database..."
mkdir -p $DB_DIR
bin/download_clone.sh --db-dir="$DB_DIR/" --meta=attic --source="https://dev.overpass-api.de/api_drolbr/"
# Step 4: Create system user
echo "Creating system user..."
useradd -m osm
chown -R osm:osm .
# Step 5: Set up systemd service files
echo "Setting up services..."
SCRIPT_DIR=$(dirname "$0")
cp "$SCRIPT_DIR/systemd/*" /etc/systemd/system/
install "$SCRIPT_DIR/oscmonitor/oscmonitor" /usr/local/bin/
systemctl enable --now overpass
systemctl enable --now overpassareas
systemctl enable --now overpassloop
systemctl enable --now overpassosc
systemctl enable --now oscmonitor.timer
echo "Overpass API installation completed."
echo "Please set up Apache based on the apache/example.conf file."

8
oscmonitor/oscmonitor Normal file
View file

@ -0,0 +1,8 @@
#!/bin/bash
SERVICE_NAME="overpassosc"
if journalctl -u $SERVICE_NAME --since "1 hour ago" | grep -q -- '-- No entries --'; then
echo "No output from $SERVICE_NAME in the last hour. Restarting..."
systemctl restart $SERVICE_NAME
fi

View file

@ -0,0 +1,6 @@
[Unit]
Description=Overpass OSC Monitor
[Service]
Type=oneshot
ExecStart=/usr/local/bin/oscmonitor

9
systemd/oscmonitor.timer Normal file
View file

@ -0,0 +1,9 @@
[Unit]
Description=Overpass OSC Monitor Timer
[Timer]
OnBootSec=3600s
OnUnitActiveSec=3600s
[Install]
WantedBy=timers.target

11
systemd/overpass.service Normal file
View file

@ -0,0 +1,11 @@
[Service]
User = osm
Group = osm
WorkingDirectory = /opt/osm/
ExecStartPre=/bin/sh -c "rm -f /opt/osm/db/osm*_base || true"
ExecStartPre=/bin/sh -c "rm -f /dev/shm/osm*_base || true"
ExecStart=/opt/osm/bin/dispatcher --osm-base --attic --db-dir=/opt/osm/db --rate-limit=-1 --allow-duplicate-queries=yes
LimitNOFILE=10000
[Install]
WantedBy=multi-user.target

View file

@ -0,0 +1,15 @@
[Unit]
Description = Overpass Areas
After = overpass.service
[Service]
User = osm
Group = nogroup
WorkingDirectory = /opt/osm/
ExecStartPre=/bin/sh -c "rm -f /opt/osm/db/osm3s*_areas || true"
ExecStartPre=/bin/sh -c "rm -f /dev/shm/osm3s*_areas || true"
ExecStart=/opt/osm/bin/dispatcher --areas --db-dir=/opt/osm/db --rate-limit=-1 --allow-duplicate-queries=yes
LimitNOFILE=10000
[Install]
WantedBy=multi-user.target

View file

@ -0,0 +1,12 @@
[Unit]
Description = Overpass Area Loop
After = overpass.service
[Service]
User = osm
Group = osm
WorkingDirectory = /opt/osm/
ExecStart=/opt/osm/bin/rules_loop.sh "db/"
[Install]
WantedBy=multi-user.target

View file

@ -0,0 +1,12 @@
[Unit]
Description = Overpass OSC
After = overpass.service
[Service]
User = osm
Group = osm
WorkingDirectory = /opt/osm/
ExecStart=/opt/osm/bin/fetch_osc_and_apply.sh "http://planet.openstreetmap.org/replication/minute" --meta=attic
[Install]
WantedBy=multi-user.target