SiloCityLabs / lochnas

Docker configuration for all-in-one nas setup
https://lochnas.com
GNU General Public License v3.0
50 stars 3 forks source link

Check for certificate existing and valid #31

Closed ldrrp closed 2 years ago

ldrrp commented 2 years ago

Problem

Nginx container will fail to startup if the certificate is not valid or does not exist.

Solution

On startup we need to check for all required certificates and if they are not valid or existent we need to generate them. We report to the user to run the following command:

./server.bin -domain add domain.com
./server.bin -domain renew

See the following link for placement:

https://github.com/SiloCityLabs/docker-nas/blob/v3/server/models/app.go#L39

Previous code in bash:

nginx_cert_check () {
   # Allows us to use root domain if blank
   if [[ $1 = "" ]]; then 
      # Check for SSL cert
      if [ ! -d docker-data/letsencrypt/live/$GLOBAL_DOMAIN ]; then
         echo "Certificate does exist for $GLOBAL_DOMAIN"
         echo "Run ./domain-add.sh $GLOBAL_DOMAIN"
         exit 1
      fi
   else
      # Check for SSL cert
      if [ ! -d docker-data/letsencrypt/live/$1.$GLOBAL_DOMAIN ]; then
         echo "Certificate does exist for $1.$GLOBAL_DOMAIN"
         echo "Run ./domain-add.sh $1.$GLOBAL_DOMAIN"
         exit 1
      fi
   fi
}

Steps to Reproduce the Problem

  1. ./server.bin