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

django.wsgi #572

Closed
ghost opened this issue Apr 14, 2016 · 10 comments
Closed

django.wsgi #572

ghost opened this issue Apr 14, 2016 · 10 comments

Comments

@ghost
Copy link

ghost commented Apr 14, 2016

Hello,
I installed Askbot locally following the documentation step by step.

When I run Askbot using python manage.py runserverhostname -i:8000 everything seems to work fine but using the above apache configuration it seems to end in a neverending loop. The output of the log is:

tail -f /var/log/apache2/askbot_error.log 
mod_wsgi (pid=31580): Attach interpreter ''.
mod_wsgi (pid=31580): Imported 'mod_wsgi'.
mod_authz_core.c(802): [client 127.0.0.1:41774] AH01626: authorization result of Require all granted: granted
mod_authz_core.c(802): [client 127.0.0.1:41774] AH01626: authorization result of <RequireAny>: granted
mod_authz_core.c(802): [client 127.0.0.1:41774] AH01626: authorization result of Require all granted: granted
mod_authz_core.c(802): [client 127.0.0.1:41774] AH01626: authorization result of <RequireAny>: granted
mod_wsgi (pid=31580): Create interpreter 'askbot.localhost|'.
mod_wsgi (pid=31580, process='askbot', application='askbot.localhost|'): Loading WSGI script '/var/www/html/askbot-devel/django.wsgi'.
Script timed out before returning headers: django.wsgi

But it wont go any further and the site wont stop loading...

Any idea why and how to solve it?

@ghost ghost changed the title Apache - Loop django.wsgi Apr 14, 2016
@ghost ghost closed this as completed Apr 21, 2016
@evgenyfadeev
Copy link
Member

Hi Marc, could you put a hint to solution here please?

@ghost
Copy link
Author

ghost commented Apr 21, 2016

Well I seem to got it to work for some time until it stopped suddendly again. Currently trying to find out why but the problem were some missing requirements and some errors with the virtualenv. I updated the install script above.

@evgenyfadeev
Copy link
Member

Does "python manage.py runserver" command start a working site?
If so then the issue is in the deployment

@evgenyfadeev evgenyfadeev reopened this Apr 21, 2016
@ghost
Copy link
Author

ghost commented Apr 21, 2016

It did before, right now it doesnt do anything anymore. Using the runserver will load forever and no output on the console.

@evgenyfadeev
Copy link
Member

Then solve the problem using the runserver, this also allows you to use debugger more easily.

@ghost
Copy link
Author

ghost commented Apr 21, 2016

Yes I would unfortunately the runserver wont run ;) Thats my problem right now. I might try to set it up from scratch again to test if I changed something by accident since last time.

@evgenyfadeev
Copy link
Member

It does run, but gets stuck somewhere. If you insert a debugging statement you can step up to the point where it hangs.

@ghost
Copy link
Author

ghost commented Apr 21, 2016

Seemed to be some kind of permission problem. Now it is running and just returning the 3 usual warnings (Already opened issues for them).
But now the apache-deployment doesnt like me again...
It will go to Target WSGI script '/var/www/html/askbot-devel/django.wsgi' cannot be loaded as Python module
Might try debugging more now...

Edit: Okay fun fact: As soon as I try running the apache server and triggering the error the runserver command will stop working as well

Edit: The error seems to be in this line application = get_wsgi_application()

Edit: Tracked it to execute_from_command_line(sys.argv) in manage.py (Variable is set correctly)
If I try to put debug command into this function it wont return so something seems to be wrong with that..(python manage.py help gets stuck as well)

@evgenyfadeev
Copy link
Member

Look into log files, in those cases you just need to chown some files.

On Thu, Apr 21, 2016 at 7:19 PM, MarcJose notifications@github.com wrote:

Are the test-files still up-to-date because all 229 of them throw an error
when executing...


You are receiving this because you modified the open/close state.
Reply to this email directly or view it on GitHub
#572 (comment)

Askbot
Valparaiso, Chile
skype: evgeny-fadeev

@ghost
Copy link
Author

ghost commented Apr 22, 2016

Okay I got it to work with this skript I wrote. Feel free to use and update the documentation maybe ;)

#!/usr/bin/bash
#########################################
#                                       #
# Installscript for Askbot using        #
#    * Ubuntu 14.04 LTS                 #
#    * Apache 2.4.7                     #
#    * Postgresql 9.3                   #
# Author: Marc Jose                     #
#                                       #
#########################################

function validate {
        if ! $1 &> /dev/null
        then
                echo -e "\e[31mRed"$2"\e[0m"
                exit
        fi
} 

