-
Notifications
You must be signed in to change notification settings - Fork 2
Deploy with systemd
Berg Paulo edited this page Apr 9, 2021
·
3 revisions
Obs: Assuming it was installed Raspberry Pi OS (32-bit) with Desktop
version:
Maybe with other version, be necessary install another dependencies.
sudo apt install python3-venv
- Clone project,
- Enter in project folder,
- Create a virtualenv:
python3 -m venv .venv
, - Activate virtualenv:
source .venv/bin/activate
, - Install python dependencies:
pip install -r requirements_prod.txt
, - Create a .env file in root of project and add FLASK_ENV and SECRET_KEY variables with your values.
- FLASK_ENV - Flask environment, development or production. Ex: FLASK_ENV=development
- SECRET_KEY - Your secret key into app. Ex: SECRET_KEY=your_secret_key
- Run
flask db init && flask db migrate && flask db upgrade && flask seed
to run migrations and create admin user, - Run server:
gunicorn wsgi:app --worker-class eventlet -w 1 --timeout 120 --no-sendfile -b 0.0.0.0:8000
, - Access http://your_ip:8000,
- Lisa is up.
- Running with systemd you have many options to control application execution.
This configuration starts application with O.S. start, and restarts automatically if something going wrong.
Change
pi
with your system user.
sudo nano /etc/systemd/system/lisapi.service
[Unit]
Description=LisaPi Application
After=network.target
[Service]
User=pi
WorkingDirectory=/home/pi/lisapi
ExecStart=/home/pi/lisapi/.venv/bin/gunicorn --worker-class eventlet -w 1 --timeout 120 --no-sendfile -b 0.0.0.0:8000 wsgi:app
Restart=always
[Install]
WantedBy=multi-user.target
-
Save file.
-
Restart
systemd
configurations:
sudo systemctl daemon-reload
sudo systemctl start lisapi
- Access http://your_ip:8000 to open application.