Skip to main content

Automate Letsencrypt Certs renewal for Docker with Multisites Wordpress

 Assalamualaikum, 


Well to understand this post you will need to read first how i set multiple Wordpress sites in Docker containers~

 

LetsEncrypt Certification Auto Renewal

 


Ok the trick that i did to automate the renewal process is 


1. Create 2 separate docker file

I'm not able to create a single line letsencrypt command that can run cert renewal for two different domains, thus this is a hack way. If you have any suggestion let me know please!

 

ls -l wordpress/docker-compose*
-rw-rw-r-- 1 cxx cxx 2421 Jun  7 11:32 wordpress/docker-compose-4nutz.yml
-rw-rw-r-- 1 cxx cxx 2442 Jun  7 11:28 wordpress/docker-compose.yml

For file docker-compose-4nutz.yml small change made on the certbot definition, where i commented out the volumes for another website / kedaibiskut. Highlighted you can just totally remove it. Ensure the command is correct only for one domain and one path.

certbot:
    depends_on:
      - webserver
    image: certbot/certbot
    container_name: certbot
    volumes:
      - certbot-etc:/etc/letsencrypt
      - ./data/html:/var/www/html
        #    - ./data/kedaibiskut:/var/www/kedaibiskut

    command: certonly --webroot -w /var/www/html --email 4nutzdeli@gmail.com --agree-tos --no-eff-email --force-renewal -d 4nutz.tk -d www.4nutz.tk

 

Ensure the certbot definition for another site (kedai biskut) is correct too~

2. Add cron job to run the renewal cert every 3 months and restart webserver container too~

0 0 1 */3 * /usr/local/bin/docker-compose -f /home/cxx/wordpress/docker-compose.yml --verbose up  --force-recreate --no-deps certbot > /home/cxx/wordpress/lets_encrypt_renewal.log 2>&1 && /usr/local/bin/docker-compose -f /home/cxx/wordpress/docker-compose-4nutz.yml --verbose up  --force-recreate --no-deps certbot >> /home/cxx/wordpress/lets_encrypt_renewal.log 2>&1 && /usr/local/bin/docker-compose -f /home/cxx/wordpress/docker-compose.yml --verbose up -d  --force-recreate --no-deps webserver >> /home/cxx/wordpress/lets_encrypt_renewal.log 2>&1


What does the command do? 

a)  0 0 1 */3 *

run  At 00:00 on day-of-month 1 in every 3rd month.” 

b) /usr/local/bin/docker-compose -f /home/cxx/wordpress/docker-compose.yml --verbose up  --force-recreate --no-deps certbot > /home/cxx/wordpress/lets_encrypt_renewal.log 2>&1

 run docker-compose that renew cert for kedaibiskut domain and record the standard error and output to the specified path. eg (/home/cxx/wordpress/lets_encrypt_renewal.log) , the first, i dumped to new file. next command append the output the the file. This log is for troubleshooting process. Each command we run will have output recorded to the same file. 

c) &&

run the next command if the first one before "&&" is successful

 

d) /usr/local/bin/docker-compose -f /home/cxx/wordpress/docker-compose-4nutz.yml --verbose up  --force-recreate --no-deps certbot >> /home/cxx/wordpress/lets_encrypt_renewal.log 2>&1

run docker compose to renew cert for 4nutz domain. similar to b)

notice that for b) and d) i use the full docker-compose bin path. else the cron job will have problem locating docker-compose probably due to the environment path.


e) /usr/local/bin/docker-compose -f /home/cxx/wordpress/docker-compose.yml --verbose up -d  --force-recreate --no-deps webserver >> /home/cxx/wordpress/lets_encrypt_renewal.log 2>&1

 restart the webserver container faster to reload the new cert omg~ let me know if this is not good practice. our website is not so critical restarting it should be fine lol!

 

Thats all! finally the pending task done. ! i always need some mood to do website maintenance lol! tqtq

 



 
 

Comments

Popular posts from this blog

Tutorial on Min3D framework using Android Studio

Salam peeps, UPDATES***, the model on the old link is no longer working. so i have create a github repo, where i put the source code in a project, you guys can try to clone in and run on your android studio device emulator or directly on your phone, Ive replaced the model with a cube. https://github.com/aliaramli/Min3DTutorial Previously i ve posted tutorial on min3D using eclipse IDE, i believe most of us has moved to Android Studio IDE in developing android apps? As previous tutorial shows a lot of support from readers and among hot post in my blog, i ve decided to post the same tutorial but this time using Android Studio. For those who are familiar with Eclipse/Android Studio migration they might not have problem in running this tutorial . For more detail explanation on min3D please visit this website page Ok lets get started. Step One Create a new android project in android studio. you may name it as what you like, below are how i defined my project settings. ...

Tutorial on min3d framework

Salam all. This time I want to share a bit, how I tried out the mid3d framework for the first time. Acknowledge that I am new to android development.   I just follow the tutorial on Mat-d website but there are certain things that I don’t understand how they actually work. Thus I want to share what I did step by step to make this example work. For explanations on coding/steps or errors please visit Mat-d website here J you ll understand more …. mat-d original tutorial load a 3d obl model with min3d for android Step one . Download min3d into your eclipse . Select File>Import>SVN>Checkout projects from SVN Next. Choose radio button : Create a new repository location Next. Enter the svn location http://min3d.googlecode.com/svn/trunk the thing that we want to check out from the svn is the min3d framework code. Step two. Download obj file  www.3dvia.com …you need to register first..it has free acc version.. and download the...

Some weird keyboard ISSUE + Ubuntu

 Recently my ubuntu OS  drives me crazy until i keep upgrading to the latest version. Even had issue where post upgrade the system crashed. lol and i reformat back using bootable USB Drive. You can watch how i did it! recorded and uploaded to my YouTube channel . Now im at the Ubuntu 22.04.1 LTS version! Everytime i typed on my keyboard. the numbering goes crazy, the symbols goes crazy..the mouse goes crazy. Until one time i just tried to change the Keyboard setting to English (UK) from English (US)   and it works.    sometimes it works temporarily.  sometimes it work for long hours. still monitoring. but this is my current workaround.  really an old laptop.    takder ke yang nak sponser lappie baru :P