Problem starting Gunicorn Web Service using Systemd

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












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?










share|improve this question
























  • The sequencing here is throwing me off a little bit; are you starting it manually and then running systemctl status...? You are starting it with systemctl, right?

    – Jeff Schaller
    Feb 19 at 14:38






  • 1





    Possible duplicate of systemd - My custom service exits with status code 216/GROUP

    – JdeBP
    Feb 19 at 14:43











  • @JdeBP, I don't see that the user set a Group= definition here; is the implication that User=ubuntu is failing because of that user's groups? (The other aspect of the duplicate answer relates to using nobody, and seems unrelated to me)

    – Jeff Schaller
    Feb 19 at 15:03












  • systemd exit code 216 indicates "Failed to determine or change group credentials."

    – Jeff Schaller
    Feb 19 at 15:07











  • @JeffSchaller Yep, I am trying to start it with systemctl start mata.service

    – Pavel Zagalsky
    Feb 19 at 15:33















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?










share|improve this question
























  • The sequencing here is throwing me off a little bit; are you starting it manually and then running systemctl status...? You are starting it with systemctl, right?

    – Jeff Schaller
    Feb 19 at 14:38






  • 1





    Possible duplicate of systemd - My custom service exits with status code 216/GROUP

    – JdeBP
    Feb 19 at 14:43











  • @JdeBP, I don't see that the user set a Group= definition here; is the implication that User=ubuntu is failing because of that user's groups? (The other aspect of the duplicate answer relates to using nobody, and seems unrelated to me)

    – Jeff Schaller
    Feb 19 at 15:03












  • systemd exit code 216 indicates "Failed to determine or change group credentials."

    – Jeff Schaller
    Feb 19 at 15:07











  • @JeffSchaller Yep, I am trying to start it with systemctl start mata.service

    – Pavel Zagalsky
    Feb 19 at 15:33













1












1








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?










share|improve this question
















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?







systemd






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 19 at 15:05









Jeff Schaller

43.4k1160140




43.4k1160140










asked Feb 19 at 13:36









Pavel ZagalskyPavel Zagalsky

1165




1165












  • The sequencing here is throwing me off a little bit; are you starting it manually and then running systemctl status...? You are starting it with systemctl, right?

    – Jeff Schaller
    Feb 19 at 14:38






  • 1





    Possible duplicate of systemd - My custom service exits with status code 216/GROUP

    – JdeBP
    Feb 19 at 14:43











  • @JdeBP, I don't see that the user set a Group= definition here; is the implication that User=ubuntu is failing because of that user's groups? (The other aspect of the duplicate answer relates to using nobody, and seems unrelated to me)

    – Jeff Schaller
    Feb 19 at 15:03












  • systemd exit code 216 indicates "Failed to determine or change group credentials."

    – Jeff Schaller
    Feb 19 at 15:07











  • @JeffSchaller Yep, I am trying to start it with systemctl start mata.service

    – Pavel Zagalsky
    Feb 19 at 15:33

















  • The sequencing here is throwing me off a little bit; are you starting it manually and then running systemctl status...? You are starting it with systemctl, right?

    – Jeff Schaller
    Feb 19 at 14:38






  • 1





    Possible duplicate of systemd - My custom service exits with status code 216/GROUP

    – JdeBP
    Feb 19 at 14:43











  • @JdeBP, I don't see that the user set a Group= definition here; is the implication that User=ubuntu is failing because of that user's groups? (The other aspect of the duplicate answer relates to using nobody, and seems unrelated to me)

    – Jeff Schaller
    Feb 19 at 15:03












  • systemd exit code 216 indicates "Failed to determine or change group credentials."

    – Jeff Schaller
    Feb 19 at 15:07











  • @JeffSchaller Yep, I am trying to start it with systemctl start mata.service

    – Pavel Zagalsky
    Feb 19 at 15:33
















The sequencing here is throwing me off a little bit; are you starting it manually and then running systemctl status...? You are starting it with systemctl, right?

– Jeff Schaller
Feb 19 at 14:38





