Deployment

Deployment

Prerequisites

The website depends on the Sensor Server and Digital Hospital Server to be running. The details of running the digital hospital server can be found in the repository of the digital hospital server (opens in a new tab) (it is built by Yin-Chi)

Eco System File

We use pm2 to run the website and the sensor server in a production environment. The configuration file for pm2 is ecosystem.config.js. This spins up both services and runs them on different ports in detached mode.

const prodEnv = {
  WEB_PORT: 2222,
  SENSOR_PORT: 7777,
  DH_PORT: 5000, // Can not be configured on this file
};
 
const devEnv = {
  SENSOR_PORT: 8000,
  DH_PORT: 5000, // Can not be configured on this file
};
...

Note: The DH_PORT is not configurable in this file. It is set in the docker-compose.yml file in the digital hospital server (opens in a new tab) repository.

The devEnv is used to set the ports for the sensor server when running in development mode. The website uses these ports in dev. Note you can not change the port that the website runs in development using this file. To do that you have to go into the web directory and run

PORT=<PORT> pnpm start

Use this to change the ports of the servers if you are running them on different ports.

Pre Deployment

web

Build the website by cd into the web directory and run

/web/
pnpm build

servers/sensor

Ensure you have a virtual environment set up using the folder name venv, it is important that the folder is called venv as the ecosystem file looks for this folder. Then install the packages in the requirements.txt file.

/servers/sensor/
pip install -r requirements.txt

Running

Ensure you have pm2 installed globally

npm install -g pm2

Then run

pm2 start ecosystem.config.js

This will run the website and the sensor server in detached mode. You can view the logs of the services by running

pm2 logs

You can monitor the services by running

pm2 monit

Stopping

To stop the services run

pm2 stop ecosystem.config.js

Restarting

To restart the services run

pm2 restart ecosystem.config.js

Delete

To delete the services run

pm2 delete ecosystem.config.js