Skip to content

Setting up the server

Maxime Kabel edited this page Dec 4, 2021 · 18 revisions

Instructions to prepare website

1. Please refer to section 1 of the local-dev wiki

2. Install and enable server-specific apps

sudo apt-get install redis-server

Change 'supervised no' to 'supervised systemd' in /etc/redis/redis.conf.

sudo systemctl enable --now redis.service 

Make sure the celery user is able to access the directories it needs

sudo mkdir /var/run/celery
sudo mkdir /var/log/celery
sudo chown cosmos:cosmos /var/run/celery
sudo chown cosmos:cosmos /var/log/celery

then copy the systemd file from the server repo and enable the service

cp celery.service /etc/systemd/system/celery.service
cp celeryd /etc/conf.d/celery
sudo systemctl enable --now celery.service

3. Finalize website

Copy the secrets file from server/secrets.json to /etc/secrets.json, and fill in the credentials. Make sure they are kept secret and are different from the default credentials in the file.

Create and apply migrations to the database, this sets up the initial database structure.

python manage.py migrate

Create an admin user

python manage.py createsuperuser

Collect all the static files for nginx

python manage.py collectstatic

Check if setting up the database worked

python manage.py runserver 0.0.0.0:8000

Instructions to make website accessible

4. Copy all the server specific files to their respective directories

Copy the systemd service and socket and reload the services

sudo cp server/gunicorn.* /etc/systemd/system/
sudo systemctl daemon-reload

Copy sudoers file to give the automatic deployment user permission to run the service

sudo cp server/deployerperm /etc/sudoers.d/

Copy and symlink the Nginx config file and then enable and start it

sudo cp server/nginx-cosmosweb /etc/nginx/sites-available/
sudo ln -s /etc/nginx/sites-available/nginx-cosmosweb /etc/nginx/sites-enabled
sudo systemctl --now enable nginx

Copy the shell script that is used for automated git deployment

cp server/update.sh ..

Finally, enable and start the server

sudo systemctl --now enable gunicorn.socket

Tips for Max

don't forget to reload nginx AND gunicorn

Clone this wiki locally