I'm trying to start the swagger server using gunicorn on ec2 instance by using the following code:
I tried :
gunicorn -w 4 -b 0.0.0.0:8080 -p pidfile -D swagger_server:app
and this:
gunicorn -w 4 -b 0.0.0.0:8080 -p pidfile -D "python3 -m swagger_server":app
and even this :
gunicorn -w 4 -b 0.0.0.0:8080 -p pidfile -D __main__:app
How can I get it to work?
RAW python code which works : python3 -m swagger_server
What you are trying to do is equivalent to:
from swagger_server.__main__ import main
For this to work with gunicorn, try:
gunicorn "swagger_server.__main__:main" -w 4 -b 0.0.0.0:8080`
In case you have the error:
ImportError: No module named swagger_server
add the PYTHONPATH to gunicorn command:
gunicorn "swagger_server.__main__:main" -w 4 -b 0.0.0.0:8080 --pythonpath path_to_swagger_server
gunicorn -b 0.0.0.0:8080 main:app --reload
This should be the correct syntax, obviously make sure you're in the correct directory and source your virtualenv.
isn't your application looking for a configuration file with a section like [app:main]?
This one worked for me:
gunicorn "swagger_server.__main__:app" -w 4 -b 0.0.0.0:8080
Related
Ok, I'm new to Python/Flask deployment and was following this tutorial.
This is my system file:
[Unit]
Description=Gunicorn instance to serve myapp
After=network.target
[Service]
User=deployer
Group=www-data
WorkingDirectory=/home/deployer/myapp
Environment="PATH=/home/deployer/myapp/myapp_env/bin"
ExecStart=/home/deployer/myapp/myapp_env/bin/gunicorn --workers 3 --bind unix:myapp.sock -m 007 appserver:gunicorn_app
[Install]
WantedBy=multi-user.target
But it doesn't work. I get Main process exited, code=exited, status=203/EXEC or /root/myapp/myapp_env/bin/python3: bad interpreter: Permission denied
If I cd into my myapp directory and issue the gunicorn command like so:
gunicorn --workers 3 --bind unix:smarrttrader_api.sock -m 007 appserver:gunicorn_app
Everything works fine. If I do a which gunicorn from my app directory I get /usr/local/bin/gunicorn and try to run ()from elsewhere in the server like so:
/usr/local/bin/gunicorn --workers 3 --bind unix:smarrttrader_api.sock -m 007 appserver:gunicorn_app
It doesn't work and I get the following error: ImportError: No module named 'appserver', so how can I get it to work?
when i run "supervisorctl status hitbot" then i face this error
FATAL Exited too quickly (process log may have details)
#/bin/gunicorn_start
Here **BIND= ip_address:port **
/etc/supervisor/conf.d/hitbot.conf
But when i type these command
In log file
But when it test gunicorn_start by "bash /bin/gunicorn_start"* then it working fine
Try this command: pkill -HUP gunicorn
Gunicorn docs: http://docs.gunicorn.org/en/stable/faq.html
"You can gracefully reload by sending HUP signal to gunicorn: $ kill -HUP masterpid"
or with the full command line:
pkill -HUP -f '/usr/bin/python /usr/bin/gunicorn -w 5 -b 127.0.0.1:5000 myapp:app'
I Launch my Django app in a docker container, using a startup script as per the below:-
#!/bin/bash
python manage.py collectstatic --noinput
python manage.py makemigrations
python manage.py migrate
/etc/init.d/celeryd start
/etc/init.d/celerybeat start
exec gunicorn itapp.wsgi -b 0.0.0.0:8000
Unicorn and ngnix every now and then give me a 502 error, so I went to look for logs and it looks by default gunicorn does not log any? im on version 19.7.1
so I added the to the exec guncicorn command:
exec gunicorn itapp.wsgi -b 0.0.0.0:8000 --error-logfile /var/log/gunicorn/errors.log , --log-file /var/log/gunicorn/access.log
Which I goy form the gunicorn documentation. however now Gunicorn fails to launch with the following error:-
usage: gunicorn [OPTIONS] [APP_MODULE]
gunicorn: error: unrecognized arguments: ,
How can I create the gunicorn logs to debug these errors?
Thanks
Remove comma and you should be fine:
exec gunicorn itapp.wsgi -b 0.0.0.0:8000 --error-logfile /var/log/gunicorn/errors.log --log-file /var/log/gunicorn/access.log
I am not able to access server when starting gunicorn via a .bash file I made. It works when I do it manually with this command
$ gunicorn project.wsgi:application --bind 192.168.1.130:8000
Created a gunicorn.bash file from tutorials. I looks like this and runs without fault.
#!/bin/bash
NAME="project" # Name of the application
DJANGODIR=/home/username/projects/project # Django project directory
SOCKFILE=/home/username/.venvs/project/run/gunicorn.sock # We will communicate using this unix socket
USER=username # the user to run as
GROUP=username # the group to run as
NUM_WORKERS=1 # how many worker processes shoul Gunicorn spawn
DJANGO_SETTINGS_MODULE=project.settings.production # which settings file should Django use
DJANGO_WSGI_MODULE=project.wsgi # WSGI module name
echo "Starting $NAME as `whoami`"
# Activate the virtual environment
cd $DJANGODIR
source /home/username/.venvs/project/bin/activate
export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE
export PYTHONPATH=$DJANGODIR:$PYTHONPATH
# Create the run directory if it doesn't exsist
RUNDIR=$(dirname $SOCKFILE)
test -d $RUNDIR || mkdir -p $RUNDIR
# Start yout Django Unicorn
# Programs meant to be run under supervisor should not daemonize themselves (do not use daemon)
exec gunicorn ${DJANGO_WSGI_MODULE}:application \
--name $NAME \
--workers $NUM_WORKERS \
--user=$USER --group=$GROUP \
--bind=unix:$SOCKFILE \
--log-level=debug \
--log-file=-
I don't know how to troubleshoot this? Maybe some command to see what differs in running settings from manually starting gunicorn and from the .bash file?
$ gunicorn project.wsgi:application --bind 192.168.1.130:8000
Above you use --bind with host:port but below:
exec gunicorn ${DJANGO_WSGI_MODULE}:application \
--name $NAME \
--workers $NUM_WORKERS \
--user=$USER --group=$GROUP \
--bind=unix:$SOCKFILE \
--log-level=debug \
--log-file=-
you specify unix:file which will make your gunicorn listen on unix socket file instead of on your network interface:port, so just replace the unix:$SOCKFILE with 192.168.1.130:8000 and it should be accessible as expected
Additionally you can try and connect to the current config with a curl (curl --unix-socket /path/to/socket http:/some/resurce) or other tool of your choice to verify that it actually runs
I have a python project that I need running on a screen using uWSGI, if I run the script:
screen -d -m uwsgi --emperor "/home/rrcms/wsgi.ini" --socket :8000 --chdir /home/rrcms/ --wsgi-file /home/rrcms/wsgi.py
It will create a new screen and run the script properly, but when I try to add it to crontab it won't even create the screen, this is the script I'm using:
#reboot screen -d -m uwsgi --emperor "/home/rrcms/wsgi.ini" --socket :8000 --chdir /home/rrcms/ --wsgi-file /home/rrcms/wsgi.py
You should replace uwsgi with its absolute path:
(get absolute path from terminal: which uwsgi)
#reboot screen -d -m /home/user/venv/bin/uwsgi --emperor "/home/rrcms/wsgi.ini" --socket :8000 --chdir /home/rrcms/ --wsgi-file /home/rrcms/wsgi.py