Autorestart not working for supervisord programs - python

I am working with supervisord and I am facing issues in automatic restart of supervisord programs.
supervisord.conf
[supervisord]
logfile=/dev/null
pidfile=/tmp/supervisord.pid
nodaemon=true
[unix_http_server]
file = /tmp/supervisor.sock
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[program:worker]
command=./manage.py rq worker %(ENV_QUEUES)s
process_name=%(program_name)s-%(process_num)s
numprocs=%(ENV_WORKERS_COUNT)s
directory=/app
stopsignal=TERM
autostart=true
autorestart=true
startsecs=300
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
[eventlistener:worker_healthcheck]
autorestart=true
serverurl=AUTO
command=./manage.py rq healthcheck
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
events=TICK_60
Supervisorctl Status
abc#abc-adhocworker-c89d9667b-9lqbd:/app$ exec supervisorctl -c worker.conf status
worker:worker-0                  FATAL     Exited too quickly (process log may have details)
worker:worker-1                  FATAL     Exited too quickly (process log may have details)
worker_healthcheck               RUNNING   pid 14, uptime 7:43:34
Status shows they are in fatal state but not recovering automatically even I've configured autorestart=true.
What else do i need to make sure automatic recovery/restart of programs in case of errors ?
Edit 1
Is it possible that restart is relying on healthcheck eventlistener and it might be sending false signal i.e. everything is good and thus automatic restart not working for programs ?
Edit 2
My supervisord.conf doesn't have supervisorctl section so not sure if it is added then it can trigger auto restart correctly as without that supervisorctl status might be failing for supervisord programs ?

Related

Supervisor spawn error running uvicorn: ENXIO (No such device or address)

When I launch supervisor under root user with
supervisor -n -c /etc/supervisor/supervisord.conf
I get a few Uvicorn processes which correctly respond to requests passed from nginx via unix socket.
Creating socket unix:///var/run/supervisor/app.sock
spawned: 'uvicorn-0' with pid 15127
success: uvicorn-0 entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
If supervisor is launched automatically via systemd every Uvicorn process fails all the time with
Creating socket unix:///var/run/supervisor/app.sock
INFO spawnerr: unknown error making dispatchers for 'uvicorn-1': ENXIO
Closing socket unix:///var/run/supervisor/app.sock
I use out of the box python3 supervisor from Ubuntu 22.04 with the next config
[unix_http_server]
file=/var/run/supervisor.sock ; (the path to the socket file)
chmod=0700 ; sockef file mode (default 0700)
[supervisord]
logfile=/var/log/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log)
pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
childlogdir=/var/log/supervisor ; ('AUTO' child log dir, default $TEMP)
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[supervisorctl]
serverurl=unix:///var/run/supervisor.sock ; use a unix:// URL for a unix socket
[fcgi-program:app]
socket=unix:///var/run/supervisor/app.sock
socket_owner=app
socket_mode=766
command=/opt/app/.venv/bin/uvicorn --uds /var/run/supervisor/app.sock app.asgi:application
numprocs=1
process_name=uvicorn-%(process_num)d
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
user=app
directory=/opt/app/app
File structure looks like
/opt/app/app/
├── app
│   ├── __init__.py
│   ├── asgi.py
│   ├── settings.py
│   ├── urls.py
│   └── wsgi.py
└── manage.py
What am I missing here? Why does uvicorn fail if launched via Supervisor under Systemd?

Service not running on startup - RabbitMQ used as well

I creat a service on raspberry pi, however when rebooting and then checking the services statute I'm getting the below
pi#raspberrypi:~ $ sudo systemctl status non_verbal.service
non_verbal.service - My Sample Service
Loaded: loaded (/lib/systemd/system/non_verbal.service; enabled; vendor preset: enabled)
Active: activating (auto-restart) (Result: exit-code) since Mon 2022-06-27 12:06:54 BST;
51s ago
Process: 4378 ExecStart=/home/pi/env/bin/python3 /home/pi/linux-sdk-python-
2/examples/audio/classify3.py
Main PID: 4378 (code=exited, status=2)
lines 1-5/5 (END)
Please note that this service should send a message to Rabbitmq which is already running. I have another service as well, which is a receiver to receive messages from the rabbitMQ and perform a certain action.
This is the content of the service file
[Unit]
Description=My Sample Service
After=multi-user.target
[Service]
Type=idle
user=pi
ExecStart=/home/pi/env/bin/python3 /home/pi/linux-sdk-python-2/examples/audio/classify3.py
Restart=always
RestartSec=60
[Install]
WantedBy=multi-user.target

