1

I have a problem running a Gunicorn Web service using Systemd.

Here are the files I created in order to execute:

The shell script file (/home/ubuntu/mata.sh):

#!/usr/bin/env bash

cd /home/ubuntu/workspace/test-api
/home/ubuntu/workspace/mata_venv/bin/gunicorn --workers=4 app:app --bind 0.0.0.0:xxxx

Here's my .service file (/lib/systemd/system/mata.service):

[Unit]
Description=Test API Service
After=multi-user.target
Conflicts=getty@tty1.service

[Service]
User=ubuntu
Type=simple
ExecStart=/home/ubuntu/mata.sh
StandardInput=tty-force

[Install]
WantedBy=multi-user.target

Running the shell script on its own works well, but when running systemctl status mata.service, I am getting the following message:

Started Test API Service
mata.service: Main process exited, code=exited, status=216/GROUP
mata.service: Unit entered failed state.
mata.service: Failed with result 'exit-code'.

Any idea?

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255

1 Answers1

0

You don't have a "Type=simple" service, you have a forking service, since it's not the "mata.sh" process that you care about, it's the "gunicorn" process.

For a Type=simple service, change the [Service] section to:

[Service]
User=ubuntu
Type=simple
WorkingDirectory=/home/ubuntu/workspace/test-api
ExecStart=/home/ubuntu/workspace/mata_venv/bin/gunicorn --workers=4 app:app --bind 0.0.0.0:xxxx
StandardInput=tty-force

... where I imported the cd command with a WorkingDirectory directive.

Or make it a Forking service with:

[Service]
User=ubuntu
Type=forking
ExecStart=/home/ubuntu/mata.sh
StandardInput=tty-force

You may prefer the Type=forking solution if, as it appears, the gunicorn process starts sub-processes (workers=4).

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255