41 lines
920 B
Bash
Executable File
41 lines
920 B
Bash
Executable File
#!/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." |