Add systemd service and switch app to port 80

Add c2.service unit to run the FastAPI app as workshop-c2. The unit
invokes uv via /usr/bin/env, sets PATH and PYTHONUNBUFFERED, enables
automatic restarts with a short backoff, and logs to the journal using
SyslogIdentifier. Also update main.py's runtime invocation
This commit is contained in:
Stefan Kempinger 2025-11-05 16:59:37 +01:00
parent 3ea31027f1
commit 38e46a3c50
2 changed files with 29 additions and 1 deletions

28
c2.service Normal file
View file

@ -0,0 +1,28 @@
[Unit]
Description=Workshop C2 FastAPI service
After=network.target
[Service]
Type=simple
WorkingDirectory=/home/kemp/ins/teaching/workshop-c-and-c-server
# Run the requested command. This uses /usr/bin/env to locate `uv` in PATH.
ExecStart=/usr/bin/env uv run main.py
# Ensure common system paths are available when using /usr/bin/env
Environment=PATH=/usr/local/bin:/usr/bin:/bin
Environment=PYTHONUNBUFFERED=1
# Automatically restart the process if it exits/crashes
Restart=always
RestartSec=5
# Log to the journal/syslog with a clear identifier
StandardOutput=journal
StandardError=journal
SyslogIdentifier=workshop-c2
# (Optional) Uncomment and set a non-root user if desired
#User=www-data
#Group=www-data
[Install]
WantedBy=multi-user.target

View file

@ -108,4 +108,4 @@ async def root():
if __name__ == "__main__":
# Run with: python main.py
uvicorn.run("main:app", host="0.0.0.0", port=8000, log_level="info")
uvicorn.run("main:app", host="0.0.0.0", port=80, log_level="info")