|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Copyright (c) 2021-2025 community-scripts ORG |
| 4 | +# Author: MickLesk (CanbiZ) |
| 5 | +# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE |
| 6 | +# Source: https://github.com/dedicatedcode/reitti |
| 7 | + |
| 8 | +source /dev/stdin <<<"$FUNCTIONS_FILE_PATH" |
| 9 | +color |
| 10 | +verb_ip6 |
| 11 | +catch_errors |
| 12 | +setting_up_container |
| 13 | +network_check |
| 14 | +update_os |
| 15 | + |
| 16 | +msg_info "Installing Dependencies" |
| 17 | +$STD apt install -y \ |
| 18 | + redis-server \ |
| 19 | + rabbitmq-server \ |
| 20 | + libpq-dev \ |
| 21 | + zstd |
| 22 | +msg_ok "Installed Dependencies" |
| 23 | + |
| 24 | +JAVA_VERSION="24" setup_java |
| 25 | +PG_VERSION="17" PG_MODULES="postgis" setup_postgresql |
| 26 | + |
| 27 | +msg_info "Setting up PostgreSQL" |
| 28 | +DB_NAME="reitti_db" |
| 29 | +DB_USER="reitti" |
| 30 | +DB_PASS="$(openssl rand -base64 18 | tr -dc 'a-zA-Z0-9' | cut -c1-13)" |
| 31 | +$STD sudo -u postgres psql -c "CREATE ROLE $DB_USER WITH LOGIN PASSWORD '$DB_PASS';" |
| 32 | +$STD sudo -u postgres psql -c "CREATE DATABASE $DB_NAME WITH OWNER $DB_USER ENCODING 'UTF8' TEMPLATE template0;" |
| 33 | +$STD sudo -u postgres psql -c "ALTER ROLE $DB_USER SET client_encoding TO 'utf8';" |
| 34 | +$STD sudo -u postgres psql -c "ALTER ROLE $DB_USER SET default_transaction_isolation TO 'read committed';" |
| 35 | +$STD sudo -u postgres psql -c "ALTER ROLE $DB_USER SET timezone TO 'UTC';" |
| 36 | +$STD sudo -u postgres psql -d "$DB_NAME" -c "CREATE EXTENSION IF NOT EXISTS postgis;" |
| 37 | +$STD sudo -u postgres psql -d "$DB_NAME" -c "CREATE EXTENSION IF NOT EXISTS postgis_topology;" |
| 38 | +{ |
| 39 | + echo "Reitti Credentials" |
| 40 | + echo "Database Name: $DB_NAME" |
| 41 | + echo "Database User: $DB_USER" |
| 42 | + echo "Database Password: $DB_PASS" |
| 43 | +} >>~/reitti.creds |
| 44 | +msg_ok "PostgreSQL Setup Completed" |
| 45 | + |
| 46 | +msg_info "Configuring RabbitMQ" |
| 47 | +RABBIT_USER="reitti" |
| 48 | +RABBIT_PASS="$(openssl rand -base64 18 | tr -dc 'a-zA-Z0-9' | cut -c1-13)" |
| 49 | +RABBIT_VHOST="/" |
| 50 | +$STD rabbitmqctl add_user "$RABBIT_USER" "$RABBIT_PASS" |
| 51 | +$STD rabbitmqctl add_vhost "$RABBIT_VHOST" |
| 52 | +$STD rabbitmqctl set_permissions -p "$RABBIT_VHOST" "$RABBIT_USER" ".*" ".*" ".*" |
| 53 | +$STD rabbitmqctl set_user_tags "$RABBIT_USER" administrator |
| 54 | +{ |
| 55 | + echo "" |
| 56 | + echo "Reitti Credentials" |
| 57 | + echo "RabbitMQ User: $RABBIT_USER" |
| 58 | + echo "RabbitMQ Password: $RABBIT_PASS" |
| 59 | +} >>~/reitti.creds |
| 60 | +msg_ok "Configured RabbitMQ" |
| 61 | + |
| 62 | +USE_ORIGINAL_FILENAME="true" fetch_and_deploy_gh_release "reitti" "dedicatedcode/reitti" "singlefile" "latest" "/opt/reitti" "reitti-app.jar" |
| 63 | +mv /opt/reitti/reitti-*.jar /opt/reitti/reitti.jar |
| 64 | +USE_ORIGINAL_FILENAME="true" fetch_and_deploy_gh_release "photon" "komoot/photon" "singlefile" "latest" "/opt/photon" "photon-0*.jar" |
| 65 | +mv /opt/photon/photon-*.jar /opt/photon/photon.jar |
| 66 | + |
| 67 | +msg_info "Creating Reitti Configuration-File" |
| 68 | +cat <<EOF >/opt/reitti/application.properties |
| 69 | +# Reitti Server Base URI |
| 70 | +reitti.server.advertise-uri=http://127.0.0.1:8080 |
| 71 | +
|
| 72 | +# PostgreSQL Database Connection |
| 73 | +spring.datasource.url=jdbc:postgresql://127.0.0.1:5432/$DB_NAME |
| 74 | +spring.datasource.username=$DB_USER |
| 75 | +spring.datasource.password=$DB_PASS |
| 76 | +spring.datasource.driver-class-name=org.postgresql.Driver |
| 77 | +
|
| 78 | +# Flyway Database Migrations |
| 79 | +spring.flyway.enabled=true |
| 80 | +spring.flyway.locations=classpath:db/migration |
| 81 | +spring.flyway.baseline-on-migrate=true |
| 82 | +
|
| 83 | +# RabbitMQ (Message Queue) |
| 84 | +spring.rabbitmq.host=127.0.0.1 |
| 85 | +spring.rabbitmq.port=5672 |
| 86 | +spring.rabbitmq.username=$RABBIT_USER |
| 87 | +spring.rabbitmq.password=$RABBIT_PASS |
| 88 | +
|
| 89 | +# Redis (Cache) |
| 90 | +spring.data.redis.host=127.0.0.1 |
| 91 | +spring.data.redis.port=6379 |
| 92 | +
|
| 93 | +# Server Port |
| 94 | +server.port=8080 |
| 95 | +
|
| 96 | +# Optional: Logging & Performance |
| 97 | +logging.level.root=INFO |
| 98 | +spring.jpa.hibernate.ddl-auto=none |
| 99 | +spring.datasource.hikari.maximum-pool-size=10 |
| 100 | +
|
| 101 | +# OIDC / Security Settings |
| 102 | +reitti.security.oidc.registration.enabled=false |
| 103 | +
|
| 104 | +# Photon (Geocoding) |
| 105 | +PHOTON_BASE_URL=http://127.0.0.1:2322 |
| 106 | +PROCESSING_WAIT_TIME=15 |
| 107 | +PROCESSING_BATCH_SIZE=1000 |
| 108 | +PROCESSING_WORKERS_PER_QUEUE=4-16 |
| 109 | +
|
| 110 | +# Disable potentially dangerous features unless needed |
| 111 | +DANGEROUS_LIFE=false |
| 112 | +EOF |
| 113 | +msg_ok "Created Configuration-File for Reitti" |
| 114 | + |
| 115 | +msg_info "Creating Services" |
| 116 | +cat <<EOF >/etc/systemd/system/reitti.service |
| 117 | +[Unit] |
| 118 | +Description=Reitti |
| 119 | +After=network.target postgresql.service redis-server.service rabbitmq-server.service photon.service |
| 120 | +Wants=postgresql.service redis-server.service rabbitmq-server.service photon.service |
| 121 | +
|
| 122 | +[Service] |
| 123 | +Type=simple |
| 124 | +WorkingDirectory=/opt/reitti/ |
| 125 | +ExecStart=/usr/bin/java --enable-native-access=ALL-UNNAMED -jar -Xmx2g reitti.jar |
| 126 | +TimeoutStopSec=20 |
| 127 | +KillMode=process |
| 128 | +Restart=on-failure |
| 129 | +
|
| 130 | +[Install] |
| 131 | +WantedBy=multi-user.target |
| 132 | +EOF |
| 133 | + |
| 134 | +cat <<'EOF' >/etc/systemd/system/photon.service |
| 135 | +[Unit] |
| 136 | +Description=Photon Geocoding Service (Germany, OpenSearch) |
| 137 | +After=network.target |
| 138 | +
|
| 139 | +[Service] |
| 140 | +Type=simple |
| 141 | +WorkingDirectory=/opt/photon |
| 142 | +ExecStart=/usr/bin/java -Xmx4g -jar photon.jar \ |
| 143 | + -data-dir /opt/photon \ |
| 144 | + -listen-port 2322 \ |
| 145 | + -listen-ip 0.0.0.0 \ |
| 146 | + -cors-any |
| 147 | +Restart=on-failure |
| 148 | +TimeoutStopSec=20 |
| 149 | +
|
| 150 | +[Install] |
| 151 | +WantedBy=multi-user.target |
| 152 | +EOF |
| 153 | +systemctl enable -q --now photon |
| 154 | +systemctl enable -q --now reitti |
| 155 | +msg_ok "Created Services" |
| 156 | + |
| 157 | +motd_ssh |
| 158 | +customize |
| 159 | + |
| 160 | +msg_info "Cleaning up" |
| 161 | +$STD apt -y autoremove |
| 162 | +$STD apt -y autoclean |
| 163 | +$STD apt -y clean |
| 164 | +msg_ok "Cleaned" |
0 commit comments