I try to start my Gunicorn server using systemd.
The service definition is presented below:
[Unit]
Description=Gunicorn instance to serve Flask application using gunicorn
After=network.target
[Service]
PIDFile=/home/username/application/app.pid
User=username
Group=nginx
WorkingDirectory=/home/username/application
Environment=PATH=/opt/venv/bin/
ExecStart=/opt/venv/bin/gunicorn --pid /home/username/application/app.pid --workers 3 --bind unix:socket.sock -m 007 app:app
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
[Install]
WantedBy=multi-user.target
The problem is that sometimes the app crashes on startup with the following messages in journalctl
gunicorn[28376]: [2019-08-22 15:01:48 +0300] [28379] [INFO] Worker exiting (pid: 28379)
gunicorn[28376]: [2019-08-22 15:01:48 +0300] [28381] [INFO] Worker exiting (pid: 28381)
gunicorn[28376]: [2019-08-22 15:01:48 +0300] [28376] [INFO] Shutting down: Master
gunicorn[28376]: [2019-08-22 15:01:48 +0300] [28376] [INFO] Reason: Worker failed to boot.
systemd[1]: urzchat-dev.service: main process exited, code=exited, status=3/NOTIMPLEMENTED
systemd[1]: urzchat-dev.service: control process exited, code=exited status=1
systemd[1]: Unit urzchat-dev.service entered failed state.
systemd[1]: urzchat-dev.service failed.
This behavior occurs about 1/3 of all starts.
Tell me, why might that be and how to fix it?
The Environment directive should be enclosed as a string:
Environment="PATH=/opt/venv/bin/"
Also, you may add a condition for your network being connected to the internet before start:
After=network.target network-online.target
Related
I'm trying to start the airflow webserver with an existing application and the latest version (2.2.2). The executor is set as LocalExecutor, the datastore is Postgres, Python v3.9. Upon start up, it launches 4 workers which promptly die. It then spins its wheels continually trying to restart them.
Here's an example of the messages showing a worker starting and dying with signal 11 (segmentation violation). This is all within a second of starting.
Using worker: sync
[2021-11-30 17:29:31 -0500] [12529] [INFO] Booting worker with pid: 12529
[2021-11-30 17:29:31 -0500] [12530] [INFO] Booting worker with pid: 12530
[2021-11-30 17:29:31 -0500] [12531] [INFO] Booting worker with pid: 12531
[2021-11-30 17:29:31 -0500] [12532] [INFO] Booting worker with pid: 12532
Running the Gunicorn Server with:
Workers: 4 sync
Host: 0.0.0.0:8080
Timeout: 120
settings.prepare_engine_args(): Using pool settings. pool_size=5, max_overflow=10, pool_recycle=1800, pid=12529
[WARNING] Worker with pid 12529 was terminated due to signal 11
Any suggestions on how to debug these workers?
I gave up on trying to run Airflow directly on my M1 Mac. I suspect it has something to do with the emulator for the M1 chip, but don't know for sure. I fell back to running Airflow in Docker. It takes a very long time to start, but does run OK that way.
I have a Python + FastAPI restful API project running the free tier of Oracle Cloud VM instance.
I use Gunicorn to serve the api and also installed Nginx just in case it's needed.
I have tested my running project with
curl http://localhost:8000
and I can see my API response.
Now my question is : how can I expose this api endpoint outside on the Internet?
Update 1
I started my Python API project with this command:
gunicorn -w 4 -k uvicorn.workers.UvicornWorker main:app --timeout 1200 -b 0.0.0.0
I saw the messages below:
[2021-05-23 00:40:28 +0000] [3850] [INFO] Starting gunicorn 20.0.2
[2021-05-23 00:40:28 +0000] [3850] [INFO] Listening at: http://0.0.0.0:8000 (3850)
[2021-05-23 00:40:28 +0000] [3850] [INFO] Using worker: uvicorn.workers.UvicornWorker
[2021-05-23 00:40:28 +0000] [3853] [INFO] Booting worker with pid: 3853
[2021-05-23 00:40:28 +0000] [3854] [INFO] Booting worker with pid: 3854
[2021-05-23 00:40:28 +0000] [3857] [INFO] Booting worker with pid: 3857
[2021-05-23 00:40:28 +0000] [3858] [INFO] Booting worker with pid: 3858
[2021-05-23 00:42:04 +0000] [3853] [INFO] Started server process [3853]
[2021-05-23 00:42:04 +0000] [3857] [INFO] Started server process [3857]
[2021-05-23 00:42:04 +0000] [3857] [INFO] Waiting for application startup.
[2021-05-23 00:42:04 +0000] [3858] [INFO] Started server process [3858]
[2021-05-23 00:42:04 +0000] [3858] [INFO] Waiting for application startup.
[2021-05-23 00:42:04 +0000] [3858] [INFO] Application startup complete.
[2021-05-23 00:42:04 +0000] [3853] [INFO] Waiting for application startup.
[2021-05-23 00:42:04 +0000] [3853] [INFO] Application startup complete.
[2021-05-23 00:42:04 +0000] [3857] [INFO] Application startup complete.
[2021-05-23 00:42:04 +0000] [3854] [INFO] Started server process [3854]
[2021-05-23 00:42:04 +0000] [3854] [INFO] Waiting for application startup.
[2021-05-23 00:42:04 +0000] [3854] [INFO] Application startup complete.
Then I copied the IP address from the Compute >> Instances >> Instance Details panel and accessed it from my Chrome. Straightaway, it shows me
Unable to connect
Also read through several articles about using Nginx and tried without any luck.
Update 2
Using curl to access the website from my local machine
$ curl http://168.138.12.192:8000/
curl: (7) Failed to connect to 168.138.12.192 port 8000: No route to host
However, when access the IP directly using curl, I was able to get the default Nginx website.
$ curl http://168.138.12.192
Finally, I found out what I missed:
sudo iptables -I INPUT -p tcp -s 0.0.0.0/0 --dport 8000 -j ACCEPT
I have to run this command to open the port 8000(yes, my website is using port 8000).
I thought I have added Ingress Rule to accept tcp 8000, but it turns out that I still need to run the aforementioned command.
I do not quite understand why I need to do it, but it solves the problem.
Did you changed the default html page under /var/www/html directory? If not try customize the html page as per your requirement and see if it works for you or else it would just show the default nginx page when accessed from browser using public IP.
Adding to this, Also check if the port 8000 is allowed in the security list and OS firewall. The default port for http request is 80, you need to change the default port from 80 to 8000 in the config file to make this work. refer this page this might be useful How to Change Apache HTTP Port in Linux.
I followed this tutorial
https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-centos-7
Tried to deploy Django project on centos 8
Everything went fine and worked, except gunicorn.service
[Unit]
Description=gunicorn daemon
After=network.target
[Service]
User=facealatoo
Group=nginx
WorkingDirectory=/home/facealatoo/nadyr/promed
ExecStart=/home/facealatoo/nadyr/promed/venv/bin/gunicorn \
--workers 3 \
--bind unix:/home/facealatoo/nadyr/promed/promed.sock \
configs.wsgi:application
[Install]
WantedBy=multi-user.target
Folders destinations
my project folder destination '/home/facealatoo/nadyr/promed' settings.py file 'home/facealatoo/nadyr/promed/configs/settings.py'
server user name 'facealatoo'
after running
sudo systemctl daemon-reload
sudo systemctl start gunicorn
sudo systemctl enable gunicorn
sudo systemctl status gunicorn.service
Error message
● gunicorn.service - gunicorn daemon
Loaded: loaded (/etc/systemd/system/gunicorn.service; enabled; vendor
preset: disabled)
Active: failed (Result: exit-code) since Fri 2020-05-15 18:37:22 +06; 13s
ago
Main PID: 32293 (code=exited, status=203/EXEC)
May 15 18:37:22 facealatoo.net.kg systemd[1]: Started gunicorn daemon.
May 15 18:37:22 facealatoo.net.kg systemd[1]: gunicorn.service: Main
process exited, code=exited, status=203/EXEC
May 15 18:37:22 facealatoo.net.kg systemd[1]: gunicorn.service: Failed
with result 'exit-code'.
Please help me! ;) Thanks in advance ))))
I just change socket file destination (home/facealatoo(user)/) and gunicorn destination (usr/local/bin/gunicorn). And these actions solved my problem)))
I follow this article to deploy my Django project. I created gunicorn.service file in /etc/systemd/system/gunicorn.service with this configuration:
[Unit]
Description=gunicorn daemon
After=network.target
[Service]
User=azizbek
Group=www-data
WorkingDirectory=/home/admin/respositories/ninersComingSoon
ExecStart=/root/.local/share/virtualenvs/ninersComingSoon-_UZsUc5R/bin/gunicorn --access-logfile - --workers 3 --bind unix:/home/admin/repositories/ninersComingSoon/niners.sock ninersComingSoon.wsgi:application
[Install]
WantedBy=multi-user.target
Location of my project is /home/admin/respositories/ninersComingSoon
And when I run
systemctl start gunicorn
systemctl enable gunicorn
it must create niners.sock file inside the project directory but it doesn't.
Then I typed this command to figure out what I did wrong.
journalctl -u gunicorn
And the result was
Dec 05 02:05:26 server.niners.uz systemd[1]: Started gunicorn daemon.
Dec 05 02:05:26 server.niners.uz systemd[1]: gunicorn.service: Main process exited, code=exited, status=203/EXEC
Dec 05 02:05:26 server.niners.uz systemd[1]: gunicorn.service: Unit entered failed state.
Dec 05 02:05:26 server.niners.uz systemd[1]: gunicorn.service: Failed with result 'exit-code'.
So can you help me to solve this problem?
The problem was in WorkingDirectory. There was an incorrect path. There should be .../repositories/... instead of .../respositories/...
Im trying to run flower as daemon. My flower.service file read as follows:
[Unit]
Description=Flower Service
After=network.target
[Service]
Type=forking
User=maas
Group=maas
PermissionsStartOnly=true
ExecStart=/bin/flower --broker=amqp://oser000300//
[Install]
WantedBy=multi-user.target
But when i start the service, it is giving error.
//systemctl status flower.service
* flower.service - Flower Service
Loaded: loaded (/etc/systemd/system/flower.service; enabled; vendor preset: disabled)
Active: failed (Result: timeout) since Mon 2017-07-10 20:25:59 UTC; 4min 38s ago
Process: 49255 ExecStart=/bin/flower --broker=amqp://oser000300// (code=exited, status=0/SUCCESS)
Connected to amqp://guest:**#oser000300:5672//
flower.service start operation timed out. Terminating.
SIGTERM detected, shutting down
Failed to start Flower Service.
Unit flower.service entered failed state.
flower.service failed.
I had the same timeout problem when starting the service.
Those parameters has done the trick (i had already celery service running with forking type):
Type=simple
Restart=on-failure