GHCND Big Data API Server

Running the API

This document explains how to run the FastAPI + Spark service, both manually and as a systemd service.

Manual Run (Development)

From the project root, with the Python environment activated:

uvicorn app.main:app --host 0.0.0.0 --port 8000

The API will be available at:

Production Run via systemd

You can manage the API as a long-running service using systemd.

Unit File

Create /etc/systemd/system/ghcnd-api.service:

[Unit]
Description=GHCND FastAPI + Spark API
After=network.target

[Service]
Type=simple
User=root
WorkingDirectory=/root/UNI-BIG-DATA-COURSE-PROJECT-SERVER

# Load pyenv environment and start Uvicorn
ExecStart=/bin/bash -c 'source /opt/pyenv/bin/activate && uvicorn app.main:app --host 0.0.0.0 --port 8000'

Restart=always
RestartSec=5s

[Install]
WantedBy=multi-user.target

Adjust:

Enable and Start

sudo systemctl daemon-reload
sudo systemctl enable ghcnd-api
sudo systemctl start ghcnd-api
sudo systemctl status ghcnd-api

Tail logs:

journalctl -u ghcnd-api -f

Deployment Helper Scripts

Two shell scripts are provided to streamline deployment:

Both scripts assume: