Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"No module named simple_wsgi" when deploying following the documentation #420

Closed
anthony-o opened this issue Jan 6, 2017 · 3 comments
Closed

Comments

@anthony-o
Copy link

anthony-o commented Jan 6, 2017

I'm trying to deploy biostar following the documentation.

I'm running into 2 issues:

  1. The files live/deploy.env and live/deploy.py don't exist so I copied live/staging.env and live/staging.py to live/simple.env and live/simple.py like indicated.

  2. When I run waitress-serve --port 8080 live.deploy.simple_wsgi:application, I've got the following error:

There was an exception (ImportError) importing your module.

It had these arguments:
1. No module named deploy.simple_wsgi

So I copied those to files to live/deploy.env and live/deploy.py. This time I've got:

1. No module named simple_wsgi

Then I copied biostar/settings/base.py to live/deploy.py and this time I've got:

1. No module named logger

So I deleted line 8 from .logger import LOGGING and this time got:

1. No module named simple_wsgi

It exists a stackoverflow on the same subject, and also a similar issue (#311) which seems to be never treated.

I also tried to run waitress-serve --port 8080 live.deploy:application after my copies to live/deploy* files and got:

1. 'module' object has no attribute 'application'

And if I run waitress-serve --port 8080 live:deploy, I've got the message Serving on http://0.0.0.0:8080, but when trying to access to the deployed website, it answers with an HTTP 500 and the following logs in the waitress-server command output:

ERROR:waitress:Exception when serving /
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/site-packages/waitress/channel.py", line 338, in service
    task.service()
  File "/usr/local/lib/python2.7/site-packages/waitress/task.py", line 169, in service
    self.execute()
  File "/usr/local/lib/python2.7/site-packages/waitress/task.py", line 399, in execute
    app_iter = self.channel.server.application(env, start_response)
TypeError: 'module' object is not callable

I think the documentation lacks some precise instructions to do the deployment correctly.

@ialbert
Copy link
Owner

ialbert commented Jan 6, 2017

a module of that name needs to exist and be importable by Python. The docs are a bit out of sync but it very straightforward django and Python deployment.

Make sure the files that you import exist in the location that they are imported from - that is they are also on Python path.

@ialbert ialbert closed this as completed Jan 6, 2017
@anthony-o
Copy link
Author

anthony-o commented Jan 6, 2017

Well, after more work, I've made some little steps.

Here is what I did:

cp live/staging.env live/deploy.env
cp live/staging.py live/deploy.py
# Replace the value of DJANGO_SETTINGS_MODULE to "live.deploy" thanks to http://stackoverflow.com/a/5955623/535203
sed -i -e '/DJANGO_SETTINGS_MODULE=/ s/=.*/=live.deploy/' live/deploy.env
[[ -n "$BIOSTAR_HOSTNAME" ]] && sed -i -e "/BIOSTAR_HOSTNAME=/ s/=.*/=$BIOSTAR_HOSTNAME/" live/deploy.env
source live/deploy.env
biostar.sh init import
waitress-serve --port 8080 biostar.wsgi:application

Now it nearly works: the dynamic part of Biostar is served correctly, but the static files result in HTTP 404 errors.
I've tried to use Whitenoise following this documentation from heroku but then I have the following error:

1. cannot import name ManifestStaticFilesStorage

It seems to be due to the fact that Biostar uses an old version of Django (1.6.11) so we can't use Whitenoise.

So once again, the "Low trafic deployment" part of the documentation is not usable as is.

@anthony-o
Copy link
Author

anthony-o commented Jan 6, 2017

I've finally passed by a gunicorn conf + nginx.

Here it is:

source live/deploy.env
# Nginx config based on http://docs.gunicorn.org/en/stable/deploy.html and https://github.com/ialbert/biostar-central/blob/production/conf/server/biostar.nginx.conf
tee "$LIVE_DIR/nginx.conf" <<EOF
worker_processes 1;

user nobody nogroup;
# 'user nobody nobody;' for systems with 'nobody' as a group instead
pid /tmp/nginx.pid;
error_log /tmp/nginx.error.log;

events {
  worker_connections 1024; # increase if you have lots of clients
  accept_mutex off; # set to 'on' if nginx worker_processes > 1
  # 'use epoll;' to enable for Linux 2.6+
  # 'use kqueue;' to enable for FreeBSD, OSX
}

http {
  include /etc/nginx/mime.types;
  # fallback in case we can't determine a type
  default_type application/octet-stream;
  access_log /tmp/nginx.access.log combined;
  sendfile on;

  upstream app_server {
    # fail_timeout=0 means we always retry an upstream even if it failed
    # to return a good HTTP response

    # for UNIX domain socket setups
    server unix:/tmp/biostar.sock fail_timeout=0;

    # for a TCP configuration
    # server 192.168.0.7:8000 fail_timeout=0;
  }

  server {
    # if no Host match, close the connection to prevent host spoofing
    listen 8080 default_server;
    return 444;
  }

  server {
    # use 'listen 80 deferred;' for Linux
    # use 'listen 80 accept_filter=httpready;' for FreeBSD
    listen 8080;
    client_max_body_size 5M;

    # set the correct host(s) for your site
    server_name $SITE_DOMAIN;

    keepalive_timeout 25s;

    # path for static files
    root $LIVE_DIR/export/;
    location = /favicon.ico {
        alias    $LIVE_DIR/export/static/favicon.ico;
    }

    location = /sitemap.xml {
        alias    $LIVE_DIR/export/static/sitemap.xml;
    }

    location = /robots.txt {
        alias    $LIVE_DIR/export/static/robots.txt;
    }

    location /static/ {
        autoindex on;
        expires max;
        add_header Pragma public;
        add_header Cache-Control "public";
        access_log off;
    }

    location / {
      # checks for static file, if not found proxy to app
      try_files \$uri @proxy_to_app;
    }

    location @proxy_to_app {
      proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
      # enable this if and only if you use HTTPS
      # proxy_set_header X-Forwarded-Proto https;
      proxy_set_header Host \$http_host;
      # we don't want nginx trying to do something clever with
      # redirects, we set the Host: header above already.
      proxy_redirect off;
      proxy_pass http://app_server;
    }
  }
}
EOF

gunicorn -b unix:/tmp/biostar.sock biostar.wsgi &
# Start Nginx in non daemon mode thanks to http://stackoverflow.com/a/28099946/535203
nginx -g 'daemon off;' -c "$LIVE_DIR/nginx.conf"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants