-1

I have following systemctl service

[Unit]
Description=Ml api

[Service]
#user=root

ExecStart=/usr/local/bin/python3.9 -u /home/a.nikitin@corp.bsv.legal/bsv_ml_api/app.py

ExecStop=/bin/kill -15 $MAINPID
Type=forking

#KillMode=process

#SyslogIdentifier=ml-api
#SyslogFacility=daemon

Restart=on-failure

[Install]
WantedBy=multiuser.target

When i run it i got an error. The sudo journalctl -u ml.service -e shows

    ml.service - Ml api
   Loaded: loaded (/usr/lib/systemd/system/ml.service; disabled; vendor preset: disabled)
   Active: failed (Result: start-limit) since Fri 2022-06-10 11:38:38 MSK; 1 day 23h ago
 Main PID: 77614 (code=exited, status=203/EXEC)

Jun 10 11:38:38 srv-ml-api.corp.bsv.legal systemd[1]: Unit ml.service entered failed state.
Jun 10 11:38:38 srv-ml-api.corp.bsv.legal systemd[1]: ml.service failed.
Jun 10 11:38:38 srv-ml-api.corp.bsv.legal systemd[1]: ml.service holdoff time over, scheduling restart.
Jun 10 11:38:38 srv-ml-api.corp.bsv.legal systemd[1]: Stopped Ml api.
Jun 10 11:38:38 srv-ml-api.corp.bsv.legal systemd[1]: start request repeated too quickly for ml.service
Jun 10 11:38:38 srv-ml-api.corp.bsv.legal systemd[1]: Failed to start Ml api.
Jun 10 11:38:38 srv-ml-api.corp.bsv.legal systemd[1]: Unit ml.service entered failed state.
Jun 10 11:38:38 srv-ml-api.corp.bsv.legal systemd[1]: ml.service failed.

However, if i run directly

 /usr/local/bin/python3.9 -u /home/a.nikitin@corp.bsv.legal/bsv_ml_api/app.py

Everything is ok and the script started

INFO:     Started server process [4401]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     Uvicorn running on http://127.0.0.1:1111 (Press CTRL+C to quit)

I don't know where the problem is. It's FastAPI + uvicorn app.

Alex Nikitin
  • 841
  • 1
  • 10
  • 29
  • Does `journalctl` show any output from your script? That might help locate the source of the problem. – larsks Jun 12 '22 at 11:38

1 Answers1

0

Turns out i need to specify python env

Environment="PYTHONPATH=$PYTHONPATH:/home/a.nikitin@corp.bsv.legal/.local/lib/python3.9/site-packages"
Alex Nikitin
  • 841
  • 1
  • 10
  • 29