Skip to content

Instantly share code, notes, and snippets.

@mster429
Last active October 1, 2023 08:12
Show Gist options
  • Save mster429/1b0bfe4d39eccd104165effedb09e937 to your computer and use it in GitHub Desktop.
Save mster429/1b0bfe4d39eccd104165effedb09e937 to your computer and use it in GitHub Desktop.
Shell script to install osrm service is centos 7
#!/bin/bash
OSRM_VERSION="5.24"
#Colours
GREEN='\e[32m'
YELLOW='\e[33m'
NC='\033[0m' # No Color
#Install dependencies
printf "${YELLOW}Installing required dependencies\n${NC}"
yum install -y yum-utils centos-release-scl
yum-config-manager --enable rhel-server-rhscl-7-rpms
yum install -y devtoolset-7 git wget cmake3 zlib-devel boost boost-devel java-1.8.0-openjdk-devel
source /opt/rh/devtoolset-7/enable
printf "${GREEN}Installing dependencies completed\n${NC}"
#Install osrm-backend
printf "${YELLOW}Installing OSRM\n${NC}"
cd /opt
git clone https://github.com/Project-OSRM/osrm-backend.git
cd osrm-backend
git checkout ${OSRM_VERSION}
mkdir -p build
cd build
cmake3 .. -DENABLE_MASON=ON -DCMAKE_CXX_COMPILER=/opt/rh/devtoolset-7/root/usr/bin/g++
make
make install
echo 'pathmunge /opt/osrm-backend/build/' > /etc/profile.d/osrm.sh
chmod +x /etc/profile.d/osrm.sh
source /etc/profile
printf "${GREEN}Installing OSRM completed\n${NC}"
#Installing Osmosis tool for dataset merging
printf "${YELLOW}Installing Osmosis tool for merging datasets\n${NC}"
OSMOSIS_VERSION=0.48.3
cd /opt
wget https://github.com/openstreetmap/osmosis/releases/download/${OSMOSIS_VERSION}/osmosis-${OSMOSIS_VERSION}.tgz
mkdir -p osmosis
mv osmosis-*.tgz osmosis
cd osmosis
tar xvfz osmosis-*.tgz
rm -f osmosis-*.tgz
chmod a+x bin/osmosis
echo 'pathmunge /opt/osmosis/bin' > /etc/profile.d/osmosis.sh
chmod +x /etc/profile.d/osmosis.sh
source /etc/profile
printf "${GREEN}Installing Osmosis tool completed\n${NC}"
#Downloading and Merging OSM dataset
cd /opt
mkdir -p osrm_data
cd osrm_data
printf "${YELLOW}Downloading datasets\n${NC}"
wget http://download.geofabrik.de/asia/sri-lanka-latest.osm.pbf
wget http://download.geofabrik.de/asia/maldives-latest.osm.pbf
printf "${GREEN}Downloading Datasets completed\n${NC}"
printf "${YELLOW}Merging Datasets\n${NC}"
osmosis --read-pbf sri-lanka-latest.osm.pbf --read-pbf maldives-latest.osm.pbf --merge --write-pbf sl-mald.osm.pbf
printf "${GREEN}Merging Datasets completed\n${NC}"
#Compile Dataset
printf "${YELLOW}Compiling dataset\n${NC}"
cd /opt/osrm_data
osrm-extract sl-mald.osm.pbf -p ../osrm-backend/profiles/car.lua
osrm-contract sl-mald.osrm
printf "${GREEN}Compiling Dataset completed\n${NC}"
#Create Config Files
mkdir -p /opt/osrm
echo "DATA_FILE=/opt/osrm_data/sl-mald.osrm" > /opt/osrm/ENV_CONFIG
# Create systemd service file
printf "${YELLOW}Adding systemd file\n${NC}"
cat <<'EOF' > /etc/systemd/system/osrm-routed.service
[Unit]
Description=OSRM Service
After=network.target
Wants=network.target
[Service]
Type=simple
EnvironmentFile=/opt/osrm/ENV_CONFIG
ExecStart=/usr/local/bin/osrm-routed --max-table-size=1000 $DATA_FILE
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=osrm-routed
TimeoutStopSec=0
Restart=always
User=root
Group=root
ExecStop=/bin/kill -s TERM $MAINPID
[Install]
WantedBy=multi-user.target
EOF
printf "${GREEN}Adding systemd file completed\n${NC}"
systemctl daemon-reload
systemctl start osrm-routed
printf "${GREEN}Service Started\n${NC}"
systemctl enable osrm-routed
printf "${GREEN}Enabled automatic startup.\n${NC}"
printf "${GREEN}Installation successful.\n${NC}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment