Server time went out of sync

Last Sunday night I received a call from one of my clients that the pdf generation stopped working! What on earth! It was working fine for the 2 years and it decided this Sunday to stop working? What happened? I checked the code (nothing was committed accidentally). Checked the requests “Server can not generate pdf”. Then after a bit of debugging it turned out that the code that was uploading the generated PDF to Amazon S3 was throwing an error. Luckily the error description was quite clear:

The difference between the request time and the current time is too large.

So right away I checked the hour of the server that generates the PDF files & indeed it was around 15 mins in front. After a bit of looking up online I found that you can sync your server time using the command below. And that right away solved the issue & PDF generation was magically fixed 🙂

sudo ntpdate
sudo apt install ntp
sudo systemctl reload ntp.service

You can read more about it on Ubuntu documentation