[Unit]
Description=AutoKanban Thermal Printer Web App
After=network.target
# Wait for system to fully boot before starting
After=multi-user.target

[Service]
Type=simple
User=pi
Group=pi
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="PYENV_ROOT=/home/pi/.pyenv"
ExecStart=/home/pi/.pyenv/versions/autokanban/bin/python /home/pi/autokanban/start_app.py
Restart=on-failure
RestartSec=5
StandardOutput=journal
StandardError=journal

# Graceful shutdown
TimeoutStopSec=10
KillMode=mixed
KillSignal=SIGTERM

[Install]
WantedBy=multi-user.target