NUMBER=$(($RANDOM%63000+2001))
clear

### Get install directory
read -e -p "Please enter the directory of Askbot: "\
     -i "/var/www/html/askbot-devel" DIRECTORY
DIRECTORY=${DIRECTORY:-/var/www/html}

### Setting up requirements
echo -e "\e[32mInstalling requirements (Might take a while)\e[0m"
validate "apt-get -y update"\
         "Error updating package sources"
validate "apt-get -y install postfix apache2 apache2-mpm-worker postgresql git python python-pip libapache2-mod-wsgi apache2-dev python-dev libxml2-dev libcups2-dev libffi-dev libpq-dev build-essential gcc memcached python-memcache libmemcached-tools python-setuptools libjpeg-dev libapache2-mod-python"\
         "Error occured installing dependencies"

### Cloning repository
echo -e "\e[32mCloning repository (Please be patient)\e[0m"
validate "rm -rf $DIRECTORY"\
         "Error occured cleaning the given directory"
validate "mkdir -p $DIRECTORY"\
         "Error occured creating the new directory"
cd $DIRECTORY
if [ ! -d ~/gitcaches/askbot.reference ]; then
    validate "git clone --mirror https://github.com/ASKBOT/askbot-devel.git ~/gitcaches/askbot.reference"\
                  "Error creating cached repository ~/gitcaches/askbot.reference"
fi
git clone --reference ~/gitcaches/askbot.reference https://github.com/ASKBOT/askbot-devel.git . &> /dev/null
validate "git pull"\
         "Error pulling from repository"
read -e -p "Please enter the version of Askbot you want (master|0.9|0.8|0.7): "\
     -i "master" VERSION
VERSION=${VERSION:-master}
VERSION=${VERSION,,} 
if [[ $VERSION =~ ^(0.9)$ ]]
then
        validate "git checkout -b 0.9.x"\
                 "Error changing to version 0.9.x"
fi
if [[ $VERSION =~ ^(0.8)$ ]]
then
        validate "git checkout -b 0.8.x"\
                 "Error changing to version 0.8.x"
fi
if [[ $VERSION =~ ^(0.7)$ ]]
then
        validate "git checkout -b 0.7.x"\
                 "Error changing to version 0.7.x"
fi
chown -R www-data:www-data $DIRECTORY >/dev/null

### Creating virtualenv
echo -e "\e[32mCreating virtualenv (Might take a while as well)\e[0m"
validate "pip install --upgrade pip"\
         "Error upgrading pip"
validate "virtualenv env"\
         "Error creating virtualenv"
validate "env/bin/pip install --upgrade pip"\
         "Error updating pip inside virtualenv"
validate "env/bin/pip install pyopenssl ndg-httpsclient pyasn1 psycopg2 python-memcached django-configurations"\
         "Error installing python dependencies"
validate "env/bin/pip install -r askbot_requirements.txt"\
         "Error installing Askbot dependencies"
if [ -f askbot_requirements_dev.txt ]; then
    validate "env/bin/pip install -r askbot_requirements_dev.txt"\
                 "Error installing Askbot dependencies"
fi
validate "env/bin/pip uninstall -y markdown2"\
         "Error uninstalling markdown2"
validate "env/bin/pip install -e git+git://github.com/andryuha/python-markdown2.git#egg=markdown2"\
         "Error getting new markdown2 version"
validate "env/bin/pip uninstall -y html5lib"\
         "Error removing wrong html5lib"
validate "env/bin/pip install html5lib==0.90"\
         "Error installing proper html5lib==0.90"
validate "env/bin/python setup.py develop"\
         "Error in setup.py"
chown -R www-data:www-data $DIRECTORY >/dev/null

### Creating database
echo -e "\e[32mSetting up database\e[0m"
read -e -p "Please enter the new username for the Askbot-user: " -i "askbot" USERNAME
USERNAME=${USERNAME:-askbot}
read -e -p "Please enter the password for the Askbot-user: " -i "root" PASSWORD
PASSWORD=${PASSWORD:-abc}
read -e -p "Please enter the database name used by Askbot: " -i "askbot" DATABASENAME
DATABASENAME=${DATABASENAME:-askbot}
service postgresql restart >/dev/null
sudo -u postgres psql -c "DROP DATABASE IF EXISTS $DATABASENAME;" >/dev/null
sudo -u postgres psql -c "DROP USER IF EXISTS $USERNAME;" >/dev/null
sudo -u postgres psql -c "CREATE USER $USERNAME WITH PASSWORD '$PASSWORD';" >/dev/null
sudo -u postgres psql -c "ALTER USER $USERNAME CREATEDB;" >/dev/null
sudo -u postgres psql -c "CREATE DATABASE $DATABASENAME WITH OWNER=$USERNAME;" >/dev/null
service postgresql stop >/dev/null
cp /etc/postgresql/9.3/main/pg_hba.conf /etc/postgresql/9.3/main/pg_hba.conf.old >/dev/null
sed -i -e "1ilocal   $DATABASENAME      $USERNAME                            md5\n" /etc/postgresql/9.3/main/pg_hba.conf >/dev/null
chown -R postgres:postgres /etc/postgresql/9.3/main >/dev/null
service postgresql start >/dev/null

