Adding deployment to raspberrypi
This commit is contained in:
41
scripts/setup_service.sh
Normal file
41
scripts/setup_service.sh
Normal file
@@ -0,0 +1,41 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
REPO_DIR="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
SERVICE_NAME="birdcam"
|
||||
USER="$(whoami)"
|
||||
VENV_PYTHON="$(poetry env info --path)/bin/python"
|
||||
GUNICORN="$(poetry env info --path)/bin/gunicorn"
|
||||
|
||||
echo "Installing systemd service..."
|
||||
|
||||
sudo tee /etc/systemd/system/${SERVICE_NAME}.service > /dev/null <<EOF
|
||||
[Unit]
|
||||
Description=Birdcam Flask Application
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
User=${USER}
|
||||
WorkingDirectory=${REPO_DIR}
|
||||
ExecStart=${GUNICORN} \
|
||||
--workers 2 \
|
||||
--worker-class gthread \
|
||||
--threads 4 \
|
||||
--bind 127.0.0.1:8000 \
|
||||
--access-logfile - \
|
||||
--error-logfile - \
|
||||
"src.app:app"
|
||||
Restart=on-failure
|
||||
RestartSec=5
|
||||
Environment=PYTHONPATH=${REPO_DIR}
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF
|
||||
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl enable "$SERVICE_NAME"
|
||||
sudo systemctl start "$SERVICE_NAME"
|
||||
sudo systemctl status "$SERVICE_NAME" --no-pager
|
||||
|
||||
echo "Service installed and started."
|
||||
Reference in New Issue
Block a user