Overview

Artifact ID: 29b675f628e8aaaf77879485ea2d3fbe0dab570c48576abd4be0a693d0920ef9
Page Name:covidphy.eu
Date: 2021-07-16 11:34:14
Original User: xbello
Mimetype:text/x-markdown
Parent: 62b3b5aed6caece1c428ca71bfaa37ff568bb84ec0d5cd0bf87d14dfb17b06a5 (diff)
Next a6147f65f98d6d8da70e2563465aa0ee1200a52757dc42747e8696a7e399b964
Content

Install Nim

You'll need a C compiler (gcc). The recommended way to install Nim is choosenim. On Linux:

  $ curl https://nim-lang.org/choosenim/init.sh -sSf | sh

Follow the post-install instructions, and add the nim binary to your PATH.

Get the package

This package is SCM'ed with Fossil. Thus:

  • Members of the team: ask the mantainer ([email protected]) for the Fossil file, and follow his instructions if you're not familiar with Fossil.

  • People that want to install a local server: ask the mantainer for the site tarball. This tarball can be uncompressed in a directory and keep going.

Build the package

Build the package with Nimble (included with Nim). The tool takes care of dependencies:

  $ nimble build covidphy
  $ nimble jvs

Add a .env file

The covidphy binary looks for a file .env in the same dir. Create this file readable only by owner to configure your http server:

  $ touch .env
  $ chmod 600 .env

Edit the file to include the following adjustable settings:

  debug=false
  bindAddr=0.0.0.0
  port=8080
  appName=covidphy.eu
  staticDir=/static
  alignDir=/aligns
  logLevel=lvlDebug
  mailFrom="[email protected]"
  mailTo="[email protected]"
  mail=YourMailPassword
  secretKey=A_Long_Random_Chain_Of_Chars
  db=db.sqlite3
  entrezKey=The_Entrez_Key

Setup the DB

The DB should be created empty by running Jester the first time. But tables are not (by now). Build the tables with the following script:

  $ nim r src/migrate.nim all

Load the needed fixtures from src/fixtures/name.sql:

  $ cat src/fixtures/name.sql | sqlite3 db.sqlite3  # One fixture

  $ for F in src/fixtures/*sql; do cat $F | sqlite3 db.sqlite3; done  #* All at once

The variant frequency data can be loaded with a script:

  $ nim r src/helpers/updateVariantsServer src/fixtures/variant.sql

Make a log dir

A log dir is not strictly necessary, but if you deploy the server you might want to collect the logs together. Fossil is instructed to ignore the path "log/*.log".

Running the server

The server is ready to run. Launch it with:

  $ ./covidphy

It won't say anything (maybe Serving at 0.0.0.0:8080). You can test it worked by curling localhost at the port configured in the .env file above. Open another terminal and type:

  $ curl 127.0.0.1:8080
  <!DOCTYPE html>
  ...
  </html>

Configure nginx to listen

It's a bad practice to expose servers directly to the internet. Use a proxy like Nginx to transfer the requests to the application. This goes well beyond the aim of this document, but it can be resumed as:

User Nginx CovidPhy Dynamic Static
O1: oval "User" fit;
B1: box at 2cm right of O1 "Nginx" fit;
B2: box at 2cm right of B1 "CovidPhy" fit;
O2: oval at 2cm right of B2 "Dynamic" fit;
O3: oval with .c at 1cm south of O2.s "Static" fit;

arrow from O1.e to B1.w;
arrow from B1.w to O1.e;
arrow from B1.e to B2.w;
arrow from B2.w to B1.e;
arrow from B2.e to O2.w;
arrow from O2.w to B2.e;

arrow from B1.s down 1cm then to O3.w;
arrow from O3.w left until even with B1 then to B1.s;
  • Create a server directive that points / to a proxy_pass:

    server {
      location / {
        proxy_pass http://covidphy/;
      }
    }
    

Read some docs to set the parameters proxy_set_header, proxy_redirect and others needed.

  • Create an upstream pointing to the server compiled above. Depending on .env:

    upstream covidphy {
      server 127.0.0.1:8080;
    }
    
  • Fix the static dir to be server directly by Nginx instead of the server:

    location /static/ {
      alias /path/of/your/static/;
    }
    

This is not complicated, but it's also not for beginners. Look for help. It can be done in minutes if you know what your are doing, but takes days if you don't.

Some other gotchas to nginx configuration:

  • Run nginx as proper user.

  • Ensure /var/lib/nginx permissions are OK:

    # chown -R userabove:nginx /var/lib/nginx
    

Configure supervisor to do its thing

Note: this can be done also with systemd.

Use supervisor to launch the command. The config .ini file include at least the following entries: directory, command, user and stdout_logfile.

  [program:covidphy]
  directory = /abs/path/to/covidphy.eu/
  command = /abs/path/to/covidphy.eu/covidphy ; Command to start app
  user = genvip ; User to run as
  stdout_logfile = /abs/path/to/covidphy.eu/log/supervisor.log ; Where to write log messages
  redirect_stderr = true ; Save stderr in the same log
  environment=LANG=en_US.UTF-8,LC_ALL=en_US.UTF-8 ; Set UTF-8 as default encoding

Then reload the daemon:

  # supervisorctl reread
  covidphy: available
  # supervisorctl avail
  covidphy                  avail     auto      999:999
  # supervisorctl update

Manteinance

From the deployment dir:

  $ fossil up
  $ nim c -d:danger -o:covidphy src/covidphy
  $ nimble jvs

  ### If needed ###
  $ nim r src/migrate XXXX
  $ cat src/fixtures/name.sql |sqlite3 db.sqlite3

  ### The variant frequency data can only be loaded with a script:
  $ nim r src/helpers/updateVariantServer.nim src/fixtures/variant.sql

  ### Restart ###
  $ sudo supervisorctl restart covidphy