title: Unable to run flask application as a service with systemd on Centos 7 server
body: <p>I'm able to run flask app within virtualenv <code>/web_services/flask_api/flask_api</code> like this:</p>
  
  <p><code>gunicorn --workers=4 --bind=localhost:8000 --log-level=error app:app</code></p>
  
  <p>But, when I try to run it as a service it's not working. Here's a post that I followed to create a <code>.service</code> config file:</p>
  
  <p><a href="https://blog.miguelgrinberg.com/post/running-a-flask-application-as-a-service-with-systemd" rel="nofollow noreferrer">https://blog.miguelgrinberg.com/post/running-a-flask-application-as-a-service-with-systemd</a></p>
  
  <p>Here's how my <code>web_service.service</code> file looks like:</p>
  
  <pre><code>[Unit]
  Description=Sample web service
  After=network.target 
  
  [Service]
  User=aaa.bbb
  WorkingDirectory=/web_services/flask_api/flask_api
  ExecStart=/web_services/flask_api/flask_api/bin/gunicorn --workers=4 --bind=localhost:8000 --log-level=error web_service:app
  Restart=always 
  
  [Install]
  WantedBy=multi-user.target
  </code></pre>
  
  <p>After saving this file I did:</p>
  
  <pre><code>$ sudo systemctl daemon-reload
  $ sudo systemctl start web_service
  $ sudo systemctl enable web_service
  </code></pre>
  
  <p><code>systemctl | grep running</code> is not displaying this api.</p>
  
  <p>While checking status of this service, I'm getting this:</p>
  
  <pre><code>sudo systemctl status web_service
  ● web_service.service - Sample web service  
   Loaded: loaded (/etc/systemd/system/web_service.service; enabled; vendor preset: disabled)   
   Active: failed (Result: start-limit) since Mon 2020-06-01 16:15:15 EDT; 13s ago 
   Process: 1016 ExecStart=/web_services/flask_api/flask_api/bin/gunicorn --workers=4 --bind=localhost:8000 --log-level=error web_service:app (code=exited, status=1/FAILURE)
   Main PID: 1016 (code=exited, status=1/FAILURE)
  </code></pre>
  
  <p>Don't know what I'm missing here or doing wrong. Any help would be appreciated..</p>