I have application FastAPI which I run directly through below command
gunicorn app.main:app --workers 4 --worker-class uvicorn.workers.UvicornWorker --bind 0.0.0.0
It works fine. Now I serve this app through systemd service
[Unit]
Description=To run FX FastAPI backend through gunicorn
After=network.target
[Service]
User=root
Group=root
WorkingDirectory=/home/fx/fx_demo_all_modules/fastapi/
Environment="PATH=/home/fx/fx_demo_all_modules/fastapi/venv/bin"
ExecStart=/home/fx/fx_demo_all_modules/fastapi/venv/bin/gunicorn app.main:app --workers 4 --worker-class uvicorn.workers.UvicornWorker --bind 0.0.0.0
[Install]
WantedBy=multi-user.target
Location of service file is /etc/systemd/system
and also I change the owner from root to fx
The service is also worked fine.
Problem comes when I run bash script from python
manufacturer = subprocess.check_output(['/var/www/get-manufacturer.sh'])
The Script is below
#! /bin/bash
var=$(sudo dmidecode -s system-manufacturer)
echo $var
If I run the application direct then it works fine if I run from service it didn't work. Below is journalctl log
/var/www/get-manufacturer.sh: line 2: sudo: command not found
Advance thanks for the solution.