I have a problem with my configuration from supervisor, my app is using django_channles well, when I run my app using of two codes below working well
(myenv)/colonybit/colonybitbasics/python manage.py runserver 0.0.0.0:8000
or
(myenv)/colonybit/colonybitbasics/daphne -b 0.0.0.0 -p 8000
and I have other app in vuejs, the code above is working, but when I try run my app with this code below like this
(myenv)/colonybit/ ./bin/start.sh
my file start.sh
NAME="colony_app"
DJANGODIR=/home/ubuntu/colonybit # Django project directory
SOCKFILE=/home/ubuntu/colonybit/run/gunicorn.sock
USER=ubuntu # the user to run as
GROUP=ubuntu # the group to run as
NUM_WORKERS=3
DJANGO_SETTINGS_MODULE=colonybit.settings
DJANGO_WSGI_MODULE=colonybit.asgi # ASGI module name
echo "Starting $NAME as `whoami`"
# Activate the virtual environment
cd $DJANGODIR
source /home/ubuntu/colonybit/bin/activate
export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE
export PYTHONPATH=$DJANGODIR:$PYTHONPATH
# Create the run directory if it doesn't exist
RUNDIR=$(dirname $SOCKFILE)
test -d $RUNDIR || mkdir -p $RUNDIR
exec colonybit ${DJANGO_WSGI_MODULE}:application \
--name $NAME \
--workers $NUM_WORKERS \
--user=$USER --group=$GROUP \
--bind=0.0.0.0:8000 \
--log-level=debug \
--log-file=-
the server is running well, but my app in vuejs, show me an error 500, can't cossuming my app in django_channels
please told me, how to config my file start.sh for working using ASGI
thanks for your time.
Your django app works with its development server, because this server handles both http and websocket requests for you. Now looks your problem is with production, and gunicorn couldn't handle both requests, so daphne comes to play.
A BF way to solve it is to start the daphne ASGI within another file, which contains- exec daphne -b 0.0.0.0 -p 8001 $DJANGO_ASGI_MODULE:application (note the different port used here), other parts of the two files should be quite similar. Lately, you can refer to this for more sight, or see whether abandon unix sockets is necessary (it works for me): https://github.com/django/channels/issues/919#issuecomment-422346729
Once you've done this, integrate with supervisor to make your run simple and stable.