Django deployment with digital ocean

I’m following the guide to deploy my first django app on digitalocean.

It gives me the error:

Jul 30 16:33:41 ubuntu-s-1vcpu-1gb-nyc1-01 systemd[1]: Listening on gunicorn socket.
Jul 30 17:05:04 ubuntu-s-1vcpu-1gb-nyc1-01 systemd[1]: gunicorn.socket: Failed with result 'service-star>
Jul 30 17:06:47 ubuntu-s-1vcpu-1gb-nyc1-01 systemd[1]: Listening on gunicorn socket.
Jul 30 17:34:53 ubuntu-s-1vcpu-1gb-nyc1-01 systemd[1]: gunicorn.socket: Failed with result 'service-star>
– Reboot –
Jul 30 18:12:15 ubuntu-s-1vcpu-1gb-nyc1-01 systemd[1]: Listening on gunicorn socket.
Jul 30 18:13:30 ubuntu-s-1vcpu-1gb-nyc1-01 systemd[1]: gunicorn.socket: Failed with result 'service-star>
Jul 30 18:19:20 ubuntu-s-1vcpu-1gb-nyc1-01 systemd[1]: Listening on gunicorn socket.

I think it has to do with my gunicorn.service file.

.[Unit]
Description=gunicorn daemon
Requires=gunicorn.socket
After=network.target

[Service]
User=stelity
Group=www-data
WorkingDirectory=/home/stelity/myonlinefoodpantry
ExecStart=/home/stelity/myonlinefoodpantry/bin/gunicorn
–access-logfile -
–workers 3
–bind unix:/run/gunicorn.sock
myonlinefoodpantry.wsgi:application

[Install]
WantedBy=multi-user.target

Does anyone know what I shoudl put for: User, WorkingDirectory, and ExecStart? I followed the guide brainlessly and it doesn’t seem to work. Does my project need to be in the env folder?

Currently my app is in: /root/myonlinefp/myonlinefp
My env folder is in: /root/myonlinefp/env

What does your gunicorn.socket file look like? (As referenced by the Requires directive.)

[Unit]
Description=gunicorn socket

[Socket]
ListenStream=/run/gunicorn.sock

[Install]
WantedBy=sockets.target

after trying to start gunicorn with this command:

sudo systemctl status gunicorn

I got this:

Jul 31 08:00:35 ubuntu-s-1vcpu-1gb-nyc1-01 systemd[1]: Started gunicorn.service.
Jul 31 08:00:35 ubuntu-s-1vcpu-1gb-nyc1-01 systemd[17341]: gunicorn.service: Failed to determine user credentials: No such process
Jul 31 08:00:35 ubuntu-s-1vcpu-1gb-nyc1-01 systemd[17341]: gunicorn.service: Failed at step USER spawning /usr/bin/gunicorn: No such process
Jul 31 08:00:35 ubuntu-s-1vcpu-1gb-nyc1-01 systemd[1]: gunicorn.service: Main process exited, code=exited, status=217/USER
Jul 31 08:00:35 ubuntu-s-1vcpu-1gb-nyc1-01 systemd[1]: gunicorn.service: Failed with result ‘exit-code’.
Jul 31 08:00:35 ubuntu-s-1vcpu-1gb-nyc1-01 systemd[1]: gunicorn.service: Start request repeated too quickly.
Jul 31 08:00:35 ubuntu-s-1vcpu-1gb-nyc1-01 systemd[1]: gunicorn.service: Failed with result ‘exit-code’.
Jul 31 08:00:35 ubuntu-s-1vcpu-1gb-nyc1-01 systemd[1]: Failed to start gunicorn.service.
Aug 02 05:04:13 ubuntu-s-1vcpu-1gb-nyc1-01 systemd[1]: /etc/systemd/system/gunicorn.service:14: Missing ‘=’, ignoring line.
~

Ok, I don’t use gunicorn, so I’m far from being an expert here - but from what I’m reading, it appears you’re conflating two different methodologies here.

It appears to me that the socket listener entry is designed to start a new instance of a process any time a message is sent through the socket, but your gunicorn definition is designed to run persistently.

The example I see in those docs where it shows the use of the listener does not include the worker parameter on the gunicorn command.

Again, there’s a lot of conjecture here - I haven’t taken any time to play with this myself. If I were doing this, the first thing I’d do is try it exactly as it is documented and not add any parameters that aren’t in the example.

Also, I believe you need a backslash at the end of each line as a continuation character. I think you need to add a backslash to all but the last line of your ExecStart parameter.

I did follow everything in the tutorial, but there were new variables that wasn’t mentioned in the past and I don’t know what to do with it:

One thing I did notice is that you don’t have the \ as the continuation character at the end of the lines on your ExecStart directive.

What new variables are you talking about?

user. workingdirectory, and execstart.

i found a youtube video and followed it… took over 6 hours to find out what the issue was…

Apparently, I had to create a username on ubtun and that is the User that I was going to use. I wasn’t suppose to use root.
workingdirectory is the folder where you can find the wsgi file and exec start is where you can find the gunicorn file. For people who have the same issue as me, make sure you install all your modules inside your env as well.

could u send the url of videos? I have similar problem


pi@raspberrypi:~ $ sudo systemctl daemon-reload
pi@raspberrypi:~ $ sudo systemctl restart gunicorn
pi@raspberrypi:~ $ file /run/gunicorn.sock
/run/gunicorn.sock: socket
pi@raspberrypi:~ $ sudo systemctl status gunicorn
● gunicorn.service - gunicorn daemon
     Loaded: loaded (/etc/systemd/system/gunicorn.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Mon 2023-06-05 21:40:49 CEST; 11s ago
TriggeredBy: ● gunicorn.socket
    Process: 7251 ExecStart=/home/pi/Folderdjangodir/Folderdjangoenv/bin/gunicorn --access-logfile - --workers 3 --b>
   Main PID: 7251 (code=exited, status=203/EXEC)
        CPU: 5ms

cze 05 21:40:49 raspberrypi systemd[1]: Started gunicorn daemon.
cze 05 21:40:49 raspberrypi systemd[7251]: gunicorn.service: Failed to execute /home/pi/Folderdjangodir/Folderdjango>
cze 05 21:40:49 raspberrypi systemd[7251]: gunicorn.service: Failed at step EXEC spawning /home/pi/Folderdjangodir/F>
cze 05 21:40:49 raspberrypi systemd[1]: gunicorn.service: Main process exited, code=exited, status=203/EXEC
cze 05 21:40:49 raspberrypi systemd[1]: gunicorn.service: Failed with result 'exit-code'.

Unfortunately, I don’t have the link to the video anymore.

It looks like there’s an issue with your gunicorn file. I suggest starting a new thread and posting what you have in your gunicorn.service file

The main problem with this tutorial is that after step:
mkdir ~/myprojectdir
cd ~/myprojectdir
we should also do:
sudo chown username path-with-myprojectdir.

Also, all commands outside of the environment are preceded by ‘sudo’.