Error in deploy Gunicorn and Supervisor on AWS EC2

ahmed osama

I'm new to this, so please be patient

I am trying to deploy a flask app using AWS Ubuntu machine with open ports 443 and 80

when I run the flask app using sudo python app.py it works.

The problem appears when I try to use gunicorn. when I use the command

gunicorn -b 0.0.0.0:443 app:app

it pushes this error

[2018-06-18 13:30:30 +0000] [11135] [INFO] Starting gunicorn 19.8.1
[2018-06-18 13:30:30 +0000] [11135] [ERROR] Retrying in 1 second.
[2018-06-18 13:30:31 +0000] [11135] [ERROR] Retrying in 1 second.
[2018-06-18 13:30:32 +0000] [11135] [ERROR] Retrying in 1 second.
[2018-06-18 13:30:33 +0000] [11135] [ERROR] Retrying in 1 second.
[2018-06-18 13:30:34 +0000] [11135] [ERROR] Retrying in 1 second.
[2018-06-18 13:30:35 +0000] [11135] [ERROR] Can't connect to ('0.0.0.0', 443)

I have checked that no process listen to port 443 using lsof -i:443

Here is app.py

from flask import Flask
application = Flask(__name__)

@application.route("/")
def index():
    return "Hello World!"

if __name__ == "__main__":
    application.run(host='0.0.0.0', port='443')

Edited : gunicorn error solved by installing it using sudo -H pip install gunicorn

I am trying to deploy app in production so i want it continuously running . i tried supervisor to keep it up all the time

Here is the configuration of supervisor

[program:app_name]
directory=/home/ubuntu/FIFA_Captcha
command=/usr/local/bin/gunicorn -b 0.0.0.0:443 app:app
autostart=true
user=root
autorestart=true
stderr_logfile=/home/ubuntu/app_name.err.log
stdout_logfile=/home/ubuntu/app_name.out.log
environment=PYTHONPATH=/usr/bin/python

output sudo service supervisor status

Jun 18 22:02:39 ip-172-31-3-59 systemd[1]: Started Supervisor process control system for UNIX.
Jun 18 22:02:39 ip-172-31-3-59 supervisord[19562]: 2018-06-18 22:02:39,828 CRIT Supervisor running as root (no user in config file)
Jun 18 22:02:39 ip-172-31-3-59 supervisord[19562]: 2018-06-18 22:02:39,829 WARN Included extra file "/etc/supervisor/conf.d/app_name.conf" Jun 18 22:02:39 ip-172-31-3-59 supervisord[19562]: 2018-06-18 22:02:39,834 INFO RPC interface 'supervisor' initialized
Jun 18 22:02:39 ip-172-31-3-59 supervisord[19562]: 2018-06-18 22:02:39,834 CRIT Server 'unix_http_server' running without any HTTP authenticatJun 18 22:02:39 ip-172-31-3-59 supervisord[19562]: 2018-06-18 22:02:39,834 INFO supervisord started with pid 19562
Jun 18 22:02:40 ip-172-31-3-59 supervisord[19562]: 2018-06-18 22:02:40,837 INFO spawned: 'app_name' with pid 19569
Jun 18 22:02:40 ip-172-31-3-59 supervisord[19562]: 2018-06-18 22:02:40,952 INFO exited: app_name(exit status 3; not expected)
Jun 18 22:02:41 ip-172-31-3-59 supervisord[19562]: 2018-06-18 22:02:41,955 INFO spawned: 'app_name' with pid 19574
Jun 18 22:02:42 ip-172-31-3-59 supervisord[19562]: 2018-06-18 22:02:42,069 INFO exited: app_name(exit status 3; not expected)

output from app_name.err.log. Although I set PYTHONPATH

  File "/usr/local/lib/python2.7/dist-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/util.py", line 350, in import_app
    __import__(module)
  File "/home/ubuntu/FIFA_Captcha/app.py", line 2, in <module>
    from flask import Flask, render_template, request
ImportError: No module named flask
[2018-06-18 22:09:34 +0000] [19681] [INFO] Worker exiting (pid: 19681)
[2018-06-18 22:09:34 +0000] [19677] [INFO] Shutting down: Master
[2018-06-18 22:09:34 +0000] [19677] [INFO] Reason: Worker failed to boot.
George Sibble

You'd need to be root to use port 443.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

TOP Ranking

HotTag

Archive