Skip to content

Instantly share code, notes, and snippets.

@deatharse
Last active May 16, 2018 07:16
Show Gist options
  • Save deatharse/25ecb68e692fdd615bc9 to your computer and use it in GitHub Desktop.
Save deatharse/25ecb68e692fdd615bc9 to your computer and use it in GitHub Desktop.
Please bear in mind this is for a Debian environment - specifically Jessie so directive in apache
vhost will differ if you're not using apache-2.4.
I followed the instructions for the development environment (N.B. DO NOT use `test` as the account
for `createsuperuser` as this will break `loaddate test_data`):
sudo mkdir /usr/share/readthedocs
sudo chown your_username readthedocs
sudo apt-get install build-essential python-dev libxml2-dev libxslt1-dev zlib1g-dev virtualenv git
cd /usr/share/
virtualenv readthedocs
cd readthedocs
source bin/activate
pip install --upgrade pip
mkdir checkouts
cd checkouts
git clone https://github.com/rtfd/readthedocs.org.git
cd readthedocs.org
pip install -r requirements.txt
./manage.py migrate
./manage.py createsuperuser
./manage.py loaddata test_data
./manage.py runserver
which all worked so I stopped the dev server `[CTRL]+C` then I installed missing dependencie (some
of which may not be needed):
sudo apt-get install libpq-dev redis-server
cd /usr/share/readthedocs/
source bin/activate
pip install psycopg2 redis django-redis-cache django-redis-sessions
pip install --upgrade hiredis
pip install pysolr
cd checkouts/readthedocs.org/
pip install -U -r requirements/deploy.txt
pip install requests==2.6.0
verified redis
redis-cli ping
which returns `PONG`
I then migrated the DB to Postgresql:
./manage.py dumpdata > database.json
sudo -u postgres createdb docs
sudo -u postgres createuser -P rtd_user
sudo -u postgres psql
GRANT ALL PRIVILEGES ON DATABASE docs to rtd_user;
and made sure i had the line:
host all all 127.0.0.1/32 md5
in the pg_hba.conf file to allow password logins (and of course restarted postgres)
I then edited the `manage.py` file to change the line:
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "readthedocs.settings.sqlite")
to
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "readthedocs.settings.__init__")
then symlinked the file to the postgres config:
cd /usr/share/readthedocs/checkouts/readthedocs.org/readthedocs/settings/
ln -s postgres.py __init__.py
Update the postgres.py with the correct credentials for the username / password / host and change
the line:
FILE_SYNCER = 'privacy.backends.syncers.DoubleRemotePuller'
to
FILE_SYNCER = 'readthedocs.privacy.backends.syncers.DoubleRemotePuller'
then feed the dumped db into postgres:
cd ../../
./manage.py syncdb
./manage.py sqlflush
./manage.py loaddata database.json
Apache setup
sudo apt-get install libapache2-mod-wsgi
this should be enabled automatically, it its not enable it:
sudo a2enmod wsgi
setup a vhost (`/etc/apache2/sites-available/docs.my-domain.com.conf`)
<VirtualHost *:80>
ServerName docs.my-domain.com
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\"" common
LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
CustomLog /usr/share/readthedocs/checkouts/readthedocs.org/logs/access_log combined
ErrorLog /usr/share/readthedocs/checkouts/readthedocs.org/logs/error_log
Alias /static/admin /usr/share/readthedocs/lib/python2.7/site-packages/django/contrib/admin/static/admin
Alias /static /usr/share/readthedocs/checkouts/readthedocs.org/readthedocs/static
Alias /media /usr/share/readthedocs/checkouts/readthedocs.org/media
WSGIPassAuthorization On
WSGIScriptAlias / /usr/share/readthedocs/checkouts/readthedocs.org/readthedocs/wsgi.py
WSGIProcessGroup www-data
WSGIDaemonProcess www-data \
python-path=/usr/share/readthedocs/checkouts/readthedocs.org/readthedocs/:/usr/share/readthedocs/lib/python2.7/site-packages/:/usr/share/readthedocs/:/usr/share/readthedocs/checkouts/readthedocs.org/:/usr/share/readthedocs/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/:/usr/share/readthedocs/checkouts/readthedocs.org/readthedocs/settings/
<Directory /usr/share/readthedocs/checkouts/readthedocs.org/readthedocs/>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
<Directory /usr/share/readthedocs/lib/python2.7/site-packages/django/contrib/admin/static/admin/>
Require all granted
</Directory>
<Directory /usr/share/readthedocs/checkouts/readthedocs.org/readthedocs/static/>
Require all granted
</Directory>
<Directory /usr/share/readthedocs/checkouts/readthedocs.org/media/>
Require all granted
</Directory>
</VirtualHost>
fix the permissions for apache:
sudo chown -R www-data: /usr/share/readthedocs
and create cache dir in apache home directory:
sudo mkdir /var/www/.cache/
sudo chown www-data: /var/www/.cache
enable the vhost and restart:
sudo a2ensite docs.my-domain.com.conf
sudo service apache2 graceful
ElasticSearch
sudo apt-get install icedtea-7-jre-jamvm
wget -qO - https://packages.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
echo "deb http://packages.elastic.co/elasticsearch/1.7/debian stable main" | sudo tee -a /etc/apt/sources.list.d/elasticsearch-1.7.list
sudo apt-get update && sudo apt-get install elasticsearch
edit `/etc/elasticsearch/elasticsearch.yml` and add the lines:
network.bind_host: localhost
network.host: localhost
and restart ES:
sudo service elasticsearch restart
add icu as specified:
sudo /usr/share/elasticsearch/bin/plugin -install elasticsearch/elasticsearch-analysis-icu/2.3.0
and restart apache
postgres.py file
import os
from .base import * # noqa
TIME_ZONE = 'Europe/London'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'docs',
'USER': 'rtd_user', # Not used with sqlite3.
'PASSWORD': 'password',
'HOST': '127.0.0.1',
'PORT': '',
}
}
REDIS = {
'host': 'localhost',
'port': 6379,
'db': 0,
}
DEBUG = True
TEMPLATE_DEBUG = False
BROKER_URL = 'redis://localhost:6379/0'
CELERY_ALWAYS_EAGER = True
CELERY_RESULT_BACKEND = 'redis://localhost:6379/0'
MEDIA_URL = 'http://docs.my-domain.com/media/'
STATIC_URL = 'http://docs.my-domain.com/static/'
ADMIN_MEDIA_PREFIX = MEDIA_URL + 'admin/'
SESSION_COOKIE_DOMAIN = None
SESSION_COOKIE_HTTPONLY = False
SESSION_ENGINE = "django.contrib.sessions.backends.cached_db"
HAYSTACK_CONNECTIONS = {
'default': {
# Is pointless to try any other engine (Solr/Whoosh) as ES is that engrained in the RTD code
'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine',
'URL': 'http://localhost:9200/',
'INDEX_NAME': 'readthedocs',
}
}
CACHES = {
'default': {
'BACKEND': 'redis_cache.RedisCache',
'LOCATION': 'localhost:6379',
'PREFIX': 'docs',
'OPTIONS': {
'DB': 1,
'PARSER_CLASS': 'redis.connection.HiredisParser'
},
},
}
# Elasticsearch settings.
ES_HOSTS = ['localhost:9200']
ES_DEFAULT_NUM_REPLICAS = 1
ES_DEFAULT_NUM_SHARDS = 5
#WEBSOCKET_HOST = 'websocket.readthedocs.org:8088'
ALLOW_PRIVATE_REPOS = True
SLUMBER_USERNAME = 'test'
SLUMBER_PASSWORD = 'test' # not sure about these settings
SLUMBER_API_HOST = 'http://docs.my-domain.com'
# GROK_API_HOST = 'http://localhost:5555'
PRODUCTION_DOMAIN = 'docs.my-domain.com'
USE_SUBDOMAIN = False
NGINX_X_ACCEL_REDIRECT = True
#SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
# Lock builds for 10 minutes
REPO_LOCK_SECONDS = 300
#FILE_SYNCER = 'privacy.backends.syncers.DoubleRemotePuller'
#FILE_SYNCER = 'readthedocs.privacy.backends.syncers.DoubleRemotePuller'
FILE_SYNCER = 'readthedocs.privacy.backends.syncers.LocalSyncer'
# set GitHub scope
SOCIALACCOUNT_PROVIDERS = {
'github': {'SCOPE': ['user:email', 'read:org', 'admin:repo_hook', 'repo:status']}
}
# allauth settings
ACCOUNT_DEFAULT_HTTP_PROTOCOL = 'http'
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
# Host for sending e-mail.
EMAIL_HOST = 'SMTP.server'
# Port for sending e-mail.
EMAIL_PORT = 587
# Optional SMTP authentication information for EMAIL_HOST.
EMAIL_HOST_USER = 'smtp_user'
EMAIL_HOST_PASSWORD = 'smtp_password'
EMAIL_USE_TLS = True
if not os.environ.get('DJANGO_SETTINGS_SKIP_LOCAL', False):
try:
from local_settings import * # noqa
except ImportError:
pass
@NikitaEgorov
Copy link

NikitaEgorov commented Dec 14, 2016

Thanks!!!
But i have issues with ES WARNING [elasticsearch:82] POST /_bulk [status:400 request:0.006s]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment