Skip to content

Instantly share code, notes, and snippets.

@maybemkl
Last active February 16, 2025 23:25
Show Gist options
  • Save maybemkl/e735703d7a724db797c0a972d918d398 to your computer and use it in GitHub Desktop.
Save maybemkl/e735703d7a724db797c0a972d918d398 to your computer and use it in GitHub Desktop.

Installing Martin Tileserver and Setting Up Persistent Tile Serving on GC

This guide covers how to:

  1. Install Martin Tileserver.
  2. Download a Maptiler tileset for North America.
  3. Set up Martin to run as a persistent service using systemd.

1. Install Martin Tileserver

Per instructions in the documentation:

mkdir martin
cd martin
# Download some sample data
curl -L -O https://github.com/maplibre/martin/raw/main/tests/fixtures/mbtiles/world_cities.mbtiles
# Download the latest version of Martin binary, extract it, and make it executable
curl -L -O https://github.com/maplibre/martin/releases/latest/download/martin-x86_64-unknown-linux-gnu.tar.gz 
tar -xzf martin-x86_64-unknown-linux-gnu.tar.gz
chmod +x ./martin
# Run Martin with the sample data as the only tile source
./martin world_cities.mbtiles

2. Download the Maptiler Tileset

Let's create a directory for all of our tilesets (just one in this example):

mkdir tilesets
cd tilesets

You can get your download URL directly from Maptiler. Next, you can download the Maptiler North America tileset with wget using the following command:

wget -c URL-FROM-MAPTILER

This will download the tileset as a .mbtiles file. Once downloaded, you can start serving these tiles using the Martin server.

3. Setup Martin as a Persistent Process Using systemd

To ensure Martin keeps running even after you log out, we will set it up with systemd.

sudo nano /etc/systemd/system/martin-tileserver.service

Paste the following into the file, chaning [ROOT] and [MAPTILER-FILE] to whatever those paths are.

[Unit]
Description=Martin Tileserver
After=network.target

[Service]
ExecStart=[ROOT]/martin/martin [ROOT]/tilesets/[MAPTILER-FILE]
WorkingDirectory=[ROOT]
User=mikaelbrunila
Restart=always

[Install]
WantedBy=multi-user.target

Do NOT use relative paths.

Reload systemd and start the service: Run the following commands to reload systemd and start Martin:

sudo systemctl daemon-reload
sudo systemctl start martin-tileserver

Enable Martin to start on boot: To make sure Martin starts on system boot, use:

sudo systemctl enable martin-tileserver

Verify the status of the service: To check that Martin is running correctly, use:

sudo systemctl status martin-tileserver

Now, Martin should be running as a persistent service. If you need to stop or restart Martin, use:

sudo systemctl stop martin-tileserver
sudo systemctl restart martin-tileserver

You can view logs for troubleshooting with:

sudo journalctl -u martin-tileserver

This guide should help you get Martin running as a persistent service on your server. You can now serve tiles and access them using the appropriate URL. When using GC, also remember to do the following:

  1. Go to the Google Cloud Console.
  2. In the left sidebar, go to VPC network > Firewall rules.
  3. Click Create firewall rule.
  4. Name the rule (e.g., martin).
  5. In the Targets section, select All instances in the network or Specified target tags.
  6. Under Source filter, select IP ranges and specify 0.0.0.0/0 to allow all external IP addresses (or specify a more restricted range if necessary).
  7. Set Allowed protocols and ports to tcp:3000.
  8. Click Create.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment