Created
December 20, 2024 04:44
-
-
Save febritecno/1a3c1361f2398b6794136e9a95d01a89 to your computer and use it in GitHub Desktop.
Graphhoper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Exit on error | |
set -e | |
# Variables | |
SERVICE_NAME="graphhopper" | |
SERVICE_FILE="/etc/systemd/system/${SERVICE_NAME}.service" | |
WORKING_DIR="$HOME/graphhopper/graphhopper" | |
JAVA_EXEC="/usr/bin/java" | |
JAR_PATH="web/target/graphhopper-web-*.jar" | |
CONFIG_FILE="config.yml" | |
JAVA_OPTS="-Xmx4g -Xms4g" | |
# Ensure GraphHopper directory exists | |
if [ ! -d "$WORKING_DIR" ]; then | |
echo "Error: Working directory $WORKING_DIR does not exist." | |
exit 1 | |
fi | |
# Create the service file | |
echo "Creating systemd service file at $SERVICE_FILE" | |
sudo tee "$SERVICE_FILE" > /dev/null << EOL | |
[Unit] | |
Description=GraphHopper Routing Engine | |
After=network.target | |
[Service] | |
Type=simple | |
User=$USER | |
WorkingDirectory=$WORKING_DIR | |
ExecStart=$JAVA_EXEC $JAVA_OPTS -jar $JAR_PATH server $CONFIG_FILE | |
Restart=always | |
[Install] | |
WantedBy=multi-user.target | |
EOL | |
# Reload systemd to load the new service | |
echo "Reloading systemd..." | |
sudo systemctl daemon-reload | |
# Enable the service to start on boot | |
echo "Enabling the GraphHopper service..." | |
sudo systemctl enable $SERVICE_NAME | |
# Start the service | |
echo "Starting the GraphHopper service..." | |
sudo systemctl start $SERVICE_NAME | |
# Show the service status | |
echo "Checking service status..." | |
sudo systemctl status $SERVICE_NAME | |
# Display the latest logs for the service | |
echo "Displaying the latest logs for the GraphHopper service:" | |
echo " sudo journalctl -u $SERVICE_NAME -n 50 --no-pager " |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e # Exit on error | |
# Update system and upgrade installed packages | |
sudo apt update && sudo apt upgrade -y | |
# Install necessary dependencies only if not already installed | |
if ! command -v java &>/dev/null; then | |
# Install Java | |
sudo apt install -y software-properties-common | |
sudo add-apt-repository -y ppa:openjdk-r/ppa | |
sudo apt update | |
sudo apt install -y openjdk-17-jdk | |
else | |
echo "Java is already installed." | |
fi | |
# Ensure JAVA_HOME is set securely | |
if ! grep -q "JAVA_HOME" ~/.bashrc; then | |
echo "export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64" >> ~/.bashrc | |
echo "export PATH=\$PATH:\$JAVA_HOME/bin" >> ~/.bashrc | |
source ~/.bashrc | |
else | |
echo "JAVA_HOME already configured." | |
fi | |
# Verify Java installation | |
java -version | |
# Install other dependencies (check if already installed) | |
for package in maven git wget unzip; do | |
if ! dpkg -l | grep -q "$package"; then | |
sudo apt install -y "$package" | |
else | |
echo "$package is already installed." | |
fi | |
done | |
# Create directory for GraphHopper | |
mkdir -p ~/graphhopper | |
cd ~/graphhopper | |
# Clone GraphHopper repository securely | |
if [ ! -d "graphhopper" ]; then | |
git clone https://github.com/graphhopper/graphhopper.git | |
fi | |
cd graphhopper | |
# Build GraphHopper (skip tests to save time) | |
mvn clean package -DskipTests | |
# Create directory for map data and download securely | |
mkdir -p map-data | |
cd map-data | |
# Secure download of OpenStreetMap data using HTTPS | |
if [ ! -f "indonesia-latest.osm.pbf" ]; then | |
wget https://download.geofabrik.de/asia/indonesia-latest.osm.pbf | |
else | |
echo "Map data already downloaded." | |
fi | |
cd .. | |
# Check if config.yml already exists | |
if [ -f "config.yml" ]; then | |
echo "config.yml already exists. Skipping creation." | |
else | |
# Create a secure config file if it doesn't exist | |
cat > config.yml << EOL | |
graphhopper: | |
# OpenStreetMap input file | |
datareader.file: "map-data/indonesia-latest.osm.pbf" | |
# Local folder for GraphHopper data storage | |
graph.location: graph-cache | |
# Basic profiles with simple custom model | |
profiles: | |
- name: car | |
custom_model: | |
speed: | |
- if: "true" | |
limit_to: "car_average_speed" | |
# Enable speed mode for car profile | |
profiles_ch: | |
- profile: car | |
routing.snap_preventions_default: tunnel, bridge, ferry | |
routing.max_visited_nodes: 1000000 | |
# Required encoded values for basic car routing | |
graph.encoded_values: road_class,road_class_link,road_environment,max_speed,road_access,car_access,car_average_speed | |
# Minimum size for connected components | |
prepare.min_network_size: 200 | |
prepare.subnetworks.threads: 2 | |
# Memory configuration | |
graph.dataaccess.default_type: RAM_STORE | |
# Ignore unnecessary highway types for car routing | |
import.osm.ignored_highways: footway,cycleway,path,pedestrian,steps | |
# Server configuration | |
server: | |
application_connectors: | |
- type: http | |
port: 8989 | |
bind_host: localhost | |
admin_connectors: | |
- type: http | |
port: 8990 | |
bind_host: localhost | |
# Logging configuration | |
logging: | |
appenders: | |
- type: console | |
time_zone: UTC | |
log_format: "%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n" | |
loggers: | |
"com.graphhopper.osm_warnings": | |
level: DEBUG | |
additive: false | |
appenders: | |
- type: console | |
logFormat: '[%level] %msg%n' | |
EOL | |
echo "config.yml created successfully." | |
fi | |
# Start GraphHopper with the secure config | |
java -Xmx8g -Xms4g -jar web/target/graphhopper-web-*.jar server config.yml |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment