Basic deployment

From Mayan EDMS Wiki
Jump to: navigation, search

Mayan EDMS should be deployed like any other Django project and preferably using virtualenv.

Being a Django and a Python project, familiarity with these technologies is recommended to better understand why Mayan EDMS does some of the things it does.

Using Ubuntu 18.04[edit]

  1. Install binary dependencies:
    sudo apt-get install g++ gcc ghostscript gnupg1 graphviz libfuse2 libjpeg-dev libmagic1 libpq-dev libpng-dev libreoffice libtiff-dev poppler-utils postgresql python-dev python-virtualenv redis-server sane-utils supervisor tesseract-ocr zlib1g-dev -y
  2. Create an user account for the installation:
    sudo adduser mayan --disabled-password --disabled-login --no-create-home --gecos ""
  3. Create the parent directory where the project will be deployed:
    sudo mkdir -p /opt
  4. Create the Python virtual environment for the installation:
    sudo virtualenv /opt/mayan-edms
  5. Make the mayan user the owner of the installation directory:
    sudo chown mayan:mayan /opt/mayan-edms -R
  6. Install Mayan EDMS:
    Professional Edition
    sudo -u mayan /opt/mayan-edms/bin/pip install --no-cache-dir -i https://<product key>@pypi.mayan-edms.com mayan-edms-pro --extra-index-url=https://pypi.org/simple
    Community Edition
    sudo -u mayan /opt/mayan-edms/bin/pip install --no-cache-dir mayan-edms
  7. Install the Python client for PostgreSQL and Redis:
    sudo -u mayan /opt/mayan-edms/bin/pip install --no-cache-dir psycopg2==2.7.3.2 redis==2.10.6
  8. Create the database for the installation:
    sudo -u postgres psql -c "CREATE USER mayan WITH password 'mayanuserpass';"
    sudo -u postgres createdb -O mayan mayan
  9. Initialize the project:
    sudo -u mayan MAYAN_DATABASE_ENGINE=django.db.backends.postgresql MAYAN_DATABASE_NAME=mayan MAYAN_DATABASE_PASSWORD=mayanuserpass MAYAN_DATABASE_USER=mayan MAYAN_DATABASE_HOST=127.0.0.1 MAYAN_MEDIA_ROOT=/opt/mayan-edms/media /opt/mayan-edms/bin/mayan-edms.py initialsetup
  10. Collect the static files:
    Professional Edition
    sudo -u mayan MAYAN_MEDIA_ROOT=/opt/mayan-edms/media /opt/mayan-edms/bin/mayan-edms.py collectstatic -i tests --noinput
    Community Edition
    sudo -u mayan MAYAN_MEDIA_ROOT=/opt/mayan-edms/media /opt/mayan-edms/bin/mayan-edms.py collectstatic --noinput
  11. Create the supervisor file at /etc/supervisor/conf.d/mayan.conf:
    [supervisord]
    environment=
        MAYAN_ALLOWED_HOSTS='["*"]',  # For versions < 3.1 use MAYAN_ALLOWED_HOSTS="*"
        MAYAN_CELERY_RESULT_BACKEND="redis://127.0.0.1:6379/0",
        MAYAN_BROKER_URL="redis://127.0.0.1:6379/0",
        PYTHONPATH=/opt/mayan-edms/lib/python2.7/site-packages:/opt/mayan-edms/data,
        MAYAN_MEDIA_ROOT=/opt/mayan-edms/media,
        MAYAN_DATABASE_ENGINE=django.db.backends.postgresql,
        MAYAN_DATABASE_HOST=127.0.0.1,
        MAYAN_DATABASE_NAME=mayan,
        MAYAN_DATABASE_PASSWORD=mayanuserpass,
        MAYAN_DATABASE_USER=mayan,
        MAYAN_DATABASE_CONN_MAX_AGE=60,
        DJANGO_SETTINGS_MODULE=mayan.settings.production
    
    [program:mayan-gunicorn]
    autorestart = true
    autostart = true
    command = /opt/mayan-edms/bin/gunicorn -w 2 mayan.wsgi --max-requests 500 --max-requests-jitter 50 --worker-class gevent --bind 0.0.0.0:8000 --timeout 120
    user = mayan
    
    [program:mayan-worker-fast]
    autorestart = true
    autostart = true
    command = nice -n 1 /opt/mayan-edms/bin/mayan-edms.py celery worker -Ofair -l ERROR -Q converter -n mayan-worker-fast.%%h --concurrency=1
    killasgroup = true
    numprocs = 1
    priority = 998
    startsecs = 10
    stopwaitsecs = 1
    user = mayan
    
    [program:mayan-worker-medium]
    autorestart = true
    autostart = true
    command = nice -n 18 /opt/mayan-edms/bin/mayan-edms.py celery worker -Ofair -l ERROR -Q checkouts_periodic,documents_periodic,indexing,metadata,sources,sources_periodic,uploads,documents -n mayan-worker-medium.%%h --concurrency=1
    killasgroup = true
    numprocs = 1
    priority = 998
    startsecs = 10
    stopwaitsecs = 1
    user = mayan
    
    [program:mayan-worker-slow]
    autorestart = true
    autostart = true
    command = nice -n 19 /opt/mayan-edms/bin/mayan-edms.py celery worker -Ofair -l ERROR -Q mailing,tools,statistics,parsing,ocr -n mayan-worker-slow.%%h --concurrency=1
    killasgroup = true
    numprocs = 1
    priority = 998
    startsecs = 10
    stopwaitsecs = 1
    user = mayan
    
    [program:mayan-celery-beat]
    autorestart = true
    autostart = true
    command = nice -n 1 /opt/mayan-edms/bin/mayan-edms.py celery beat --pidfile= -l ERROR
    killasgroup = true
    numprocs = 1
    priority = 998
    startsecs = 10
    stopwaitsecs = 1
    user = mayan
    • Be very careful that:
      • There are exactly four spaces before each line of the environment variables at the top of the config
      • There is a comma after each environment variable except the last
      • Each line of the [program] blocks contains exactly one key = value pair (be sure there aren't any surprise carriage returns/newlines)
  12. Configure Redis to discard data when it runs out of memory:
    echo "maxmemory-policy allkeys-lru" >> /etc/redis/redis.conf
    echo "save \"\"" >> /etc/redis/redis.conf
    echo "databases 1" >> /etc/redis/redis.conf
    systemctl restart redis
  13. Enable and restart the services[1]:
    systemctl enable supervisor
    systemctl restart supervisor

Using Ubuntu 16.04[edit]

Install gnupg instead of gnupg1. Add the extra environment variable to the supervisor configuration file:

MAYAN_SIGNATURES_GPG_PATH=/usr/bin/gpg

Troubleshooting[edit]

Ask Supervisor to log verbosely[edit]

Set loglevel=debug in /etc/supervisord.conf.

Check the Supervisord log[edit]

Navigate to /var/log and take a look at supervisord.log

Check the Supervisor configuration file[edit]

  • The environment section must be formatted as shown. Each line starts with 4 spaces. Each line, except the last one ends with comma.
  • If changes are made to the supervisor file the following commands must be execute to force and update:
    supervisorctl reread
    supervisorctl update