RHEL 9 Gunicorn in python virtual environment system service issues

158 Views Asked by At

I am trying to configure gunicorn to serve my flask application, and use NGINX for the proxy config. This application is being hosted on a RHEL 9 server. Python 3.9 and gunicorn 20.1.0 are installed.

Currently stuck on trying to get gunicorn to start as a service.

The location of the service is /etc/systemd/system/gunicorn.service and the configuration is as follows:

[Unit]
Description=Gunicorn instance to serve Flask app
After=network.target

[Service]
User=testuser
Group=testuser
WorkingDirectory=/home/testuser/webapp
Environment="PATH=/home/testuser/env/vwebapp/bin"
ExecStart=/home/testuser/env/vwebapp/bin/gunicorn --chdir /home/testuser/webapp --config /home/testuser/webapp/gunicorn.py  app:app

[Install]
WantedBy=multi-user.target

This is the error I am receiving:

Apr 08 01:09:50 TEST gunicorn[265951]: All git commands will error until this is rectified.
Apr 08 01:09:50 TEST gunicorn[265951]: This initial warning can be silenced or aggravated in the future by setting the
Apr 08 01:09:50 TEST gunicorn[265951]: $GIT_PYTHON_REFRESH environment variable. Use one of the following values:
Apr 08 01:09:50 TEST gunicorn[265951]:     - quiet|q|silence|s|none|n|0: for no warning or exception
Apr 08 01:09:50 TEST gunicorn[265951]:     - warn|w|warning|1: for a printed warning
Apr 08 01:09:50 TEST gunicorn[265951]:     - error|e|raise|r|2: for a raised exception
Apr 08 01:09:50 TEST gunicorn[265951]: Example:
Apr 08 01:09:50 TEST gunicorn[265951]:     export GIT_PYTHON_REFRESH=quiet
Apr 08 01:09:50 TEST systemd[1]: gunicorn.service: Main process exited, code=exited, status=1/FAILURE
Apr 08 01:09:50 TEST systemd[1]: gunicorn.service: Failed with result 'exit-code'.

For reference, this is the gunicorn config file I am using for testing:

bind = "0.0.0.0:8080"
graceful_timeout = 3000
limit_request_line = 0
loglevel = "debug"
preload_app = True
raw_env = ["TERM=screen"]
timeout = 3000
workers = 5

Getting the gunicorn system service to work has been my primary issue throughout this process. For whatever reason I am able to run the same arguments "--chdir /home/testuser/webapp --config /home/testuser/webapp/gunicorn.py app:app" in the ExecStart manually and gunicorn starts up with no issues. Any assistance would be greatly appreciated.

I have tried several variations of examples for the gunicorn.service config (including leaving off the --chdir and --config arguments) and still have had no luck with getting this service to work.

I ultimately would like to be able to pass my gunicorn python config file as an argument in the ExecStart section of the custom gunicorn service.

0

There are 0 best solutions below