Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 97 additions & 1 deletion docs/backendDeployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,50 @@ The backend is available at [http://it2810-28.idi.ntnu.no:3001/](http://it2810-2

The systemd service runs under a Linux user with access to the backend directory. The `User` and `WorkingDirectory` settings must match the configuration on the VM.

## Installing the systemd Service

The backend is managed by systemd to ensure that it continues running after SSH logout and starts automatically when the VM boots.

The service configuration is stored in `deploy/t28-backend.service`.

To install the service on the VM, first ensure that the backend dependencies are installed and that `backend/.env` is configured correctly.

The `User` and `WorkingDirectory` values in the service file must match the Linux user and project location on the VM.

Copy the service file to the systemd configuration directory:

```bash
sudo cp deploy/t28-backend.service /etc/systemd/system/
```

Reload systemd to register the service:

```bash
sudo systemctl daemon-reload
```

Enable the service to start automatically when the VM boots:

```bash
sudo systemctl enable t28-backend
```

Start the backend:

```bash
sudo systemctl start t28-backend
```

Verify that the service is running:

```bash
sudo systemctl status t28-backend
```

The service should show `active (running)`.

These installation steps are only required when setting up the service for the first time or when reinstalling its configuration.

## Starting and Restarting the Backend

To access the VM through SSH, a connection to the NTNU network or NTNU VPN is required.
Expand Down Expand Up @@ -91,6 +135,58 @@ sudo journalctl -u t28-backend -f

The backend is configured to start automatically when the VM reboots, so manual startup is normally unnecessary.

## Updating the Backend

When changes to the backend are merged into the main branch, the running backend on the VM must be updated to use the latest code.

Connect to the NTNU network or VPN and log in to the VM using SSH:

```bash
ssh <ntnu-username>@it2810-28.idi.ntnu.no
```

Navigate to the project directory on the VM:

```bash
cd ~/T28-Project-2
```

Make sure you are on the main branch and pull the latest changes:

```bash
git switch main
git pull origin main
```

Install or update backend dependencies:

```bash
cd backend
npm ci
```

Restart the systemd service to apply the updated backend code:

```bash
sudo systemctl restart t28-backend
```

Verify that the backend is running:

```bash
sudo systemctl status t28-backend
```

If the service fails to start, inspect the logs:

```bash
sudo journalctl -u t28-backend -n 50
```

The backend should now be running the updated code.

If the systemd service configuration has also changed, copy the updated service file to `/etc/systemd/system/` and run `sudo systemctl daemon-reload` before restarting the service.

## Database

PostgreSQL runs on the same VM as the backend.
Expand All @@ -111,7 +207,7 @@ The backend endpoint is configured through the `VITE_GRAPHQL_URL` environment va

This allows the frontend to communicate with different backend environments without changing the application code.

The configured backend endpoint is `http://it2810-28.idi.ntnu.no:3001/`.
The configured backend endpoint is [http://it2810-28.idi.ntnu.no:3001/](http://it2810-28.idi.ntnu.no:3001/).

Users interact with the application through the frontend and do not need direct SSH access to the VM or database.

Expand Down