I’ve been dealing with this really annoying issue over the past few months in which a server reboot will cause the hostname to get screwed up. Essentially this is what will happen:

Normally the hostname will be server.mydomain.com. When the server is rebooted, the hostname is changed to just server with no domain attached. This causes some really annoying headaches, such as the inability to access cPanel due to certificate problems. When that happens, you need to fix the hostname and run a set of commands via SSH to get the certificate to reissue. The commands to fix the missing SSL issue are outlined here on Webtrunk.

While rebuilding a web server, I ran into this same annoying issue and finally decided I’d had enough of it. I’ve written a sort of fix for it that needs to run via a cronjob. Essentially what it does is checks the hostname of your server and if it’s not correct, it fixes it.

The script to update the hostname can be found on GitHub.

You’ll need to run it via a cronjob to make it effective. Using crontab -e,  you would add something like this:

*/15 * * * * /path/to/hostnamecheck.sh

Obviously change /path/to/ to whatever the path is where you have stored the hostnamecheck.sh script. This will run every 15 minutes. If it’s wrong, it fixes it. If it’s not, it does nothing.

Need more cronjob help? Try this post at The Geek Stuff.

I am now off to do battle with NGINX. What a wonderful way to spend Christmas Eve.

Leave a Reply

Your email address will not be published. Required fields are marked *