0

I am new to web services especially when it comes to deployment options. I made a Flask application webserver, and now I would like to deploy it on production mode. I went for Gunicorn + Nginx options and followed this tutorial on Medium.

I installed nginx with:

~ >>> sudo pacman -S nginx
~ >>> sudo systemctl start nginx 
~ >>> sudo systemctl enable nginx 

Everything worked well, but when I created my systemd service webserver.service, the Group=www-data made the service exited, with status=216/GROUP.

Here is the webserver.service file:

[Unit]

Description=Gunicorn instance to serve the test server webserver
After=network.target


[Service]

User=user
Group=www-data

WorkingDirectory=/home/user/webserver/
Environment="PATH=/home/user/webserver/.env/bin"
ExecStart=/home/user/webserver/.env/bin/gunicorn --workers 3 --bind unix:app.sock -m 007 wsgi:app

[Install]

WantedBy=multi-user.target

Here is the full log:

~ >>> sudo systemctl start webserver 
~ >>> sudo systemctl enable webserver 
~ >>> sudo systemctl status webserver 

● webserver.service - Gunicorn instance to serve the test server webserver
     Loaded: loaded (/etc/systemd/system/webserver.service; enabled; vendor preset: disabled)
     Active: failed (Result: exit-code) since Sun 2020-07-05 14:50:02 CEST; 20min ago
   Main PID: 5464 (code=exited, status=216/GROUP)

juil. 05 14:50:02 user systemd[1]: Started Gunicorn instance to serve the test server webserver.
juil. 05 14:50:02 user systemd[5464]: webserver.service: Failed to determine group credentials: No such process
juil. 05 14:50:02 user systemd[5464]: webserver.service: Failed at step GROUP spawning /home/user/webserver/.env/bin/gunicorn: No such process
juil. 05 14:50:02 user systemd[1]: webserver.service: Main process exited, code=exited, status=216/GROUP
juil. 05 14:50:02 user systemd[1]: webserver.service: Failed with result 'exit-code'.

In fact, when I list all the groups, the www-data required by Nginx is missing:

~ >>> groups
sys network power docker lp wheel user

So obviously the above code won't work with www-data group.

What I tried

1. A different group

I tried to change the group option to Group=root, and it worked. I then finished the tutorial without any errors. I thought it fixed my issue, but I couldn't access my server on my browser at http://www.my_domain_webserver.com, so I guess the www-data is mandatory to work with Nginx and GUnicorn.

My nginx location block:

server {
    listen 80;
    server_name my_domain_webserver.com www.my_domain_webserver.com;

    location / {
        include proxy_params;
        proxy_pass http://unix:/home/user/webserver/app.sock;
    }
}
2. Reloading Daemon

I also tried to re-execute daemon with systemctl daemon-reexec, but it didn't solved my issue.

My project tree is:

webserver
├── app.py
├── app.sock
└── wsgi.py

Why is the group www-data missing ?
Do I need to add special nginx.conf files ? I didn't modify any of them.

Thanks for your help !

jegertor
  • 73
  • 2
  • 8
  • 1
    The `www-data` user/group is the default for using with web servers on **some** linux distros, but not all of them and is definitely not mandatory to work with nginx and could be changed to any other group (which would have the permissions to access your web data files/folders/control socket). Your problem is somewhere else. – Ivan Shatsky Jul 05 '20 at 23:16
  • Thanks, I will keep testing. If I find a solution, I will edit my post ! Have a good day. – jegertor Jul 06 '20 at 09:06

1 Answers1

0

You could try to add the folder to the "www-data" group:

sudo chown www-data /home/user/webserver

That helped for me...

levi.hrb
  • 51
  • 6