Search code examples
pythonflaskgunicornsystemdtensorflow

tensorflow gpu failed init from systemd service


I'm trying to host flask API which is using tensorflow libraries.I installed tensorflow gpu library with CUDA and cudnn libraries.I manually checked with the following command which is working fine.

/captcha/env/bin/gunicorn captcha:app -b 0.0.0.0:5124 -k gevent --worker-connections 1000

But when i add this systemd service im getting a tensorflow gpu error

systemd service

[Unit]
Description=gunicorn daemon
Requires=gunicorn.socket
After=network.target

[Service]
PIDFile=/run/gunicorn/pid
User=root
Group=root
WorkingDirectory=/captcha/env
ExecStart=/captcha/env/bin/gunicorn captcha:app -b 0.0.0.0:5124 -k gevent --worker-connections 1000
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

Error text in Log file:

Failed to load the native TensorFlow runtime.

See https://www.tensorflow.org/install/install_sources#common_installation_problems

for some common reasons and solutions. Include the entire stack trace above this error message when asking for help.

Can anyone point me where I'm doing wrong?


Solution

  • I'm using PM2 to manage tensorflow-flask api process.

    http://pm2.keymetrics.io/

    I Create a shell file with the following command as a content.

    pm2 start run.sh