Skip to content
This repository has been archived by the owner on May 4, 2024. It is now read-only.

Configuring DTU server

marcosantiagomuro edited this page Oct 12, 2023 · 6 revisions

Open VPN

Open OpenVPN and tunnel TunnelBlick to connect to DTU Compute

Access VM

To access our VM using a ssh connection open terminal/command prompt and type

ssh s123456@se2-d.compute.dtu.dk

then access using your DTU password

Or if you have set up the ssh key just type

ssh compute.dtu and you will connect automatically

Configuring the Server

This is required in order to install Node.js (version 18, NODE_MAJOR=18) and create the correct directories.
This has already been configured and there is no need to repeat.

curl -sL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt-get update
sudo apt-get install -y ca-certificates curl gnupg
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
NODE_MAJOR=18                                 //to set NodeJS version 18
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list
sudo apt-get update
sudo apt-get install nodejs -y
node -v                                       //to check the installed version

Configuring git

Now we need to clone our Repo to the server.
This has already been configured.

git clone https://github.com/DTU-SE-Group-D/LiRA-Viz.git

Then access to the correct folder using ls and cd commands.

Then type git status to see in which branch we are located.

If needed git checkout dev to checkout to the dev-branch

Starting the web app

Then by using the npm command (it is a software registry installed with Node.js) we can download the pm2 manager (it is an advanced process manager for NodeJS applications that allows you quickly start, control, or stop your node processes). Type:

sudo npm i -g pm2

and manage all the dependencies needed for our project. With pm2 now we can monitor the processes on our machine and their status.
Some useful prompts are:

  • pm2 --help

to see all the options

  • pm2 list

to see the status of the running processes

  • pm2 monit

to see the real-time monitoring of the processes

  • pm2 start [app.js]

to start the app in main file [app.js]

  • pm2 stop [#pid]

to stop the process with pid number [#pid]

  • pm2 restart [#pid]

to restart the process with pid number [#pid]

  • pm2 delete [#pid]

to delete the process with pid number [#pid]


Frontend

To serve the frontend app, navigate into the frontend folder and type:

REACT_APP_BACKEND_URL_PROD=http://se2-d.compute.dtu.dk:3002 NODE_ENV=production pm2 serve build/ 3000 --spa -n frontend

where:

  • the first two parameters are env vars
  • pm2 command to start and manage Node.js applications using PM2
  • serve command within PM2 used to serve static files as a web server
  • build/ the path folder
  • 3000 the port number
  • --spa meaning it is a single page application
  • -n frontend defining the app name

And build the frontend app: npm run build

Backend

To start the backend, navigate into the backend folder and type

pm2 start dist/main.js 3002 -n backend

where:

  • pm2 command to start and manage Node.js applications using PM2
  • start command within PM2 used to start a Node.js application
  • dist/main.js path to the main JavaScript file of the Node.js application that PM2 will start
  • 3002 the port number
  • -n backend defining the app name

Now the web app is up and running. :)

Upload new dev version on the server

Once the app is already running, to update the new version do the following:

Navigate into the Lira-Viz folder.

git status to see in which branch you are (should be dev). if not git checkout dev

Then: git fetch

And to pull the new commits: git pull

Go to the frontend folder and run:

npm install if there are new dependencies to be installed and then:

REACT_APP_BACKEND_URL_PROD=http://se2-d.compute.dtu.dk:3002 NODE_ENV=production npm run build

Go to the backend folder and run

npm install if there are new dependencies to be installed and then:

NODE_ENV=production npm run build

Then go back to backend and frontend folder and run:

npm run start

(if there are already processes running on those ports just do pm2