The sequencing here is throwing me off a little bit; are you starting it manually and then running systemctl status...? You are starting it with systemctl, right?

– Jeff Schaller
Feb 19 at 14:38




1




1





Possible duplicate of systemd - My custom service exits with status code 216/GROUP

– JdeBP
Feb 19 at 14:43





Possible duplicate of systemd - My custom service exits with status code 216/GROUP

– JdeBP
Feb 19 at 14:43













@JdeBP, I don't see that the user set a Group= definition here; is the implication that User=ubuntu is failing because of that user's groups? (The other aspect of the duplicate answer relates to using nobody, and seems unrelated to me)

– Jeff Schaller
Feb 19 at 15:03






@JdeBP, I don't see that the user set a Group= definition here; is the implication that User=ubuntu is failing because of that user's groups? (The other aspect of the duplicate answer relates to using nobody, and seems unrelated to me)

– Jeff Schaller
Feb 19 at 15:03














systemd exit code 216 indicates "Failed to determine or change group credentials."

– Jeff Schaller
Feb 19 at 15:07





systemd exit code 216 indicates "Failed to determine or change group credentials."

– Jeff Schaller
Feb 19 at 15:07













@JeffSchaller Yep, I am trying to start it with systemctl start mata.service

– Pavel Zagalsky
Feb 19 at 15:33





@JeffSchaller Yep, I am trying to start it with systemctl start mata.service

– Pavel Zagalsky
Feb 19 at 15:33










1 Answer
1






active

oldest

votes


















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).






share|improve this answer























  • See also docs.gunicorn.org/en/stable/deploy.html which has a sample systemd service file.

    – Jeff Schaller
    Feb 19 at 13:48











  • Hmmmm, getting the same error.. Any other suggestions?

    – Pavel Zagalsky
    Feb 19 at 14:32










Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f501590%2fproblem-starting-gunicorn-web-service-using-systemd%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









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).






share|improve this answer























  • See also docs.gunicorn.org/en/stable/deploy.html which has a sample systemd service file.

    – Jeff Schaller
    Feb 19 at 13:48











  • Hmmmm, getting the same error.. Any other suggestions?

    – Pavel Zagalsky
    Feb 19 at 14:32















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).






share|improve this answer























  • See also docs.gunicorn.org/en/stable/deploy.html which has a sample systemd service file.

    – Jeff Schaller
    Feb 19 at 13:48











  • Hmmmm, getting the same error.. Any other suggestions?

    – Pavel Zagalsky
    Feb 19 at 14:32













0












0








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).






share|improve this answer













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).







share|improve this answer












share|improve this answer



share|improve this answer










answered Feb 19 at 13:48









Jeff SchallerJeff Schaller

43.4k1160140




43.4k1160140












  • See also docs.gunicorn.org/en/stable/deploy.html which has a sample systemd service file.

    – Jeff Schaller
    Feb 19 at 13:48











  • Hmmmm, getting the same error.. Any other suggestions?

    – Pavel Zagalsky
    Feb 19 at 14:32

















  • See also docs.gunicorn.org/en/stable/deploy.html which has a sample systemd service file.

    – Jeff Schaller
    Feb 19 at 13:48











  • Hmmmm, getting the same error.. Any other suggestions?

    – Pavel Zagalsky
    Feb 19 at 14:32
















See also docs.gunicorn.org/en/stable/deploy.html which has a sample systemd service file.

– Jeff Schaller
Feb 19 at 13:48





See also docs.gunicorn.org/en/stable/deploy.html which has a sample systemd service file.

– Jeff Schaller
Feb 19 at 13:48













Hmmmm, getting the same error.. Any other suggestions?

– Pavel Zagalsky
Feb 19 at 14:32





Hmmmm, getting the same error.. Any other suggestions?

– Pavel Zagalsky
Feb 19 at 14:32

















draft saved

draft discarded
















































Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f501590%2fproblem-starting-gunicorn-web-service-using-systemd%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown






Popular posts from this blog

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay