A primary job of the webmaster or server administrator is to keep the online server healthy, running and up to date. While Ubuntu maintenance task seems to be easy, but technically it’s become difficult with more hacking, data breach and theft these days.
One of the major reason is the out-dated software program. Hence, it’s very important to keep the server updated with all the security patch releases and latest version.
In this article, we are going to learn different command lines that help in maintaining the Ubuntu cloud server. We will learn how to update, upgrade and clean up the old obsolete files. We are also going to automate these task using CRON jobs.
Let’s get started with Ubuntu maintenance and automation —
Ubuntu Maintenance Task using Command Line
Some of the basic maintenance task that a server administrator performs is upgrading and cleaning up the old files. You can use below commands via your SSH login to run and perform maintenance of Ubuntu cloud server.
Update the apt repository using below CLI command:
sudo apt-get update
Upgrade the Ubuntu Server Distribution using below command:
sudo apt-get dist-upgrade -y
Upgrade entire Ubuntu Server using below command:
sudo apt-get upgrade -y
Remove the older Ubuntu upgraded system files using below command
sudo apt-get autoremove
Clean the obsolete Ubuntu server files using below command:
sudo apt-get autoclean
Reboot Ubuntu cloud server using below command:
There is no harm in running these commands multiple times in a day except rebooting. However, it’s recommended to perform upgrades and cleanups at least once a week. Especially the security upgrades that keep the server healthy.
Automating Ubuntu Maintenance using CRONTAB
The command lines previous need to be manually executed via SSH. This could be easily eliminated using CRON jobs automation.
Basically, we will set up a rule that will tell the Ubuntu cloud server when to execute a set of pre-defined commands. This commands basically update, upgrade and also clean and remove the old Ubuntu server files and replace with the newest version.
Let’s get started with the automation —
Login into your Cloud Server SSH client and edit the crontab file using below command:
sudo nano /etc/crontab
Insert the below Ubuntu maintenance after all other existing rules. This will execute the CRON job at the set daily interval at 0425 server time.
25 4 * * * root sudo -- sh -c 'apt-get update; apt-get upgrade -y; apt-get dist-upgrade -y; apt-get autoremove -y; apt-get autoclean -y'
The above CRON job rule can be translated as below:
m h dom mon dow user command minute hour dayOfMonth Month dayOfWeek userToRun commandToRun
You can even customize the Ubuntu maintenance automation as per your need and timings. I analyzed my Google Analytics audience report to understand the lowest traffic point hence setup the CRON job to run the task at 0425 hours every day.
Once you’ve added the above rule to crontab file, do not forget to reboot the cloud server using below command:
Scheduling Weekly Server Reboot (Optional)
The Ubuntu cloud server is pretty powerful and does not require frequent reboots. However, its good idea to reboot the server once in a week or at least whenever you notice the alert saying *** system reboot required *** after login into SSH client.
You can even automate the periodical reboot using the CRON jobs. All you need is to add the following snippet in the crontab file for a weekly reboot on Sunday at 0525 hours server time.
25 5 * * 1 root sudo reboot
I personally reboot once in while when notice the aforementioned alert, however as a system administrator you can schedule the reboot automation using the above rule in a /etc/crontab file.
You can even customize the time and frequency per needs. Also, I do not suggest to reboot the Ubuntu server every day, unless if required, to maintain the smooth functioning.
Watch Ubuntu Maintenance Tutorial
Watch the complete video tutorial about Ubuntu Cloud Server maintenance and it’s automation. It’s important to keep your server up to date and healthy.
I hope you liked the video, please subscribe to our YouTube channel for more videos.
What’s next in #CloudServer Series?
We have learned how to maintain the Ubuntu Cloud Server for the long run. And also automating the basic maintenance task using the CRON jobs feature.
Next, we are going to touch base upon the Ubuntu error logs and getting support for resolution of any issue with Cloud Server.
If you've any thoughts on Ubuntu Maintenance Automation: update, upgrade, clean and reboot easily, then feel free to drop in below comment box. Also, please subscribe to our restoreBin YouTube channel for amazing videos tips. Cheers!