I’ve django application running with uwsgi and nginx. I was using uwsgi python package to configure uwsgi manually. Now i need to switch to supervisor to run the uwsgi process. I create the supervisor config and started the uwsgi processes and the site is working but i’m getting the following error when i start the uwsgi process using supervisorctl command
uwsgi:uwsgi_00: ERROR (spawn error)
But there are 8 processes created in the server. I’m not sure why i’m getting this error then.
I’m attaching my supervisor config and uwsgi.ini file
[program:uwsgi]
command=/var/www/django/virtual/bin/uwsgi —ini /var/www/django/uwsgi.ini
user=root
process_name = %(program_name)s_%(process_num)02d
autostart=true
autorestart=true
stderr_logfile=/var/www/django/super.log
stdout_logfile=/var/www/django/super.log
Uwsgi.ini file
[uwsgi]
master = true
socket = /tmp/uwsgi.sock
chmod-socket = 666
chdir = /var/www/django/webserver_test
wsgi-file = /var/www/django/webserver_test/Django_app/wsgi.py
virtualenv = /var/www/django/virtual
pythonpath = /var/www/django/virtual/bin/python
vacuum = true
enable-threads = true
daemonize= /var/www/django/uwsgi.log
Supervisor error log:
2017-05-29 09:49:50,953 INFO spawned: ‘uwsgi_00’ with pid 20819 2017-05-29 09:49:50,978 INFO exited: uwsgi_00 (exit status 0; not expected) 2017-05-29 09:49:51,979 INFO gave up: uwsgi_00 entered FATAL state, too many start retries too quickly 2017-05-29 10:01:52,874 INFO spawned: ‘uwsgi_00’ with pid 20993 2017-05-29 10:01:52,906 INFO exited: uwsgi_00 (exit status 0; not expected) 2017-05-29 10:01:53,914 INFO spawned: ‘uwsgi_00’ with pid 20998 2017-05-29 10:01:53,932 INFO exited: uwsgi_00 (exit status 0; not expected) 2017-05-29 10:01:55,941 INFO spawned: ‘uwsgi_00’ with pid 21005 2017-05-29 10:01:55,966 INFO exited: uwsgi_00 (exit status 0; not expected) 2017-05-29 10:01:58,976 INFO spawned: ‘uwsgi_00’ with pid 21013 2017-05-29 10:01:58,994 INFO exited: uwsgi_00 (exit status 0; not expected) 2017-05-29 10:01:59,995 INFO gave up: uwsgi_00 entered FATAL state, too many start retries too quickly
And the server configuration is 1 core, 2GB RAM
IS it possible to reduce the number of processes created by supervisor
I’ve gone through how to use celery on my django production server using supervisor.
However when I try to start supervisor with sudo supervisorctl start app-celery
— it returns:
app-celery: ERROR (spawn error)
Here is my config /etc/supervisor/conf.d/app-celery.conf
:
[program:app-celery]
command=/home/zorgan/app/env/bin/celery worker -A draft1 --loglevel=INFO
directory=/home/zorgan/app/draft1
numprocs=1
stdout_logfile=/var/log/supervisor/celery.log
stderr_logfile=/var/log/supervisor/celery.log
autostart=true
autorestart=true
startsecs=10
; Need to wait for currently executing tasks to finish at shutdown.
; Increase this if you have very long running tasks.
stopwaitsecs = 600
stopasgroup=true
; Set Celery priority higher than default (999)
; so, if rabbitmq is supervised, it will start first.
priority=1000
I’ve followed the tutorial word for word — I don’t know why it is not working. I’ve checked that my path to celery
is /home/zorgan/app/env/bin/celery
, and my celery.py
and tasks.py
is in /home/zorgan/app/draft1
. As well as the init file in /home/zorgan/app/draft1
being changed to:
from __future__ import absolute_import, unicode_literals
#This will make sure the app is always imported when
#Django starts so that shared_task will use this app.
from .celery import app as celery_app
__all__ = ['celery_app']
Here’s my celery.py:
import os
from celery import Celery
from celery.schedules import crontab
from .settings import CELERY_BROKER_URL #CELERY_BROKER_URL = 'amqp://174.138.62.649' (changed the number for privacy reasons)
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'draft1.settings')
app = Celery("draft1", broker=CELERY_BROKER_URL)
app.config_from_object('django.conf:settings', namespace='CELERY')
app.autodiscover_tasks()
Are there any red flags here? Because I’m also getting this error in my celery.log
file:
File "/home/zorgan/app/env/lib/python3.5/site-packages/kombu/utils/imports.py", line 56, in symbol_by_name
module = imp(module_name, package=package, **kwargs)
File "/home/zorgan/app/env/lib/python3.5/site-packages/celery/utils/imports.py", line 101, in import_from_cwd
return imp(module, package=package)
File "/home/zorgan/app/env/lib/python3.5/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 956, in _find_and_load_unlocked
ImportError: No module named 'draft1'
but I’m not sure if that’s related. Here a snippet of my supervisord.log
:
2018-04-25 03:15:07,665 INFO spawned: 'app-celery' with pid 24296
2018-04-25 03:15:08,050 INFO exited: app-celery (exit status 1; not expected)
2018-04-25 03:15:09,052 INFO gave up: app-celery entered FATAL state, too many start retries too quickly
2018-04-25 03:15:09,815 INFO spawned: 'app-celery' with pid 24302
2018-04-25 03:15:10,221 INFO exited: app-celery (exit status 1; not expected)
2018-04-25 03:15:11,231 INFO spawned: 'app-celery' with pid 24309
2018-04-25 03:15:11,646 INFO exited: app-celery (exit status 1; not expected)
2018-04-25 03:15:13,650 INFO spawned: 'app-celery' with pid 24313
2018-04-25 03:15:14,068 INFO exited: app-celery (exit status 1; not expected)
2018-04-25 03:15:17,074 INFO spawned: 'app-celery' with pid 24317
2018-04-25 03:15:17,505 INFO exited: app-celery (exit status 1; not expected)
Any idea what the problem is?
project tree:
home / zorgan / app / draft1
... ...
manage.py celery.py
env tasks.py
I have an Ubuntu 16.04 machine where Apache Kafka is installed. Currently, I can make it work flawlessly by using a start_kafka.sh
script with the following contents:
JMX_PORT=17264 KAFKA_HEAP_OPTS="-Xms1024M -Xmx3072M" /home/kafka/kafka_2.11-0.10.1.0/bin/kafka-server-start.sh -daemon /home/kafka/kafka_2.11-0.10.1.0/config/server.properties
Now, I want to use supervisor
to automatically restart the process should it fail and start immediately after rebooting the machine. The problem is that I cannot make supervisor
start Kafka.
I installed supervisor
using pip
and placed this configuration file at /etc/supervisord.conf
:
; Supervisor config file.
;
; For more information on the config file, please see:
; http://supervisord.org/configuration.html
[unix_http_server]
file=/tmp/supervisor.sock ; (the path to the socket file)
[supervisord]
logfile=/tmp/supervisord.log ; (main log file;default $CWD/supervisord.log)
logfile_maxbytes=50MB ; (max main logfile bytes b4 rotation;default 50MB)
logfile_backups=10 ; (num of main logfile rotation backups;default 10)
loglevel=info ; (log level;default info; others: debug,warn,trace)
pidfile=/tmp/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
nodaemon=false ; (start in foreground if true;default false)
minfds=1024 ; (min. avail startup file descriptors;default 1024)
minprocs=200 ; (min. avail process descriptors;default 200)
; the below section must remain in the config file for RPC
; (supervisorctl/web interface) to work, additional interfaces may be
; added by defining them in separate rpcinterface: sections
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[supervisorctl]
serverurl=unix:///tmp/supervisor.sock ; use a unix:// URL for a unix socket
[program:kafka]
command=/home/kafka/kafka_2.11-0.10.1.0/start_kafka.sh ; the program (relative uses PATH, can take args)
;process_name=%(program_name)s ; process_name expr (default %(program_name)s)
startsecs=10 ; # of secs prog must stay up to be running (def. 1)
startretries=3 ; max # of serial start failures when starting (default 3)
;autorestart=unexpected ; when to restart if exited after running (def: unexpected)
;exitcodes=0,2 ; 'expected' exit codes used with autorestart (default 0,2)
stopsignal=TERM ; signal used to kill process (default TERM)
stopwaitsecs=180 ; max num secs to wait b4 SIGKILL (default 10)
stdout_logfile=NONE ; stdout log path, NONE for none; default AUTO
;environment=A="1",B="2" ; process environment additions (def no adds)
When I try to start Kafka, the following error occurs:
# supervisorctl start kafka
kafka: ERROR (spawn error)
And the supervisor log (at /tmp/supervisord.log
) contains this:
2017-01-23 22:10:24,532 INFO spawned: 'kafka' with pid 21311
2017-01-23 22:10:24,536 INFO exited: kafka (exit status 127; not expected)
2017-01-23 22:10:25,542 INFO spawned: 'kafka' with pid 21312
2017-01-23 22:10:25,559 INFO exited: kafka (exit status 127; not expected)
2017-01-23 22:10:27,562 INFO spawned: 'kafka' with pid 21313
2017-01-23 22:10:27,567 INFO exited: kafka (exit status 127; not expected)
2017-01-23 22:10:30,571 INFO spawned: 'kafka' with pid 21314
2017-01-23 22:10:30,576 INFO exited: kafka (exit status 127; not expected)
2017-01-23 22:10:31,578 INFO gave up: kafka entered FATAL state, too many start retries too quickly
It must be said that I’ve already tried removing the -daemon
flag in start_kafka.sh
to use with supervisor
but without success.
Does anyone have an idea on what’s going on?