gunicorn fails to launch python-eve

Here’s settings.py

root@00d72ee95c2d:/var/www/eve-auth# cat settings.py
DOMAIN = {'people': {}}

And here’s run.py

  • OpenVSwitch in container with IP-Tables
  • Get command used to start a Docker container
  • cAdvisor: How to run it with a remote docker API?
  • Visual Studio 2015 Docker Integration wont attach for debuging
  • In docker-compose how to create an alias / link to localhost?
  • Difference between 2 varieties of Dockerfiles for running a nodejs app
  • from eve import Eve
    app = Eve()
    
    if __name__ == '__main__':
        app.run()
    

    It works when I run it standalone:

    root@00d72ee95c2d:/var/www/eve-auth# python run.py
     * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
    

    But fails to run when I launch it through gunicorn:

    root@00d72ee95c2d:/var/www/eve-auth# gunicorn -b 0.0.0.0:5000 run:app
    [2016-02-12 02:07:22 +0000] [20] [INFO] Starting gunicorn 19.4.5
    [2016-02-12 02:07:22 +0000] [20] [INFO] Listening at: http://0.0.0.0:5000 (20)
    [2016-02-12 02:07:22 +0000] [20] [INFO] Using worker: sync
    [2016-02-12 02:07:22 +0000] [23] [INFO] Booting worker with pid: 23
    [2016-02-12 02:07:22 +0000] [23] [ERROR] Exception in worker process:
    Traceback (most recent call last):
      File "/usr/local/lib/python3.5/site-packages/eve/flaskapp.py", line 246, in validate_domain_struct
        domain = self.config['DOMAIN']
    KeyError: 'DOMAIN'
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "/usr/local/lib/python3.5/site-packages/gunicorn/arbiter.py", line 515, in spawn_worker
        worker.init_process()
      File "/usr/local/lib/python3.5/site-packages/gunicorn/workers/base.py", line 122, in init_process
        self.load_wsgi()
      File "/usr/local/lib/python3.5/site-packages/gunicorn/workers/base.py", line 130, in load_wsgi
        self.wsgi = self.app.wsgi()
      File "/usr/local/lib/python3.5/site-packages/gunicorn/app/base.py", line 67, in wsgi
        self.callable = self.load()
      File "/usr/local/lib/python3.5/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
        return self.load_wsgiapp()
      File "/usr/local/lib/python3.5/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
        return util.import_app(self.app_uri)
      File "/usr/local/lib/python3.5/site-packages/gunicorn/util.py", line 357, in import_app
        __import__(module)
      File "/var/www/eve-auth/run.py", line 2, in <module>
        app = Eve()
      File "/usr/local/lib/python3.5/site-packages/eve/flaskapp.py", line 135, in __init__
        self.validate_domain_struct()
      File "/usr/local/lib/python3.5/site-packages/eve/flaskapp.py", line 248, in validate_domain_struct
        raise ConfigException('DOMAIN dictionary missing or wrong.')
    eve.exceptions.ConfigException: DOMAIN dictionary missing or wrong.
    Traceback (most recent call last):
      File "/usr/local/lib/python3.5/site-packages/eve/flaskapp.py", line 246, in validate_domain_struct
        domain = self.config['DOMAIN']
    KeyError: 'DOMAIN'
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "/usr/local/lib/python3.5/site-packages/gunicorn/arbiter.py", line 515, in spawn_worker
        worker.init_process()
      File "/usr/local/lib/python3.5/site-packages/gunicorn/workers/base.py", line 122, in init_process
        self.load_wsgi()
      File "/usr/local/lib/python3.5/site-packages/gunicorn/workers/base.py", line 130, in load_wsgi
        self.wsgi = self.app.wsgi()
      File "/usr/local/lib/python3.5/site-packages/gunicorn/app/base.py", line 67, in wsgi
        self.callable = self.load()
      File "/usr/local/lib/python3.5/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
        return self.load_wsgiapp()
      File "/usr/local/lib/python3.5/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
        return util.import_app(self.app_uri)
      File "/usr/local/lib/python3.5/site-packages/gunicorn/util.py", line 357, in import_app
        __import__(module)
      File "/var/www/eve-auth/run.py", line 2, in <module>
        app = Eve()
      File "/usr/local/lib/python3.5/site-packages/eve/flaskapp.py", line 135, in __init__
        self.validate_domain_struct()
      File "/usr/local/lib/python3.5/site-packages/eve/flaskapp.py", line 248, in validate_domain_struct
        raise ConfigException('DOMAIN dictionary missing or wrong.')
    eve.exceptions.ConfigException: DOMAIN dictionary missing or wrong.
    [2016-02-12 02:07:22 +0000] [23] [INFO] Worker exiting (pid: 23)
    [2016-02-12 02:07:22 +0000] [20] [INFO] Shutting down: Master
    [2016-02-12 02:07:22 +0000] [20] [INFO] Reason: Worker failed to boot.
    

    I couldn’t find any documentation about gunicorn and python-eve… so I’m not sure where to dig from here.

  • Get IP address of host where docker engine is running
  • Docker file permissions with volumes, Boot2docker and Virtualbox
  • Docker windows with hyper-v example baffles me??? Why does the alpine example not work they way I thought it would?
  • Insert data after mysql started in a docker container
  • How to activate docker 1.12 in terminal without Moby the whale app on Mac
  • Docker for mac hostname insteat of IP
  • 2 Solutions collect form web for “gunicorn fails to launch python-eve”

    I never ran Eve on Gunicorn. However, Eve being a Flask subclass, most things that work with Flask, work for Eve too.

    According to Flask documentation you run Flask/Eve on Gunicorn like this:

    gunicorn myproject:app
    

    Hope this helps.

    The problem is that Eve uses a relative path to look for settings.py, the quickest fix is to use an absolute path:

    import os
    from eve import Eve
    
    app = Eve(__name__, settings=os.path.abspath('settings.py'))
    
    if __name__ == '__main__':
        app.run()
    
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.