set up pipenv with supervisor

I want to deploy dev server but I have a problem with starting celery and gunicorn. I'm using scripts for my purposes
celery.sh
#!/bin/bash
cd /home/dev/app
pipenv run celery -A config worker -B -l info
and start.sh for gunicorn
#!/bin/bash
cd /home/dev/app
pipenv run gunicorn config.wsgi:application -b 127.0.0.1:8005 -w 2 -t 60 \
--env DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE \
--env DSN=$SENTRY_DSN \
--env DATABASE_URL=$DATABASE_URL \
--log-file - \
--error-logfile /home/dev/app/errors.log
Also here is my config for supervisor
[program:back]
directory=/home/dev/app/
command=/home/dev/bin/start
user=dev
autostart=true
autorestart=true
redirect_stderr=true
stopsignal=QUIT
stopasgroup=true
killasgroup=true
[program:celery]
directory=/home/dev/app/
command=/home/dev/bin/celery
user=dev
autostart=true
autorestart=true
redirect_stderr=true
stopsignal=QUIT
stopasgroup=true
killasgroup=true
When I'm running sudo supervisorctl start celery I'm getting the following error:
/home/dev/bin/celery: line 3: pipenv: command not found
Also I added the following lines as pipenv documentation says (https://pipenv.readthedocs.io/en/latest/diagnose/)
[supervisord]
environment=LC_ALL='en_US.UTF-8',LANG='en_US.UTF-8'
UPDATE
Changed my supervisor config:
[program:back]
directory=/home/dev/app/
command=pipenv run gunicorn config.wsgi:application --bind 127.0.0.1:8005
user=dev
autostart=true
autorestart=true
redirect_stderr=true
stopsignal=QUIT
stopasgroup=true
killasgroup=true
[program:celery]
directory=/home/dev/app/
command=pipenv run celery -A config:celery_app worker -B -l info
user=dev
autostart=true
autorestart=true
redirect_stderr=true
stopsignal=QUIT
stopasgroup=true
killasgroup=true
And now I'm getting an error:
back: ERROR (no such file)
You need to give explicit path of gunicorn. Though I'm not sure about pipenv, but the error you are getting is because supervisor tries to find gunicorn in the directory. You should change your config file into something like this:
[program:back]
directory=/home/dev/app/
command=/path/to/pipenv run /path/to/gunicorn config.wsgi:application --bind 127.0.0.1:8005
Then you must restart your supervisord in order to load the settings.
sudo service supervisord reload
in your config file. change command= to bash -c followed by the full path and file to execute
this should do the trick

How can I configure celery to run on startup of nginx?

I have celery running locally by just running celery -A proj -l info (although I don't even know if I should be using this command in production), and I want to get celery running on my production web server every time nginx starts. The init system is systemd
Create a service file like this celery.service
[Unit]
Description=celery service
After=network.target
[Service]
PIDFile=/run/celery/pid
User=celery
Group=celery
RuntimeDirectory=/path/to/project
WorkingDirectory=/path/to/project
ExecStart=celery -A proj -l info
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
Restart=on-abort
PrivateTmp=true
[Install]
WantedBy=multi-user.target
Move the file to /etc/systemd/system/ and next time your restart server, celery will be started by systemd on boot.

getting an error Unknown command: 'celery' with celery and supervisor

i am trying to setup celery with supervisord on AWS instance. I have the project up running on a virtual environment and i tested the celery by "python2.7 manage.py celery worker". But i am getting an error Unknown command: 'celery' while running with supervisor.
My supervisor configuration are below
1)
[program:celery-eatio]
environment = PYTHONPATH="/home/ubuntu/eatio_env/lib/python2.7:/home/ubuntu/eatio-server:/home/ubuntu/eatio_env/lib/python2.7/site-packages:$PYTHONPATH",DJANGO_SETTINGS_MODULE="eatio_web.settings"
command=/home/ubuntu/eatio-server/manage.py celery worker
user=ubuntu
numprocs=1
stdout_logfile=/home/ubuntu/celery_error.log
stderr_logfile=/home/ubuntu/celery_out.log
autostart=true
autorestart=true
2)
[program:celery-eatio]
command=/home/ubuntu/eatio_env/bin/python2.7 /home/ubuntu/eatio-server/manage.py celery worker --loglevel=info -c 1 -E -B -Q celery_periodic -n periodic_worker
directory=/home/ubuntu/eatio-server
user=ubuntu
autostart=true
autorestart=true
stdout_logfile=/home/ubuntu/celery_error.log
stderr_logfile=/home/ubuntu/celery_out.log

Categories

Resources