Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kyroskoh/053df18fc21411d789abded1a7466a96 to your computer and use it in GitHub Desktop.
Save kyroskoh/053df18fc21411d789abded1a7466a96 to your computer and use it in GitHub Desktop.
Building OSRM & Setup in Production to Run on Boot (On-Premise)

Public Version

General build instructions from source

OSRM source is available via git or source archives, and is built with CMake.

Git

To download from Git, run the following commands:

git clone https://github.com/Project-OSRM/osrm-backend.git -b 5.5
cd osrm-backend

If you would like to build a specific release (optional), you can list the release tags with git tag -l and then checkout a specific tag using git checkout tags/<tag_name>.

Source Release

OSRM can be built from the source archives available on the releases page. Example:

wget https://github.com/Project-OSRM/osrm-backend/archive/vX.Y.Z.tar.gz
tar -xzf vX.Y.Z.tar.gz
cd osrm-backend-X.Y.Z

Building

mkdir -p build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
cmake --build .
sudo cmake --build . --target install
cp -R ../profiles ./
ln -s profiles/car.lua profile.lua (Create symbolink for car.lua as profile.lua)

SLA's Version

Our Source Release

wget https://s3-ap-southeast-1.amazonaws.com/sla-onemap2/osrm-backend-drive-preinstalled.zip
sudo apt-get install zip unzip
unzip osrm-backend-drive-preinstalled.zip
mv osrm-backend-drive-preinstalled osrm-backend-drive

Building on our version

See below for required dependencies.

mkdir -p build (ignore if existed)
cp -R profiles build/
cd build
nano profile.lua

Edit profile.lua (line 3) to include "profiles" in front of "lib/access".

From: local find_access_tag = require("lib/access").find_access_tag

To: local find_access_tag = require("profiles/lib/access").find_access_tag

Save the file.

cmake .. -DCMAKE_BUILD_TYPE=Release
cmake --build .
sudo cmake --build . --target install

Using OSM Data

Prepare OSM Data & Conversion for OSRM usage

./osrm-extract [filename].osm
./osrm-contract [filename].osrm

Serving up the OSRM Data as Server HTTP API

./osrm-routed [filename].osrm

Create a bash/shell script for OSRM Service

nano run.sh

Copy & Paste (Ensure that you have input the proper filename for your OSRM file:

#!/bin/bash
./osrm-routed [filename].osrm

Save the file.


Run OSRM on Boot

Prerequisite

Using PM2 as Process Manager. We support NodeJS 4.x

Install NodeJS

curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
sudo apt-get install -y nodejs

Checking NodeJS, NPM are installed via checking on their version

node -v
npm -v

Install PM2

sudo npm install -g pm2

Set PM2 as Startup (On Boot)

sudo pm2 startup ubuntu

Set OSRM Service to PM2

Ensure you are in your OSRM directory such as /home/ubuntu/osrm-backend/build with your bash script (run.sh) in it.

sudo pm2 start run.sh --name "OSRM"

Save the Process List

sudo pm2 save

Congrats! Now Your OSRM Service will boot up whenever the machine is booted/reboot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment