service change
This commit is contained in:
parent
d6edf761ac
commit
5b0a0292e1
4 changed files with 134 additions and 5 deletions
9
.env.example
Normal file
9
.env.example
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
# AutoKanban Environment Configuration
|
||||||
|
# Copy this file to .env and update with your values
|
||||||
|
|
||||||
|
# Admin password for task approval and management
|
||||||
|
ADMIN_PASSWORD=your_secure_password_here
|
||||||
|
|
||||||
|
# Session secret key for secure cookie signing
|
||||||
|
# Generate a random string for production (e.g., openssl rand -hex 32)
|
||||||
|
SESSION_SECRET=your_random_secret_key_here_at_least_32_characters_long
|
||||||
115
PRODUCTION.md
Normal file
115
PRODUCTION.md
Normal file
|
|
@ -0,0 +1,115 @@
|
||||||
|
# Production Deployment Checklist
|
||||||
|
|
||||||
|
## Before Going Live
|
||||||
|
|
||||||
|
### 1. Environment Configuration
|
||||||
|
|
||||||
|
- [ ] Copy `.env.example` to `.env` on the Pi
|
||||||
|
- [ ] Set a strong `ADMIN_PASSWORD` in `.env`
|
||||||
|
- [ ] Generate and set `SESSION_SECRET` in `.env`:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# On the Pi, generate a secure random key:
|
||||||
|
openssl rand -hex 32
|
||||||
|
# Copy the output and add to .env as SESSION_SECRET
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. Security
|
||||||
|
|
||||||
|
- [ ] Ensure `.env` is in `.gitignore` (already done)
|
||||||
|
- [ ] Never commit `.env` file to git
|
||||||
|
- [ ] Change default admin password from example
|
||||||
|
|
||||||
|
### 3. Hardware Setup
|
||||||
|
|
||||||
|
- [ ] Thermal printer connected via GPIO (Yellow to Pin 8, GND to Pin 6)
|
||||||
|
- [ ] External 9V power supply for printer
|
||||||
|
- [ ] Verify printer works: `echo -e "\x1B\x40Test\n\n\n" > /dev/serial0`
|
||||||
|
- [ ] Serial port enabled: `ls -la /dev/serial0` should point to ttyAMA0
|
||||||
|
|
||||||
|
### 4. Service Configuration
|
||||||
|
|
||||||
|
- [ ] Run `./setup_service.sh` to enable autostart
|
||||||
|
- [ ] Verify service is running: `sudo systemctl status autokanban`
|
||||||
|
- [ ] Test autostart by rebooting: `sudo reboot`
|
||||||
|
|
||||||
|
### 5. Network Access
|
||||||
|
|
||||||
|
- [ ] Set hostname to `autokanban`: `sudo hostnamectl set-hostname autokanban`
|
||||||
|
- [ ] Access app at `http://autokanban.local:8000`
|
||||||
|
- [ ] Verify 124 Hub link in header works
|
||||||
|
|
||||||
|
### 6. Production Settings Verified
|
||||||
|
|
||||||
|
- [ ] `ENABLE_PHYSICAL_PRINTER = True` in `app/main.py`
|
||||||
|
- [ ] Debug print statements removed
|
||||||
|
- [ ] Session secret loaded from environment variable
|
||||||
|
- [ ] Service runs without `--reload` flag
|
||||||
|
|
||||||
|
### 7. Testing
|
||||||
|
|
||||||
|
- [ ] Submit a test task
|
||||||
|
- [ ] Approve task as admin
|
||||||
|
- [ ] Print task and verify:
|
||||||
|
- [ ] Preview image shows on website
|
||||||
|
- [ ] Physical card prints with formatting
|
||||||
|
- [ ] Icon appears correctly
|
||||||
|
- [ ] Text is readable (larger fonts)
|
||||||
|
- [ ] Test "Erneut drucken" (reprint) function
|
||||||
|
- [ ] Test service restart: `sudo systemctl restart autokanban`
|
||||||
|
|
||||||
|
### 8. Monitoring
|
||||||
|
|
||||||
|
- [ ] Check logs: `sudo journalctl -u autokanban -f`
|
||||||
|
- [ ] Verify no errors in startup
|
||||||
|
- [ ] Test graceful shutdown: `sudo systemctl stop autokanban`
|
||||||
|
|
||||||
|
## Post-Deployment
|
||||||
|
|
||||||
|
### Regular Maintenance
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Update code
|
||||||
|
cd ~/autokanban
|
||||||
|
git pull
|
||||||
|
sudo systemctl restart autokanban
|
||||||
|
|
||||||
|
# View logs
|
||||||
|
sudo journalctl -u autokanban -n 100
|
||||||
|
|
||||||
|
# Check service status
|
||||||
|
sudo systemctl status autokanban
|
||||||
|
|
||||||
|
# Backup tasks
|
||||||
|
cp data/tasks.json data/tasks.json.backup
|
||||||
|
```
|
||||||
|
|
||||||
|
### Troubleshooting
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Service won't start
|
||||||
|
sudo journalctl -u autokanban -n 50
|
||||||
|
|
||||||
|
# Printer not working
|
||||||
|
ls -la /dev/serial0
|
||||||
|
stty -F /dev/serial0
|
||||||
|
|
||||||
|
# Check if port is accessible
|
||||||
|
curl http://localhost:8000
|
||||||
|
|
||||||
|
# Restart service
|
||||||
|
sudo systemctl restart autokanban
|
||||||
|
```
|
||||||
|
|
||||||
|
## Current Configuration
|
||||||
|
|
||||||
|
- **Port**: 8000
|
||||||
|
- **Hostname**: autokanban.local
|
||||||
|
- **Access URL**: <http://autokanban.local:8000>
|
||||||
|
- **Printer**: GPIO serial (/dev/serial0, 19200 baud)
|
||||||
|
- **Service**: Systemd with autostart enabled
|
||||||
|
- **Data**: JSON file at `data/tasks.json`
|
||||||
|
- **Previews**: PNG files in `out/`
|
||||||
|
|
||||||
|
---
|
||||||
|
Last updated: 2025-11-20
|
||||||
11
app/main.py
11
app/main.py
|
|
@ -14,8 +14,13 @@ from app.models import Task
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
from PIL import Image, ImageDraw, ImageFont
|
from PIL import Image, ImageDraw, ImageFont
|
||||||
|
|
||||||
|
# Load environment variables
|
||||||
|
load_dotenv()
|
||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
app.add_middleware(SessionMiddleware, secret_key="CHANGE_THIS_SECRET")
|
# Use environment variable for session secret, fallback to random for dev
|
||||||
|
SESSION_SECRET = os.getenv("SESSION_SECRET", "CHANGE_THIS_SECRET")
|
||||||
|
app.add_middleware(SessionMiddleware, secret_key=SESSION_SECRET)
|
||||||
templates = Jinja2Templates(directory="app/templates")
|
templates = Jinja2Templates(directory="app/templates")
|
||||||
app.mount("/static", StaticFiles(directory="app/static"), name="static")
|
app.mount("/static", StaticFiles(directory="app/static"), name="static")
|
||||||
app.mount("/out", StaticFiles(directory="out"), name="out")
|
app.mount("/out", StaticFiles(directory="out"), name="out")
|
||||||
|
|
@ -240,7 +245,6 @@ def print_task(request: Request, task_id: str):
|
||||||
|
|
||||||
# Print to physical printer if enabled
|
# Print to physical printer if enabled
|
||||||
if ENABLE_PHYSICAL_PRINTER:
|
if ENABLE_PHYSICAL_PRINTER:
|
||||||
print(f"[DEBUG] Attempting to print to {PRINTER_DEVICE} at {PRINTER_BAUDRATE} baud...")
|
|
||||||
try:
|
try:
|
||||||
printer = escpos.printer.Serial(devfile=PRINTER_DEVICE, baudrate=PRINTER_BAUDRATE, timeout=1)
|
printer = escpos.printer.Serial(devfile=PRINTER_DEVICE, baudrate=PRINTER_BAUDRATE, timeout=1)
|
||||||
|
|
||||||
|
|
@ -249,13 +253,10 @@ def print_task(request: Request, task_id: str):
|
||||||
printer.text("\n\n") # Add some spacing after image
|
printer.text("\n\n") # Add some spacing after image
|
||||||
printer.cut()
|
printer.cut()
|
||||||
|
|
||||||
print(f"[DEBUG] Print command sent successfully")
|
|
||||||
except Exception as print_err:
|
except Exception as print_err:
|
||||||
print(f"[ERROR] Printer failed: {print_err}")
|
print(f"[ERROR] Printer failed: {print_err}")
|
||||||
import traceback
|
import traceback
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
else:
|
|
||||||
print(f"[DEBUG] Physical printer disabled, skipping print")
|
|
||||||
|
|
||||||
task.status = "printed"
|
task.status = "printed"
|
||||||
msg = "success"
|
msg = "success"
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,16 @@
|
||||||
[Unit]
|
[Unit]
|
||||||
Description=AutoKanban Thermal Printer Web App
|
Description=AutoKanban Thermal Printer Web App
|
||||||
After=network.target
|
After=network.target
|
||||||
|
# Wait for system to fully boot before starting
|
||||||
|
After=multi-user.target
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Type=simple
|
Type=simple
|
||||||
User=pi
|
User=pi
|
||||||
Group=pi
|
Group=pi
|
||||||
WorkingDirectory=/home/pi/autokanban
|
WorkingDirectory=/home/pi/autokanban
|
||||||
|
# Add delay to avoid boot messages on serial port
|
||||||
|
ExecStartPre=/bin/sleep 10
|
||||||
Environment="PATH=/home/pi/.pyenv/versions/autokanban/bin:/usr/local/bin:/usr/bin:/bin"
|
Environment="PATH=/home/pi/.pyenv/versions/autokanban/bin:/usr/local/bin:/usr/bin:/bin"
|
||||||
Environment="PYENV_ROOT=/home/pi/.pyenv"
|
Environment="PYENV_ROOT=/home/pi/.pyenv"
|
||||||
ExecStart=/home/pi/.pyenv/versions/autokanban/bin/python /home/pi/autokanban/start_app.py
|
ExecStart=/home/pi/.pyenv/versions/autokanban/bin/python /home/pi/autokanban/start_app.py
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue