Skip to content

Install system services

James Andrews edited this page Feb 14, 2024 · 9 revisions

You need to have completed Install first

This describes how to install VariantGrid on a server using services, a way for Unix to run programs all the time (ie not by a user logged in on a shell)

Settings

In your settings files, be sure to set DEBUG=False. See Django docs why to never deploy a site into production with DEBUG turned on

NGINX

You will need to modify /etc/nginx/nginx.conf to work as a proxy.

There are 2 examples in the variantgrid/config dir. The one in the base directory runs on port 80 and handles static files. The one in variantgrid/config/variantgrid.com/nginx.conf uses a SSL certificate, and redirects http -> https.

cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.ORIG
cp ${VARIANTGRID_DIR}/config/nginx.conf /etc/nginx/ # Or use variantgrid one for SSL example

Edit the newly copied file, you need to change at least 3 lines: the IP address, and the path to the static files eg:

server {
    listen   80;
    server_name 130.56.244.155;   # <---------------------------------- ** Change IP **
    add_header Access-Control-Allow-Origin 130.56.244.155; # <--------- ** Change IP **

    location /static/{
    autoindex on;
    root /opt/variantgrid/variantgrid/sitestatic; # <------------------ ** Change Path **
    }
}

If you're on a VM with a small root partition, change where NGINX puts temp upload files (remember to assign this write permission to the nginx user - which is probably "www-data"):

client_body_temp_path /mnt/nginx_upload_temp;

For the changes to take effect you'll need to have nginx reload the config file (simply restarting nginx will not have the same effect).

sudo nginx -s reload

Services

Create the dir for services to log to:

sudo mkdir /var/log/variantgrid
sudo chown variantgrid /var/log/variantgrid

There are two types of services on Linux, Upstart and SystemD.

# Check which one you're using via:
ps -p1 | grep systemd && echo systemd || echo upstart

Service /etc/variantgrid .env files

Gunicorn and Celery rely on .env files to set various things. Copy the defaults into /etc/variantgrid:

cd ${VARIANTGRID_DIR} # Wherever this is
sudo cp -r config/celery/ config/gunicorn /etc/variantgrid/

If you want to install and use a virtual environment, this is where you change the paths of celery/gunicorn so that they run the version you want. Eg I setup the virtualenv in the VG "env" directory and hardcoded the paths to that:

# grep GUNICORN_BIN gunicorn/gunicorn.env
GUNICORN_BIN="/opt/variantgrid/env/bin/gunicorn"

# grep CELERY_BIN celery/*.env
celery/celeryd_analysis_workers.env:CELERY_BIN="/opt/variantgrid/env/bin/celery"
celery/celeryd_annotation_workers.env:CELERY_BIN="/opt/variantgrid/env/bin/celery"
celery/celeryd_beat.env:CELERY_BIN="/opt/variantgrid/env/bin/celery"
celery/celeryd_beat_opt.env:CELERY_BIN="/opt/variantgrid/env/bin/celery"
celery/celeryd_db_workers.env:CELERY_BIN="/opt/variantgrid/env/bin/celery"
celery/celeryd_scheduling_single_worker.env:CELERY_BIN="/opt/variantgrid/env/bin/celery"
celery/celeryd_variant_id_single_worker.env:CELERY_BIN="/opt/variantgrid/env/bin/celery"
celery/celeryd_web_workers.env:CELERY_BIN="/opt/variantgrid/env/bin/celery"

SystemD (Ubuntu >=15)

We've included service files for /opt and /mnt - to install them

cd config/systemd
# Now either go into 'mnt' or 'opt'
cp *.service /lib/systemd/system
for i in *.service;
    do systemctl enable $(basename ${i});
done;

# Then start them
./scripts/start_services.sh

If you have to change them once they've been installed, make sure to

sudo systemctl daemon-reload
./scripts/restart_services.sh

for the changes to be picked up

If you installed VG somewhere else you'll need to edit the service files in config/systemd/*.service and change so that

WorkingDirectory=/mnt/variantgrid # Needs to match ${VG_INSTALL_DIR}

Deploy

To create the static folders desired by nginx, you'll need to run Django's various collect statics. This can be achieved with scripts/upgrade.sh (as the variantgrid user)

Mail Server

You can create users using the admin tool, or allow people to create their own accounts via the registration process, which requires an email server.

Instructions to Install PostFix mail server (requires a domain name)

Data Storage

A VM root partition is usually quite small, so we need to move data storage onto mounted disks

Clone this wiki locally