Skip to content

Commit

Permalink
Merge pull request #106 from urbancamo/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
urbancamo authored Aug 13, 2024
2 parents bc760d0 + bef1cd0 commit b2fb477
Show file tree
Hide file tree
Showing 2 changed files with 130 additions and 19 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

<groupId>uk.m0nom</groupId>
<artifactId>adif-processor</artifactId>
<version>1.4.11-SNAPSHOT</version>
<version>1.4.11</version>

<name>ADIF Processor</name>
<url>https://github.com/urbancamo/adif-processor</url>
Expand Down
147 changes: 129 additions & 18 deletions src/doc/VPS-install.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@
Install the following packages:

```bash
sudo apt-get install -y default-jre
sudo apt-get install -y maven
apt-get install -y default-jre
apt-get install -y maven
apt install -y postgresql-client-common
apt install -y postgresql-client
```
Install github cli: https://github.com/cli/cli/blob/trunk/docs/install_linux.md

## Installing Java

Expand All @@ -30,12 +33,6 @@ Configure docker to start on boot:
sudo systemctl enable docker.service
sudo systemctl enable containerd.service`
```
Configure a watchdog to start and monitor the adifproc application:

```bash
sudo systemctl enable watchdog.service
sudo systemctl start watchdog.service
```

## Installing the application

Expand All @@ -56,22 +53,52 @@ Clone the repository into `/home/adifproc/code`

## Environment Variables on command line

Create a run script `adifproc.sh` with the following contents:
Create a run script `adifproc.sh` wi#!/bin/bash

```bash
#!/bin/bash
WORKDIR=/home/adifproc/code/adifproc/adifweb
JAVA_OPTIONS=""
APP_OPTIONS=""

# Set the environment variables
export POSTGRES_DB=postgres
export POSTGRES_HOST=localhost
export POSTGRES_PASSWORD=mysecretpassword
export POSTGRES_USERNAME=adifproc
export QRZ_PASSWORD=<qrz_password>
export QRZ_USERNAME=<qrz_username>
export POSTGRES_PORT=5432
export POSTGRES_USERNAME=postgres
export QRZ_PASSWORD=mark4qrzasm0nom
export QRZ_USERNAME=M0NOM
export SPRING_PROFILES_ACTIVE=prod
export LOGDIR=/home/adifproc/logs

cd $WORKDIR
mvn -Pprod spring-boot:run >> $LOGDIR/adifproc.log 2>&1 &
```

Create a systemd unit file `adifproc.service` in `/etc/systemd/system` with the following contents:

# Run the application
java -jar /home/adifproc/code/target/adif-processor-1.4.11-SNAPSHOT-jar-with-dependencies.jar
```
[Unit]
Description=ADIF Processor
After=syslog.target network.target
[Service]
SuccessExitStatus=143
User=adifproc
Group=adifproc
Type=forking
ExecStart=/home/adifproc/adifproc.sh
ExecStop=/bin/kill -15 $MAINPID
[Install]
WantedBy=multi-user.target
```

Enable the service:

```bash
sudo systemctl daemon-reload
sudo systemctl enable adifproc.service
sudo systemctl start adifproc.service
```

## Postgres Docker Container
Expand All @@ -80,5 +107,89 @@ Instructions here: https://www.docker.com/blog/how-to-use-the-postgres-docker-of

```bash
docker pull postgres
docker run --name some-postgres -e POSTGRES_PASSWORD=mysecretpassword -d postgres
#docker run --name some-postgres -e POSTGRES_PASSWORD=mysecretpassword -d postgres
docker container create --name postgres-container -e POSTGRES_PASSWORD=<password> -p 5432:5432 postgres
docker update --restart=always postgres-container
```

Check the database connection:

```bash
psql -h localhost -U postgres -p 5432 -d
```

```sql
select * from log;
```

Open the port 5432 in the firewall:

```bash
sudo ufw allow from any to any port 5432 proto tcp
```

## SSL Certificate

Following these instructions: https://certbot.eff.org/instructions?ws=nginx&os=ubuntufocal
As superuser:

```bash
apt install nginx
apt install snapd
snap install --classic certbot
```

### Certbot Configuration

```bash
sudo certbot --nginx
```

### Nginx Configuration for reverse proxy to java application

```bash
sudo vim /etc/nginx/sites-available/default
```

Add the following contents:

```
server {
server_name www.adif.uk; # managed by Certbot
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/www.adif.uk/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/www.adif.uk/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
location / {
proxy_pass http://127.0.0.1:8080;
proxy_ssl_trusted_certificate /etc/nginx/ssl/unifi.cer;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
server {
if ($host = www.adif.uk) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80 ;
listen [::]:80 ;
server_name www.adif.uk;
return 404; # managed by Certbot
}
```

```bash
sudo service nginx restart
```

0 comments on commit b2fb477

Please sign in to comment.