### Installing askbot
echo -e "\e[32mInstalling Askbot (Overwrite static files and dont create superuser when asked)\n\e[0m"
validate "askbot-setup -n . -e 1 -d $DATABASENAME -u $USERNAME -p $PASSWORD"\
         "Error running askbot-setup"
env/bin/python manage.py collectstatic
env/bin/python manage.py makemigrations
env/bin/python manage.py migrate
env/bin/python manage.py syncdb
env/bin/python manage.py migrate askbot
env/bin/python manage.py migrate django_authopenid
validate "mkdir -p $DIRECTORY/askbot/skins/style"\
         "Error occured creating the new style directory"
touch $DIRECTORY/askbot/skins/style/extra.css
chown -R www-data:www-data $DIRECTORY >/dev/null

### Configuring cache
echo -e "\e[32m\nPlease add the following line to your $DIRECTORY/settings.py:\n\e[0m"\
    "\e[96mCACHES = {\n"\
    "   'default': {\n"\
    "       'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',\n"\
    "       'LOCATION': '127.0.0.1:11211',\n"\
    "       'TIMEOUT': 18000,\n"\
    "       'KEY_PREFIX': 'askbot_"$NUMBER"_' #make this unique\n"\
    "   }\n"\
    "}\e[0m"
read -rsp $'Press any key to continue when done\n' -n1 key

### Deploying on apache
echo -e "\e[32mDeploying on apache\e[0m"
if [[ ! -d /var/python ]]; then
    mkdir -p /var/python >/dev/null
fi
if [[ ! -d /var/python/eggs ]]; then
    mkdir -p /var/python/eggs >/dev/null
fi
chown -R www-data:www-data /var/python >/dev/null
if [[ ! -d $DIRECTORY/socks ]]; then
    mkdir -p $DIRECTORY/socks >/dev/null
fi
chown -R www-data:www-data $DIRECTORY >/dev/null
cat <<EOF > /etc/apache2/sites-available/askbot.conf
WSGISocketPrefix $DIRECTORY/socks/
WSGIPythonHome $DIRECTORY/env/local
#WSGIRestrictStdout On
WSGIRestrictSignal Off
WSGIPythonOptimize 1
<VirtualHost *:80>
    ServerAdmin root@localhost.com
    ServerName askbot.localhost
    DocumentRoot "$DIRECTORY"
    Alias /m/ $DIRECTORY/static/
    Alias /upfiles/ $DIRECTORY/askbot/upfiles/
    <DirectoryMatch "$DIRECTORY/askbot/skins/([^/]+)/media">
        Order deny,allow
        Allow from all
    </DirectoryMatch>
    <Directory "$DIRECTORY/askbot/upfiles">
    Order deny,allow
        Allow from all
    </Directory>

    WSGIDaemonProcess askbot_"$NUMBER"_
    WSGIProcessGroup askbot_"$NUMBER"_
    WSGIScriptAlias / $DIRECTORY/django.wsgi

    ErrorLog \${APACHE_LOG_DIR}/askbot_error.log
    CustomLog \${APACHE_LOG_DIR}/askbot_access.log combined
</VirtualHost>
EOF
a2enmod wsgi >/dev/null
a2dismod python >/dev/null
a2ensite askbot >/dev/null

### Restart everything
echo -e "\e[32mRestarting\e[0m"
service postfix restart >/dev/null
service apache2 restart >/dev/null
service postgresql restart >/dev/null
service memcached restart >/dev/null
echo 'flush_all' | netcat localhost 11211 >/dev/null

echo
echo -e "\e[32mIf it doesn't work test with \"$DIRECTORY/env/bin/python $DIRECTORY/manage.py runserver `hostname -i`:8000\"\e[0m"

@ghost ghost closed this as completed Apr 22, 2016
This issue was closed.
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

1 participant