Hello, friends. In this post, you will learn how to update Rocky Linux automatically using dnf-automatic.
What is dnf-automatic?
dnf-automatic is a tool that helps to manage automatic unattended updates of Rocky Linux system.
This tool is a help for many sysadmins to automate updates on a server.
So, it is worth knowing this tool.
Install dnf-automatic on Rocky Linux
One of the advantages of this tool is that we can install it without too many problems because it is present in the official repositories.
So, in a terminal or on a server update the entire system
sudo dnf update
Then, install the tool with the command:
sudo dnf install dnf-automatic
Just like that, it will be installed on your system.
Automatically update Rocky Linux with dnf-automatic
Before using the tool, it is necessary to configure it correctly. In this sense, the main configuration is in the /etc/dnf/automatic.conf
file.
So, before editing it if you want you can make a backup of it
sudo cp /etc/dnf/automatic.conf /etc/dnf/automatic.conf.bak
Now edit it:
sudo vi /etc/dnf/automatic.conf
The first thing we have to do is to locate the line starting with apply_updates
and assign it a value of yes
.
apply_updates = yes
This way, the tool will apply the updates as soon as they are downloaded.
You can also define what you want to be updated. Generally, it is not recommended that these are full updates, but only security updates.
To configure this, locate the upgrade_type
file and replace default
with security
.
upgrade_type = security
Another useful aspect of the configuration is that you can define if every time you log in to the server, you will be informed of the updated packages.
To achieve this, change the value of emit_via
to motd
.
emit_via = motd
Then, save the configuration and close the editor.
To check that everything is OK, you can run this command
sudo dnf-automatic
With that, we know that it is well configured.
The tool is configured, but when will it run?
Well, you have to set a time for the task to be done.
First, start the tool:
sudo systemctl enable --now dnf-automatic.timer
And then, you can modify the time that it runs
sudo vi /etc/systemd/system/timers.target.wants/dnf-automatic.timer
In the OnCalendar
section, replace it with the desired value.
OnCalendar=*-*-*-* 01:00
The above example runs the task every day at 01:00 You can adjust it.
Save the changes and close the editor.
If you want to avoid a delay in the command execution, find the RandomizedDelaySec
directive and set it to 0m
.
RandomizedDelaySec = 0m
Save the changes and close the editor.
Apply the changes with the following command:
sudo systemctl daemon-reload
Done.
Conclusion
Automating processes is a basic task when administering servers. Today, you learned a good trick to do it.