Jump to content

Uberspace

From Torben's Wickie
Revision as of 06:16, 27 October 2026 by Torben (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Manuals

https://manual.uberspace.de and https://lab.uberspace.de

PHP

see https://manual.uberspace.de/lang-php/

to restart

uberspace tools restart php

php-fpm

less /opt/uberspace/etc/$USER/php-fpm.conf

Python FastAPI

see https://lab.uberspace.de/guide_fastapi/

# var 1: venv
python3.11 -m venv venv
source venv/bin/activate
pip install fastapi uvicorn
pip install fastapi.responses
pip install gunicorn uvloop httptools
deactivate

# var 2: not use venv
pip3.11 install --user fastapi uvicorn fastapi.responses gunicorn uvloop httptools

# config backend
uberspace web backend set /strava-be --http --port 9001
# --remove-prefix
uberspace web backend list

supervisorctl restart fastapi

~/fastapi/conf.py

#!/usr/bin/env python3.10

# apply changes via
# supervisorctl restart fastapi

import os

app_path = os.environ["HOME"] + "/fastapi"

# Gunicorn configuration
wsgi_app = "main:api"
bind = ":9001"
chdir = app_path
workers = 1
worker_class = "uvicorn.workers.UvicornWorker"

# errorlog = app_path + "/errors.log"
# accesslog = app_path + "/access.log"

~/fastapi/main.py

#!/usr/bin/env python3.10

# apply changes via
# supervisorctl restart fastapi

from fastapi import FastAPI
from fastapi.responses import JSONResponse
from pydantic import BaseModel

import subprocess
 
class StravaSession(BaseModel):
    sessionId: str

api = FastAPI()
 
@api.post("/strava-be/activityStats2/")
async def activityStats2(session: StravaSession):
    # return {session}
    response = {}
    # response = {"session": session.sessionId}
    process = subprocess.run(
        [
            "python3.10",
            "/var/www/virtual/entorb/html/strava/activityStats2.py",
            session.sessionId,
        ],
        capture_output=True,
    )

    if process.returncode == 0:
        response["status"] = "ok"
        response_code = 200
        # response["process_stdout"] = process.stdout.decode()
    else:
        response["status"] = "error"
        response_code = 400
        # response["process_stdout"] = process.stdout.decode()
        response["error_message"] = process.stderr.decode()
    return JSONResponse(content=response, status_code=response_code)

# To test this app locally, uncomment:
# import uvicorn
# uvicorn.run(api, host="localhost", port=8001)

# curl -i -X POST "https://entorb.net/strava-be/activityStats2/" -H "Content-Type: application/json" -d '{"sessionId": "1234"}'

Streamlit

see also strava-streamlit readme

Installation

pip3.11 install --user streamlit

Setup dir and config

mkdir ~/strava-streamlit
cd ~/strava-streamlit
mkdir .streamlit
vim .streamlit/config.toml
[browser]
gatherUsageStats = false

[server]
headless = true
port = 8501
baseUrlPath = "/strava-streamlit"

baseUrlPath is important when not running in web server document root

create minimal Streamlit app

vim src/app.py
import streamlit as st
st.title("Test")

start it manually as testrun (stop by ctrl+c)

streamlit run src/app.py

Add web backend

uberspace web backend set /strava-streamlit --http --port 8501
maybe add --remove-prefix

Access it via browser https://entorb.net/strava-streamlit

Create Service

vim ~/etc/services.d/streamlit-strava.ini
[program:streamlit-strava]
directory=%(ENV_HOME)s/be/strava-streamlit
command=python3.11 -O -m streamlit run src/app.py
# for env var:
environment=MY_VAR="asdf"
loglevel=info


Start Service

supervisorctl reread
supervisorctl update
supervisorctl status
supervisorctl restart strava-streamlit

Check log

supervisorctl tail -f strava-streamlit
# as this is empty:
tail -f ~/logs/supervisord.log